forked from hashicorp/go-tfe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
organization_token_integration_test.go
96 lines (75 loc) · 2.5 KB
/
organization_token_integration_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//go:build integration
// +build integration
package tfe
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestOrganizationTokensCreate(t *testing.T) {
client := testClient(t)
ctx := context.Background()
orgTest, orgTestCleanup := createOrganization(t, client)
defer orgTestCleanup()
var tkToken string
t.Run("with valid options", func(t *testing.T) {
ot, err := client.OrganizationTokens.Create(ctx, orgTest.Name)
require.NoError(t, err)
require.NotEmpty(t, ot.Token)
tkToken = ot.Token
})
t.Run("when a token already exists", func(t *testing.T) {
ot, err := client.OrganizationTokens.Create(ctx, orgTest.Name)
require.NoError(t, err)
require.NotEmpty(t, ot.Token)
assert.NotEqual(t, tkToken, ot.Token)
})
t.Run("without valid organization", func(t *testing.T) {
ot, err := client.OrganizationTokens.Create(ctx, badIdentifier)
assert.Nil(t, ot)
assert.EqualError(t, err, ErrInvalidOrg.Error())
})
}
func TestOrganizationTokensRead(t *testing.T) {
client := testClient(t)
ctx := context.Background()
orgTest, orgTestCleanup := createOrganization(t, client)
defer orgTestCleanup()
t.Run("with valid options", func(t *testing.T) {
_, otTestCleanup := createOrganizationToken(t, client, orgTest)
ot, err := client.OrganizationTokens.Read(ctx, orgTest.Name)
require.NoError(t, err)
assert.NotEmpty(t, ot)
otTestCleanup()
})
t.Run("when a token doesn't exists", func(t *testing.T) {
ot, err := client.OrganizationTokens.Read(ctx, orgTest.Name)
assert.Equal(t, ErrResourceNotFound, err)
assert.Nil(t, ot)
})
t.Run("without valid organization", func(t *testing.T) {
ot, err := client.OrganizationTokens.Read(ctx, badIdentifier)
assert.Nil(t, ot)
assert.EqualError(t, err, ErrInvalidOrg.Error())
})
}
func TestOrganizationTokensDelete(t *testing.T) {
client := testClient(t)
ctx := context.Background()
orgTest, orgTestCleanup := createOrganization(t, client)
defer orgTestCleanup()
createOrganizationToken(t, client, orgTest)
t.Run("with valid options", func(t *testing.T) {
err := client.OrganizationTokens.Delete(ctx, orgTest.Name)
require.NoError(t, err)
})
t.Run("when a token does not exist", func(t *testing.T) {
err := client.OrganizationTokens.Delete(ctx, orgTest.Name)
assert.Equal(t, err, ErrResourceNotFound)
})
t.Run("without valid organization", func(t *testing.T) {
err := client.OrganizationTokens.Delete(ctx, badIdentifier)
assert.EqualError(t, err, ErrInvalidOrg.Error())
})
}