forked from hashicorp/go-tfe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteam_token_test.go
63 lines (50 loc) · 1.56 KB
/
team_token_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
package tfe
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestTeamTokensGenerate(t *testing.T) {
client := testClient(t)
ctx := context.Background()
tmTest, tmTestCleanup := createTeam(t, client, nil)
defer tmTestCleanup()
var tkToken string
t.Run("with valid options", func(t *testing.T) {
tk, err := client.TeamTokens.Generate(ctx, tmTest.ID)
require.NoError(t, err)
require.NotEmpty(t, tk.Token)
tkToken = tk.Token
})
t.Run("when a token already exists", func(t *testing.T) {
tk, err := client.TeamTokens.Generate(ctx, tmTest.ID)
require.NoError(t, err)
require.NotEmpty(t, tk.Token)
assert.NotEqual(t, tkToken, tk.Token)
})
t.Run("without valid team ID", func(t *testing.T) {
tk, err := client.TeamTokens.Generate(ctx, badIdentifier)
assert.Nil(t, tk)
assert.EqualError(t, err, "Invalid value for team ID")
})
}
func TestTeamTokensDelete(t *testing.T) {
client := testClient(t)
ctx := context.Background()
tmTest, tmTestCleanup := createTeam(t, client, nil)
defer tmTestCleanup()
createTeamToken(t, client, tmTest)
t.Run("with valid options", func(t *testing.T) {
err := client.TeamTokens.Delete(ctx, tmTest.ID)
assert.NoError(t, err)
})
t.Run("when a token does not exist", func(t *testing.T) {
err := client.TeamTokens.Delete(ctx, tmTest.ID)
assert.Equal(t, err, ErrResourceNotFound)
})
t.Run("without valid team ID", func(t *testing.T) {
err := client.TeamTokens.Delete(ctx, badIdentifier)
assert.EqualError(t, err, "Invalid value for team ID")
})
}