Skip to content

Commit

Permalink
add missing "include" field to listOptions structs
Browse files Browse the repository at this point in the history
  • Loading branch information
uturunku1 committed Mar 1, 2022
1 parent 1b40f4a commit 430d9d1
Show file tree
Hide file tree
Showing 37 changed files with 249 additions and 136 deletions.
8 changes: 4 additions & 4 deletions admin_organization.go
Expand Up @@ -72,12 +72,12 @@ type AdminOrganizationList struct {
Items []*AdminOrganization
}

// AdminOrgIncludeOps represents the available options for include query params.
// AdminOrgIncludeOpt represents the available options for include query params.
// https://www.terraform.io/docs/cloud/api/admin/organizations.html#available-related-resources
type AdminOrgIncludeOps string
type AdminOrgIncludeOpt string

const (
AdminOrgOwners AdminOrgIncludeOps = "owners"
AdminOrgOwners AdminOrgIncludeOpt = "owners"
)

// AdminOrganizationListOptions represents the options for listing organizations via Admin API.
Expand All @@ -89,7 +89,7 @@ type AdminOrganizationListOptions struct {
Query string `url:"q,omitempty"`
// Optional: A list of relations to include. See available resources
// https://www.terraform.io/docs/cloud/api/admin/organizations.html#available-related-resources
Include []AdminOrgIncludeOps `url:"include,omitempty"`
Include []AdminOrgIncludeOpt `url:"include,omitempty"`
}

// AdminOrganizationListModuleConsumersOptions represents the options for listing organization module consumers through the Admin API
Expand Down
2 changes: 1 addition & 1 deletion admin_organization_integration_test.go
Expand Up @@ -59,7 +59,7 @@ func TestAdminOrganizations_List(t *testing.T) {

t.Run("with owners included", func(t *testing.T) {
adminOrgList, err := client.Admin.Organizations.List(ctx, &AdminOrganizationListOptions{
Include: []AdminOrgIncludeOps{AdminOrgOwners},
Include: []AdminOrgIncludeOpt{AdminOrgOwners},
})
assert.NoError(t, err)

Expand Down
12 changes: 6 additions & 6 deletions admin_run.go
Expand Up @@ -43,14 +43,14 @@ type AdminRunsList struct {
Items []*AdminRun
}

// AdminRunIncludeOps represents the available options for include query params.
// AdminRunIncludeOpt represents the available options for include query params.
// https://www.terraform.io/cloud-docs/api-docs/admin/runs#available-related-resources
type AdminRunIncludeOps string
type AdminRunIncludeOpt string

const (
AdminRunWorkspace AdminRunIncludeOps = "workspace"
AdminRunWorkspaceOrg AdminRunIncludeOps = "workspace.organization"
AdminRunWorkspaceOrgOwners AdminRunIncludeOps = "workspace.organization.owners"
AdminRunWorkspace AdminRunIncludeOpt = "workspace"
AdminRunWorkspaceOrg AdminRunIncludeOpt = "workspace.organization"
AdminRunWorkspaceOrgOwners AdminRunIncludeOpt = "workspace.organization.owners"
)

// AdminRunsListOptions represents the options for listing runs.
Expand All @@ -62,7 +62,7 @@ type AdminRunsListOptions struct {
Query string `url:"q,omitempty"`
// Optional: A list of relations to include. See available resources
// https://www.terraform.io/cloud-docs/api-docs/admin/runs#available-related-resources
Include []AdminRunIncludeOps `url:"include,omitempty"`
Include []AdminRunIncludeOpt `url:"include,omitempty"`
}

// adminRuns implements the AdminRuns interface.
Expand Down
4 changes: 2 additions & 2 deletions admin_run_integration_test.go
Expand Up @@ -69,7 +69,7 @@ func TestAdminRuns_List(t *testing.T) {

t.Run("with workspace included", func(t *testing.T) {
rl, err := client.Admin.Runs.List(ctx, &AdminRunsListOptions{
Include: []AdminRunIncludeOps{AdminRunWorkspace},
Include: []AdminRunIncludeOpt{AdminRunWorkspace},
})

assert.NoError(t, err)
Expand All @@ -81,7 +81,7 @@ func TestAdminRuns_List(t *testing.T) {

t.Run("with workspace.organization included", func(t *testing.T) {
rl, err := client.Admin.Runs.List(ctx, &AdminRunsListOptions{
Include: []AdminRunIncludeOps{AdminRunWorkspaceOrg},
Include: []AdminRunIncludeOpt{AdminRunWorkspaceOrg},
})

assert.NoError(t, err)
Expand Down
8 changes: 4 additions & 4 deletions admin_user.go
Expand Up @@ -64,12 +64,12 @@ type AdminUserList struct {
Items []*AdminUser
}

// AdminUserIncludeOps represents the available options for include query params.
// AdminUserIncludeOpt represents the available options for include query params.
// https://www.terraform.io/docs/cloud/api/admin/users.html#available-related-resources
type AdminUserIncludeOps string
type AdminUserIncludeOpt string

const (
AdminUserOrgs AdminUserIncludeOps = "organizations"
AdminUserOrgs AdminUserIncludeOpt = "organizations"
)

// AdminUserListOptions represents the options for listing users.
Expand All @@ -88,7 +88,7 @@ type AdminUserListOptions struct {

// Optional: A list of relations to include. See available resources
// https://www.terraform.io/docs/cloud/api/admin/users.html#available-related-resources
Include []AdminUserIncludeOps `url:"include,omitempty"`
Include []AdminUserIncludeOpt `url:"include,omitempty"`
}

// List all user accounts in the Terraform Enterprise installation
Expand Down
2 changes: 1 addition & 1 deletion admin_user_integration_test.go
Expand Up @@ -76,7 +76,7 @@ func TestAdminUsers_List(t *testing.T) {

t.Run("with organization included", func(t *testing.T) {
ul, err := client.Admin.Users.List(ctx, &AdminUserListOptions{
Include: []AdminUserIncludeOps{AdminUserOrgs},
Include: []AdminUserIncludeOpt{AdminUserOrgs},
})

assert.NoError(t, err)
Expand Down
12 changes: 6 additions & 6 deletions admin_workspace.go
Expand Up @@ -46,14 +46,14 @@ type AdminWorkspace struct {
CurrentRun *Run `jsonapi:"relation,current-run"`
}

// AdminWorkspaceIncludeOps represents the available options for include query params.
// AdminWorkspaceIncludeOpt represents the available options for include query params.
// https://www.terraform.io/docs/cloud/api/admin/workspaces.html#available-related-resources
type AdminWorkspaceIncludeOps string
type AdminWorkspaceIncludeOpt string

const (
AdminWorkspaceOrg AdminWorkspaceIncludeOps = "organization"
AdminWorkspaceCurrentRun AdminWorkspaceIncludeOps = "current_run"
AdminWorkspaceOrgOwners AdminWorkspaceIncludeOps = "organization.owners"
AdminWorkspaceOrg AdminWorkspaceIncludeOpt = "organization"
AdminWorkspaceCurrentRun AdminWorkspaceIncludeOpt = "current_run"
AdminWorkspaceOrgOwners AdminWorkspaceIncludeOpt = "organization.owners"
)

// AdminWorkspaceListOptions represents the options for listing workspaces.
Expand All @@ -65,7 +65,7 @@ type AdminWorkspaceListOptions struct {
Query string `url:"q,omitempty"`
// Optional: A list of relations to include. See available resources
// https://www.terraform.io/docs/cloud/api/admin/workspaces.html#available-related-resources
Include []AdminWorkspaceIncludeOps `url:"include,omitempty"`
Include []AdminWorkspaceIncludeOpt `url:"include,omitempty"`
}

// AdminWorkspaceList represents a list of workspaces.
Expand Down
4 changes: 2 additions & 2 deletions admin_workspace_integration_test.go
Expand Up @@ -88,7 +88,7 @@ func TestAdminWorkspaces_List(t *testing.T) {

t.Run("with organization included", func(t *testing.T) {
wl, err := client.Admin.Workspaces.List(ctx, &AdminWorkspaceListOptions{
Include: []AdminWorkspaceIncludeOps{AdminWorkspaceOrg},
Include: []AdminWorkspaceIncludeOpt{AdminWorkspaceOrg},
})

assert.NoError(t, err)
Expand All @@ -109,7 +109,7 @@ func TestAdminWorkspaces_List(t *testing.T) {
assert.NoError(t, err)

wl, err := client.Admin.Workspaces.List(ctx, &AdminWorkspaceListOptions{
Include: []AdminWorkspaceIncludeOps{AdminWorkspaceCurrentRun},
Include: []AdminWorkspaceIncludeOpt{AdminWorkspaceCurrentRun},
})

assert.NoError(t, err)
Expand Down
7 changes: 7 additions & 0 deletions agent_pool.go
Expand Up @@ -50,9 +50,16 @@ type AgentPool struct {
Organization *Organization `jsonapi:"relation,organization"`
}

// A list of relations to include
type AgentPoolIncludeOpt string

const AgentPoolWorkspaces AgentPoolIncludeOpt = "workspaces"

// AgentPoolListOptions represents the options for listing agent pools.
type AgentPoolListOptions struct {
ListOptions

Include []AgentPoolIncludeOpt `url:"include,omitempty"`
}

// AgentPoolCreateOptions represents the options for creating an agent pool.
Expand Down
8 changes: 8 additions & 0 deletions agent_pool_integration_test.go
Expand Up @@ -49,6 +49,14 @@ func TestAgentPoolsList(t *testing.T) {
assert.Equal(t, 1, pools.TotalCount)
})

t.Run("with Include options", func(t *testing.T) {
pools, err := client.AgentPools.List(ctx, orgTest.Name, &AgentPoolListOptions{
Include: []AgentPoolIncludeOpt{AgentPoolWorkspaces},
})
require.NoError(t, err)
assert.NotEmpty(t, pools.Items[0].Organization.Name)
})

t.Run("without a valid organization", func(t *testing.T) {
pools, err := client.AgentPools.List(ctx, badIdentifier, nil)
assert.Nil(t, pools)
Expand Down
12 changes: 6 additions & 6 deletions configuration_version.go
Expand Up @@ -98,20 +98,20 @@ type CVStatusTimestamps struct {
StartedAt time.Time `jsonapi:"attr,started-at,rfc3339"`
}

// ConfigurationVersionIncludeOps represents the available options for include query params.
// ConfigurationVersionIncludeOpt represents the available options for include query params.
// https://www.terraform.io/docs/cloud/api/configuration-versions.html#available-related-resources
type ConfigurationVersionIncludeOps string
type ConfigurationVersionIncludeOpt string

const (
ConfigurationVerIngressAttributes ConfigurationVersionIncludeOps = "ingress_attributes"
ConfigurationRun ConfigurationVersionIncludeOps = "run"
ConfigurationVerIngressAttributes ConfigurationVersionIncludeOpt = "ingress_attributes"
ConfigurationRun ConfigurationVersionIncludeOpt = "run"
)

// ConfigurationVersionReadOptions represents the options for reading a configuration version.
type ConfigurationVersionReadOptions struct {
// Optional: A list of relations to include. See available resources:
// https://www.terraform.io/docs/cloud/api/configuration-versions.html#available-related-resources
Include []ConfigurationVersionIncludeOps `url:"include,omitempty"`
Include []ConfigurationVersionIncludeOpt `url:"include,omitempty"`
}

// ConfigurationVersionListOptions represents the options for listing
Expand All @@ -120,7 +120,7 @@ type ConfigurationVersionListOptions struct {
ListOptions
// Optional: A list of relations to include. See available resources:
// https://www.terraform.io/docs/cloud/api/configuration-versions.html#available-related-resources
Include []ConfigurationVersionIncludeOps `url:"include,omitempty"`
Include []ConfigurationVersionIncludeOpt `url:"include,omitempty"`
}

// ConfigurationVersionCreateOptions represents the options for creating a
Expand Down
4 changes: 2 additions & 2 deletions configuration_version_integration_test.go
Expand Up @@ -158,7 +158,7 @@ func TestConfigurationVersionsReadWithOptions(t *testing.T) {
time.Sleep(3 * time.Second)

w, err := client.Workspaces.ReadByIDWithOptions(ctx, wTest.ID, &WorkspaceReadOptions{
Include: []WSIncludeOps{WSCurrentRunConfigVer},
Include: []WSIncludeOpt{WSCurrentRunConfigVer},
})

if err != nil {
Expand All @@ -173,7 +173,7 @@ func TestConfigurationVersionsReadWithOptions(t *testing.T) {

t.Run("when the configuration version exists", func(t *testing.T) {
options := &ConfigurationVersionReadOptions{
Include: []ConfigurationVersionIncludeOps{ConfigurationVerIngressAttributes},
Include: []ConfigurationVersionIncludeOpt{ConfigurationVerIngressAttributes},
}

cv, err := client.ConfigurationVersions.ReadWithOptions(ctx, cv.ID, options)
Expand Down
10 changes: 5 additions & 5 deletions docs/CONTRIBUTING.md
Expand Up @@ -130,12 +130,12 @@ func (s *example) Create(ctx context.Context, organization string, options Examp
return r, nil
}

// ExampleIncludeOps represents the available options for include query params.
// ExampleIncludeOpt represents the available options for include query params.
// https://www.terraform.io/cloud-docs/api-docs/examples#list-examples (replace this URL with the actual documentation URL)
type ExampleIncludeOps string
type ExampleIncludeOpt string

const (
ExampleOrganization ExampleIncludeOps = "organization"
ExampleOrganization ExampleIncludeOpt = "organization"
)

// ExampleListOptions represents the set of options for listing examples
Expand All @@ -144,7 +144,7 @@ type ExampleListOptions struct {

// Optional: A list of relations to include with an example. See available resources:
// https://www.terraform.io/cloud-docs/api-docs/examples#list-examples (replace this URL with the actual documentation URL)
Include []ExampleIncludeOps `url:"include,omitempty"`
Include []ExampleIncludeOpt `url:"include,omitempty"`
}

// List all the examples for an organization
Expand Down Expand Up @@ -177,7 +177,7 @@ func (s *example) Read(ctx context.Context, exampleID string) (*Example, error)
type ExampleReadOptions struct {
// Optional: A list of relations to include with an example. See available resources:
// https://www.terraform.io/cloud-docs/api-docs/examples#list-examples (replace this URL with the actual documentation URL)
Include []RunTaskIncludeOps `url:"include,omitempty"`
Include []RunTaskIncludeOpt `url:"include,omitempty"`
}

// Read is used to read an organization's example by ID with options
Expand Down
6 changes: 5 additions & 1 deletion errors.go
Expand Up @@ -21,6 +21,8 @@ var (
ErrUnsupportedOperations = errors.New("operations is deprecated and cannot be specified when execution mode is used")

ErrUnsupportedPrivateKey = errors.New("private Key can only be present with Azure DevOps Server service provider")

ErrUnsupportedRunTriggerType = errors.New(`"RunTriggerType" must be "inbound" when requesting "include" query params`)
)

// Library errors that usually indicate a bug in the implementation of go-tfe
Expand Down Expand Up @@ -116,7 +118,9 @@ var (

ErrInvalidRunTriggerID = errors.New("invalid value for run trigger ID")

ErrInvalidRunTriggerType = errors.New(`invalid value for RunTriggerType. It must be either "inbound" or "outbound"`)
ErrInvalidRunTriggerType = errors.New(`invalid value or no value for RunTriggerType. It must be either "inbound" or "outbound"`)

ErrInvalidRunTriggerInclude = errors.New(`invalid value for "include" field`)

ErrInvalidSHHKeyID = errors.New("invalid value for SSH key ID")

Expand Down
7 changes: 7 additions & 0 deletions oauth_client.go
Expand Up @@ -82,10 +82,17 @@ type OAuthClient struct {
OAuthTokens []*OAuthToken `jsonapi:"relation,oauth-tokens"`
}

// A list of relations to include
type OAuthClientIncludeOpt string

const OauthClientOauthTokens OAuthClientIncludeOpt = "oauth_tokens"

// OAuthClientListOptions represents the options for listing
// OAuth clients.
type OAuthClientListOptions struct {
ListOptions

Include []OAuthClientIncludeOpt `url:"include,omitempty"`
}

// OAuthClientCreateOptions represents the options for creating an OAuth client.
Expand Down
8 changes: 8 additions & 0 deletions oauth_client_integration_test.go
Expand Up @@ -67,6 +67,14 @@ func TestOAuthClientsList(t *testing.T) {
assert.Equal(t, 2, ocl.TotalCount)
})

t.Run("with Include options", func(t *testing.T) {
ocl, err := client.OAuthClients.List(ctx, orgTest.Name, &OAuthClientListOptions{
Include: []OAuthClientIncludeOpt{OauthClientOauthTokens},
})
require.NoError(t, err)
assert.NotEmpty(t, ocl.Items[0].OAuthTokens[0].ID)
})

t.Run("without a valid organization", func(t *testing.T) {
ocl, err := client.OAuthClients.List(ctx, badIdentifier, nil)
assert.Nil(t, ocl)
Expand Down
12 changes: 6 additions & 6 deletions organization_membership.go
Expand Up @@ -62,21 +62,21 @@ type OrganizationMembership struct {
Teams []*Team `jsonapi:"relation,teams"`
}

// OrganizationMembershipIncludeOps represents the available options for include query params.
// OrganizationMembershipIncludeOpt represents the available options for include query params.
// https://www.terraform.io/cloud-docs/api-docs/organization-memberships#available-related-resources
type OrganizationMembershipIncludeOps string
type OrganizationMembershipIncludeOpt string

const (
OrganizationMembershipUser OrganizationMembershipIncludeOps = "user"
OrganizationMembershipTeam OrganizationMembershipIncludeOps = "teams"
OrganizationMembershipUser OrganizationMembershipIncludeOpt = "user"
OrganizationMembershipTeam OrganizationMembershipIncludeOpt = "teams"
)

// OrganizationMembershipListOptions represents the options for listing organization memberships.
type OrganizationMembershipListOptions struct {
ListOptions
// Optional: A list of relations to include. See available resources
// https://www.terraform.io/cloud-docs/api-docs/organization-memberships#available-related-resources
Include []OrganizationMembershipIncludeOps `url:"include,omitempty"`
Include []OrganizationMembershipIncludeOpt `url:"include,omitempty"`
}

// OrganizationMembershipCreateOptions represents the options for creating an organization membership.
Expand All @@ -95,7 +95,7 @@ type OrganizationMembershipCreateOptions struct {
type OrganizationMembershipReadOptions struct {
// Optional: A list of relations to include. See available resources
// https://www.terraform.io/cloud-docs/api-docs/organization-memberships#available-related-resources
Include []OrganizationMembershipIncludeOps `url:"include,omitempty"`
Include []OrganizationMembershipIncludeOpt `url:"include,omitempty"`
}

// List all the organization memberships of the given organization.
Expand Down
6 changes: 3 additions & 3 deletions organization_membership_integration_test.go
Expand Up @@ -64,7 +64,7 @@ func TestOrganizationMembershipsList(t *testing.T) {
defer memTest2Cleanup()

ml, err := client.OrganizationMemberships.List(ctx, orgTest.Name, &OrganizationMembershipListOptions{
Include: []OrganizationMembershipIncludeOps{OrganizationMembershipUser},
Include: []OrganizationMembershipIncludeOpt{OrganizationMembershipUser},
})
require.NoError(t, err)

Expand Down Expand Up @@ -96,7 +96,7 @@ func TestOrganizationMembershipsCreate(t *testing.T) {

// Get a refreshed view from the API.
refreshed, err := client.OrganizationMemberships.ReadWithOptions(ctx, mem.ID, OrganizationMembershipReadOptions{
Include: []OrganizationMembershipIncludeOps{OrganizationMembershipUser},
Include: []OrganizationMembershipIncludeOpt{OrganizationMembershipUser},
})
require.NoError(t, err)
assert.Equal(t, refreshed, mem)
Expand Down Expand Up @@ -169,7 +169,7 @@ func TestOrganizationMembershipsReadWithOptions(t *testing.T) {
defer memTestCleanup()

options := OrganizationMembershipReadOptions{
Include: []OrganizationMembershipIncludeOps{OrganizationMembershipUser},
Include: []OrganizationMembershipIncludeOpt{OrganizationMembershipUser},
}

t.Run("when the membership exists", func(t *testing.T) {
Expand Down

0 comments on commit 430d9d1

Please sign in to comment.