Skip to content

Commit

Permalink
Token generate functions renamed to Create
Browse files Browse the repository at this point in the history
  • Loading branch information
sebasslash committed Feb 24, 2022
1 parent 23f2378 commit 9c1070d
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 50 deletions.
2 changes: 1 addition & 1 deletion helper_test.go
Expand Up @@ -897,7 +897,7 @@ func createTeamToken(t *testing.T, client *Client, tm *Team) (*TeamToken, func()
}

ctx := context.Background()
tt, err := client.TeamTokens.Generate(ctx, tm.ID)
tt, err := client.TeamTokens.Create(ctx, tm.ID)
if err != nil {
t.Fatal(err)
}
Expand Down
30 changes: 15 additions & 15 deletions mocks/team_token_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions mocks/user_token_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions team_token.go
Expand Up @@ -16,8 +16,8 @@ var _ TeamTokens = (*teamTokens)(nil)
// TFE API docs:
// https://www.terraform.io/docs/cloud/api/team-tokens.html
type TeamTokens interface {
// Generate a new team token, replacing any existing token.
Generate(ctx context.Context, teamID string) (*TeamToken, error)
// Create a new team token, replacing any existing token.
Create(ctx context.Context, teamID string) (*TeamToken, error)

// Read a team token by its ID.
Read(ctx context.Context, teamID string) (*TeamToken, error)
Expand All @@ -40,8 +40,8 @@ type TeamToken struct {
Token string `jsonapi:"attr,token"`
}

// Generate a new team token, replacing any existing token.
func (s *teamTokens) Generate(ctx context.Context, teamID string) (*TeamToken, error) {
// Create a new team token, replacing any existing token.
func (s *teamTokens) Create(ctx context.Context, teamID string) (*TeamToken, error) {
if !validStringID(&teamID) {
return nil, ErrInvalidTeamID
}
Expand Down
8 changes: 4 additions & 4 deletions team_token_integration_test.go
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/require"
)

func TestTeamTokensGenerate(t *testing.T) {
func TestTeamTokensCreate(t *testing.T) {
skipIfFreeOnly(t)

client := testClient(t)
Expand All @@ -22,21 +22,21 @@ func TestTeamTokensGenerate(t *testing.T) {

var tmToken string
t.Run("with valid options", func(t *testing.T) {
tt, err := client.TeamTokens.Generate(ctx, tmTest.ID)
tt, err := client.TeamTokens.Create(ctx, tmTest.ID)
require.NoError(t, err)
require.NotEmpty(t, tt.Token)
tmToken = tt.Token
})

t.Run("when a token already exists", func(t *testing.T) {
tt, err := client.TeamTokens.Generate(ctx, tmTest.ID)
tt, err := client.TeamTokens.Create(ctx, tmTest.ID)
require.NoError(t, err)
require.NotEmpty(t, tt.Token)
assert.NotEqual(t, tmToken, tt.Token)
})

t.Run("without valid team ID", func(t *testing.T) {
tt, err := client.TeamTokens.Generate(ctx, badIdentifier)
tt, err := client.TeamTokens.Create(ctx, badIdentifier)
assert.Nil(t, tt)
assert.Equal(t, err, ErrInvalidTeamID)
})
Expand Down
12 changes: 6 additions & 6 deletions user_token.go
Expand Up @@ -19,8 +19,8 @@ type UserTokens interface {
// List all the tokens of the given user ID.
List(ctx context.Context, userID string) (*UserTokenList, error)

// Generate a new user token
Generate(ctx context.Context, userID string, options UserTokenGenerateOptions) (*UserToken, error)
// Create a new user token
Create(ctx context.Context, userID string, options UserTokenCreateOptions) (*UserToken, error)

// Read a user token by its ID.
Read(ctx context.Context, tokenID string) (*UserToken, error)
Expand Down Expand Up @@ -49,14 +49,14 @@ type UserToken struct {
Token string `jsonapi:"attr,token"`
}

// UserTokenGenerateOptions the options for creating a user token.
type UserTokenGenerateOptions struct {
// UserTokenCreateOptions the options for creating a user token.
type UserTokenCreateOptions struct {
// Description of the token
Description string `jsonapi:"attr,description,omitempty"`
}

// Generate a new user token
func (s *userTokens) Generate(ctx context.Context, userID string, options UserTokenGenerateOptions) (*UserToken, error) {
// Create a new user token
func (s *userTokens) Create(ctx context.Context, userID string, options UserTokenCreateOptions) (*UserToken, error) {
if !validStringID(&userID) {
return nil, ErrInvalidUserID
}
Expand Down
10 changes: 5 additions & 5 deletions user_token_integration_test.go
Expand Up @@ -41,8 +41,8 @@ func TestUserTokens_List(t *testing.T) {
})
}

// TestUserTokens_Generate tests basic creation of user tokens
func TestUserTokens_Generate(t *testing.T) {
// TestUserTokens_Create tests basic creation of user tokens
func TestUserTokens_Create(t *testing.T) {
client := testClient(t)
ctx := context.Background()
user, err := client.Users.ReadCurrent(ctx)
Expand All @@ -62,15 +62,15 @@ func TestUserTokens_Generate(t *testing.T) {
}(t)

t.Run("create token with no description", func(t *testing.T) {
token, err := client.UserTokens.Generate(ctx, user.ID, UserTokenGenerateOptions{})
token, err := client.UserTokens.Create(ctx, user.ID, UserTokenCreateOptions{})
tokens = append(tokens, token.ID)
if err != nil {
t.Fatal(err)
}
})

t.Run("create token with description", func(t *testing.T) {
token, err := client.UserTokens.Generate(ctx, user.ID, UserTokenGenerateOptions{
token, err := client.UserTokens.Create(ctx, user.ID, UserTokenCreateOptions{
Description: fmt.Sprintf("go-tfe-user-token-test-%s", randomString(t)),
})
tokens = append(tokens, token.ID)
Expand Down Expand Up @@ -112,7 +112,7 @@ func createToken(t *testing.T, client *Client, user *User) (*UserToken, func())
if user == nil {
t.Fatal("Nil user in createToken")
}
token, err := client.UserTokens.Generate(ctx, user.ID, UserTokenGenerateOptions{
token, err := client.UserTokens.Create(ctx, user.ID, UserTokenCreateOptions{
Description: fmt.Sprintf("go-tfe-user-token-test-%s", randomString(t)),
})
if err != nil {
Expand Down

0 comments on commit 9c1070d

Please sign in to comment.