Skip to content

Commit

Permalink
Use consistent naming across resource methods
Browse files Browse the repository at this point in the history
This commit introduces a refactor for several methods that express an action on a relationship between two resources. By using
verbs, we can be more specific as to what action we're performing when calling these methods. An example would be
ModuleConsumers() -- from this method signature we can't necessarily tell what action this method is performing without
referring to the docs. Renaming it to ListModuleConsumers() we can now assess what the function does more conveniently.
  • Loading branch information
sebasslash committed Feb 23, 2022
1 parent 57f36e6 commit 23f2378
Show file tree
Hide file tree
Showing 24 changed files with 251 additions and 251 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
4 changes: 2 additions & 2 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
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 23f2378

Please sign in to comment.