Skip to content

Commit

Permalink
feat: Add inclusion of no-code module w/mod list.
Browse files Browse the repository at this point in the history
  • Loading branch information
paladin-devops committed Nov 18, 2024
1 parent 7004ad0 commit 7002b96
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/TESTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ $ TFE_TOKEN=xyz TFE_HOSTNAME=tfe.local ENABLE_TFE=1 go test ./... -timeout=30m

### Running tests for HCP Terraform features that require paid plans (HashiCorp Employees)

You can use the test helper `upgradeOrganizationSubscription()` to upgrade your test organization to a Business Plan, giving the organization access to all features in HCP Terraform. This method requires `TFE_TOKEN` to be a user token with administrator access in the target test environment. Furthermore, you **can not** have enterprise features enabled (`ENABLE_TFE=1`) in order to use this method since the API call fails against Terraform Enterprise test environments.
You can use the test helper `newSubscriptionUpdater()` to upgrade your test organization to a Business Plan, giving the organization access to all features in HCP Terraform. This method requires `TFE_TOKEN` to be a user token with administrator access in the target test environment. Furthermore, you **can not** have enterprise features enabled (`ENABLE_TFE=1`) in order to use this method since the API call fails against Terraform Enterprise test environments.
13 changes: 11 additions & 2 deletions registry_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var _ RegistryModules = (*registryModules)(nil)
//
// TFE API docs: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/private-registry/modules
type RegistryModules interface {
// List all the registory modules within an organization
// List all the registry modules within an organization
List(ctx context.Context, organization string, options *RegistryModuleListOptions) (*RegistryModuleList, error)

// ListCommits List the commits for the registry module
Expand Down Expand Up @@ -157,6 +157,8 @@ type RegistryModule struct {

// Relations
Organization *Organization `jsonapi:"relation,organization"`

RegistryNoCodeModule []*RegistryNoCodeModule `jsonapi:"relation,no-code-modules"`
}

// Commit represents a commit
Expand Down Expand Up @@ -202,8 +204,15 @@ type RegistryModuleVersionStatuses struct {
// RegistryModuleListOptions represents the options for listing registry modules.
type RegistryModuleListOptions struct {
ListOptions

// Include is a list of relations to include.
Include []RegistryModuleListIncludeOpt `url:"include,omitempty"`
}

type RegistryModuleListIncludeOpt string

const IncludeNoCodeModules RegistryModuleListIncludeOpt = "no-code-modules"

// RegistryModuleCreateOptions is used when creating a registry module without a VCS repo
type RegistryModuleCreateOptions struct {
// Type is a public field utilized by JSON:API to
Expand Down Expand Up @@ -311,7 +320,7 @@ type RegistryModuleVCSRepoUpdateOptions struct {
Tags *bool `json:"tags,omitempty"`
}

// List all the registory modules within an organization.
// List all the registry modules within an organization.
func (r *registryModules) List(ctx context.Context, organization string, options *RegistryModuleListOptions) (*RegistryModuleList, error) {
if !validStringID(&organization) {
return nil, ErrInvalidOrg
Expand Down
25 changes: 25 additions & 0 deletions registry_module_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,31 @@ func TestRegistryModulesList(t *testing.T) {
assert.NotEmpty(t, modl.Items)
assert.Equal(t, 1, modl.CurrentPage)
})

t.Run("include no-code modules", func(t *testing.T) {
registryModuleTest3, registryModuleTest3Cleanup := createRegistryModule(t, client, orgTest, PrivateRegistry)
defer registryModuleTest3Cleanup()

newSubscriptionUpdater(orgTest).WithPlusEntitlementPlan().Update(t)
_, noCodeModuleCleanup := createNoCodeRegistryModule(t, client, orgTest.Name, registryModuleTest3, nil)
defer noCodeModuleCleanup()

modl, err := client.RegistryModules.List(ctx, orgTest.Name, &RegistryModuleListOptions{
Include: []RegistryModuleListIncludeOpt{
IncludeNoCodeModules,
},
})
require.NoError(t, err)
assert.Len(t, modl.Items, 3)
// only module 3 is no-code, so iterate through the results before
// the test assertion
for _, m := range modl.Items {
if m.ID == registryModuleTest2.ID {
assert.True(t, modl.Items[2].NoCode)
assert.Len(t, modl.Items[2].RegistryNoCodeModule, 1)
}
}
})
}

func TestRegistryModulesCreate(t *testing.T) {
Expand Down

0 comments on commit 7002b96

Please sign in to comment.