Skip to content

Commit

Permalink
Add registry provider version
Browse files Browse the repository at this point in the history
  • Loading branch information
joekarl authored and annawinkler committed May 17, 2022
1 parent 35f00e1 commit 52b33a2
Show file tree
Hide file tree
Showing 8 changed files with 1,097 additions and 202 deletions.
12 changes: 12 additions & 0 deletions errors.go
Expand Up @@ -155,6 +155,16 @@ var (
ErrInvalidCommentID = errors.New("invalid value for comment ID")

ErrInvalidCommentBody = errors.New("invalid value for comment body")

ErrInvalidNamespace = errors.New("invalid value for namespace")

ErrInvalidPrivateProviderNamespaceDoesntMatchOrganization = errors.New("invalid namespace must match organization name for private providers")

ErrInvalidRegistryName = errors.New("invalid value for registry-name")

ErrInvalidRegistryNameType = errors.New("invalid type for registry-name. Please use 'RegistryName'")

ErrInvalidKeyID = errors.New("invalid value for key-id")
)

// Missing values for required field/option
Expand Down Expand Up @@ -268,4 +278,6 @@ var (
ErrEmptyTeamName = errors.New("team name can not be empty")

ErrInvalidEmail = errors.New("email is invalid")

ErrRequiredPrivateRegistry = errors.New("only private registry is allowed")
)
2 changes: 2 additions & 0 deletions generate_mocks.sh
Expand Up @@ -35,6 +35,8 @@ mockgen -source=policy_set.go -destination=mocks/policy_set_mocks.go -package=mo
mockgen -source=policy_set_parameter.go -destination=mocks/policy_set_parameter_mocks.go -package=mocks
mockgen -source=policy_set_version.go -destination=mocks/policy_set_version_mocks.go -package=mocks
mockgen -source=registry_module.go -destination=mocks/registry_module_mocks.go -package=mocks
mockgen -source=registry_provider.go -destination=mocks/registry_provider_mocks.go -package=mocks
mockgen -source=registry_provider_version.go -destination=mocks/registry_provider_version_mocks.go -package=mocks
mockgen -source=run.go -destination=mocks/run_mocks.go -package=mocks
mockgen -source=run_task.go -destination=mocks/run_tasks.go -package=mocks
mockgen -source=run_trigger.go -destination=mocks/run_trigger_mocks.go -package=mocks
Expand Down
94 changes: 82 additions & 12 deletions helper_test.go
Expand Up @@ -10,6 +10,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"math/rand"
"os"
"sync"
"testing"
Expand Down Expand Up @@ -761,20 +762,29 @@ func createPrivateRegistryProvider(t *testing.T, client *Client, org *Organizati

ctx := context.Background()

privateName := PrivateRegistry

options := RegistryProviderCreateOptions{
Name: String("tst-name-" + randomString(t)),
Namespace: &org.Name,
RegistryName: &privateName,
Name: "tst-name-" + randomString(t),
Namespace: org.Name,
RegistryName: PrivateRegistry,
}

prv, err := client.RegistryProviders.Create(ctx, org.Name, options)

if err != nil {
t.Fatal(err)
}

prv.Organization = org

return prv, func() {
if err := client.RegistryProviders.Delete(ctx, org.Name, prv.RegistryName, prv.Namespace, prv.Name); err != nil {
id := RegistryProviderID {
OrganizationName: org.Name,
RegistryName: prv.RegistryName,
Namespace: prv.Namespace,
Name: prv.Name,
}

if err := client.RegistryProviders.Delete(ctx, id); err != nil {
t.Errorf("Error destroying registry provider! WARNING: Dangling resources\n"+
"may exist! The full error is shown below.\n\n"+
"Registry Provider: %s/%s\nError: %s", prv.Namespace, prv.Name, err)
Expand All @@ -795,20 +805,29 @@ func createPublicRegistryProvider(t *testing.T, client *Client, org *Organizatio

ctx := context.Background()

publicName := PublicRegistry

options := RegistryProviderCreateOptions{
Name: String("tst-name-" + randomString(t)),
Namespace: String("tst-namespace-" + randomString(t)),
RegistryName: &publicName,
Name: "tst-name-" + randomString(t),
Namespace: "tst-namespace-" + randomString(t),
RegistryName: PublicRegistry,
}

prv, err := client.RegistryProviders.Create(ctx, org.Name, options)

if err != nil {
t.Fatal(err)
}

prv.Organization = org

return prv, func() {
if err := client.RegistryProviders.Delete(ctx, org.Name, prv.RegistryName, prv.Namespace, prv.Name); err != nil {
id := RegistryProviderID {
OrganizationName: org.Name,
RegistryName: prv.RegistryName,
Namespace: prv.Namespace,
Name: prv.Name,
}

if err := client.RegistryProviders.Delete(ctx, id); err != nil {
t.Errorf("Error destroying registry provider! WARNING: Dangling resources\n"+
"may exist! The full error is shown below.\n\n"+
"Registry Provider: %s/%s\nError: %s", prv.Namespace, prv.Name, err)
Expand All @@ -820,6 +839,53 @@ func createPublicRegistryProvider(t *testing.T, client *Client, org *Organizatio
}
}

func createRegistryProviderVersion(t *testing.T, client *Client, provider *RegistryProvider) (*RegistryProviderVersion, func()) {
var providerCleanup func()

if provider == nil {
provider, providerCleanup = createPrivateRegistryProvider(t, client, nil)
}

providerID := RegistryProviderID {
OrganizationName: provider.Organization.Name,
RegistryName: provider.RegistryName,
Namespace: provider.Namespace,
Name: provider.Name,
}

ctx := context.Background()

options := RegistryProviderVersionCreateOptions{
Version: randomSemver(t),
KeyID: randomString(t),
}

prvv, err := client.RegistryProviderVersions.Create(ctx, providerID, options)

if err != nil {
t.Fatal(err)
}

prvv.RegistryProvider = provider

return prvv, func() {
id := RegistryProviderVersionID {
Version: options.Version,
RegistryProviderID: providerID,
}

if err := client.RegistryProviderVersions.Delete(ctx, id); err != nil {
t.Errorf("Error destroying registry provider version! WARNING: Dangling resources\n"+
"may exist! The full error is shown below.\n\n"+
"Registry Provider Version: %s/%s/%s\nError: %s", prvv.RegistryProvider.Namespace, prvv.RegistryProvider.Name, prvv.Version, err)
}

if providerCleanup != nil {
providerCleanup()
}
}
}

func createSSHKey(t *testing.T, client *Client, org *Organization) (*SSHKey, func()) {
var orgCleanup func()

Expand Down Expand Up @@ -1340,6 +1406,10 @@ func randomString(t *testing.T) string {
return v
}

func randomSemver(t *testing.T) string {
return fmt.Sprintf("%d.%d.%d", rand.Intn(99)+3, rand.Intn(99)+1, rand.Intn(99)+1)
}

// skips a test if the environment is for Terraform Cloud.
func skipIfCloud(t *testing.T) {
if !enterpriseEnabled() {
Expand Down

0 comments on commit 52b33a2

Please sign in to comment.