Skip to content

Commit

Permalink
Merge pull request #327 from hashicorp/sebasslash/method-naming-refactor
Browse files Browse the repository at this point in the history
Use consistent naming across resource methods
  • Loading branch information
sebasslash committed Feb 24, 2022
2 parents 861c6e3 + b8682da commit 9b2ac88
Show file tree
Hide file tree
Showing 30 changed files with 301 additions and 301 deletions.
12 changes: 6 additions & 6 deletions agent_token.go
Expand Up @@ -19,8 +19,8 @@ type AgentTokens interface {
// List all the agent tokens of the given agent pool.
List(ctx context.Context, agentPoolID string) (*AgentTokenList, error)

// Generate a new agent token with the given options.
Generate(ctx context.Context, agentPoolID string, options AgentTokenGenerateOptions) (*AgentToken, error)
// Create a new agent token with the given options.
Create(ctx context.Context, agentPoolID string, options AgentTokenCreateOptions) (*AgentToken, error)

// Read an agent token by its ID.
Read(ctx context.Context, agentTokenID string) (*AgentToken, error)
Expand Down Expand Up @@ -70,8 +70,8 @@ func (s *agentTokens) List(ctx context.Context, agentPoolID string) (*AgentToken
return tokenList, nil
}

// AgentTokenGenerateOptions represents the options for creating an agent token.
type AgentTokenGenerateOptions struct {
// AgentTokenCreateOptions represents the options for creating an agent token.
type AgentTokenCreateOptions struct {
// Type is a public field utilized by JSON:API to
// set the resource type via the field tag.
// It is not a user-defined value and does not need to be set.
Expand All @@ -82,8 +82,8 @@ type AgentTokenGenerateOptions struct {
Description *string `jsonapi:"attr,description"`
}

// Generate a new agent token with the given options.
func (s *agentTokens) Generate(ctx context.Context, agentPoolID string, options AgentTokenGenerateOptions) (*AgentToken, error) {
// Create a new agent token with the given options.
func (s *agentTokens) Create(ctx context.Context, agentPoolID string, options AgentTokenCreateOptions) (*AgentToken, error) {
if !validStringID(&agentPoolID) {
return nil, ErrInvalidAgentPoolID
}
Expand Down
8 changes: 4 additions & 4 deletions agent_token_integration_test.go
Expand Up @@ -51,7 +51,7 @@ func TestAgentTokensList(t *testing.T) {
})
}

func TestAgentTokensGenerate(t *testing.T) {
func TestAgentTokensCreate(t *testing.T) {
skipIfEnterprise(t)
skipIfFreeOnly(t)

Expand All @@ -62,21 +62,21 @@ func TestAgentTokensGenerate(t *testing.T) {
defer apTestCleanup()

t.Run("with valid description", func(t *testing.T) {
token, err := client.AgentTokens.Generate(ctx, apTest.ID, AgentTokenGenerateOptions{
token, err := client.AgentTokens.Create(ctx, apTest.ID, AgentTokenCreateOptions{
Description: String(randomString(t)),
})
require.NoError(t, err)
require.NotEmpty(t, token.Token)
})

t.Run("without valid description", func(t *testing.T) {
at, err := client.AgentTokens.Generate(ctx, badIdentifier, AgentTokenGenerateOptions{})
at, err := client.AgentTokens.Create(ctx, badIdentifier, AgentTokenCreateOptions{})
assert.Nil(t, at)
assert.EqualError(t, err, ErrInvalidAgentPoolID.Error())
})

t.Run("without valid agent pool ID", func(t *testing.T) {
at, err := client.AgentTokens.Generate(ctx, badIdentifier, AgentTokenGenerateOptions{
at, err := client.AgentTokens.Create(ctx, badIdentifier, AgentTokenCreateOptions{
Description: String(randomString(t)),
})
assert.Nil(t, at)
Expand Down
6 changes: 3 additions & 3 deletions helper_test.go
Expand Up @@ -74,7 +74,7 @@ func createAgentToken(t *testing.T, client *Client, ap *AgentPool) (*AgentToken,
}

ctx := context.Background()
at, err := client.AgentTokens.Generate(ctx, ap.ID, AgentTokenGenerateOptions{
at, err := client.AgentTokens.Create(ctx, ap.ID, AgentTokenCreateOptions{
Description: String(randomString(t)),
})
if err != nil {
Expand Down Expand Up @@ -439,7 +439,7 @@ func createOrganizationToken(t *testing.T, client *Client, org *Organization) (*
}

ctx := context.Background()
tk, err := client.OrganizationTokens.Generate(ctx, org.Name)
tk, err := client.OrganizationTokens.Create(ctx, org.Name)
if err != nil {
t.Fatal(err)
}
Expand Down 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/agent_token_mocks.go

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

72 changes: 36 additions & 36 deletions mocks/organization_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/organization_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/plan_mocks.go

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

0 comments on commit 9b2ac88

Please sign in to comment.