New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ Add private registry provider version #405
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import ( | |
"errors" | ||
"fmt" | ||
"io/ioutil" | ||
"math/rand" | ||
"os" | ||
"sync" | ||
"testing" | ||
|
@@ -717,23 +718,24 @@ func createRegistryModuleWithVersion(t *testing.T, client *Client, org *Organiza | |
} | ||
|
||
func createRunTask(t *testing.T, client *Client, org *Organization) (*RunTask, func()) { | ||
runTaskURL := os.Getenv("TFC_RUN_TASK_URL") | ||
if runTaskURL == "" { | ||
t.Error("Cannot create a run task with an empty URL. You must set TFC_RUN_TASK_URL for run task related tests.") | ||
} | ||
|
||
var orgCleanup func() | ||
|
||
if org == nil { | ||
org, orgCleanup = createOrganization(t, client) | ||
} | ||
|
||
runTaskURL := os.Getenv("TFC_RUN_TASK_URL") | ||
if runTaskURL == "" { | ||
t.Error("Cannot create a run task with an empty URL. You must set TFC_RUN_TASK_URL for run task related tests.") | ||
} | ||
|
||
ctx := context.Background() | ||
r, err := client.RunTasks.Create(ctx, org.Name, RunTaskCreateOptions{ | ||
Name: "tst-" + randomString(t), | ||
URL: runTaskURL, | ||
Category: "task", | ||
}) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
@@ -751,6 +753,139 @@ func createRunTask(t *testing.T, client *Client, org *Organization) (*RunTask, f | |
} | ||
} | ||
|
||
func createPrivateRegistryProvider(t *testing.T, client *Client, org *Organization) (*RegistryProvider, func()) { | ||
var orgCleanup func() | ||
|
||
if org == nil { | ||
org, orgCleanup = createOrganization(t, client) | ||
} | ||
|
||
ctx := context.Background() | ||
|
||
options := RegistryProviderCreateOptions{ | ||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should return something here, since prv may be nil and the next line will panic There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
prv.Organization = org | ||
|
||
return prv, func() { | ||
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) | ||
} | ||
|
||
if orgCleanup != nil { | ||
orgCleanup() | ||
} | ||
} | ||
} | ||
|
||
func createPublicRegistryProvider(t *testing.T, client *Client, org *Organization) (*RegistryProvider, func()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💅 this and the previous method have so much in common, I'm wondering if there should be a third method that parameterizes PublicRegistry/PrivateRegistry ? |
||
var orgCleanup func() | ||
|
||
if org == nil { | ||
org, orgCleanup = createOrganization(t, client) | ||
} | ||
|
||
ctx := context.Background() | ||
|
||
options := RegistryProviderCreateOptions{ | ||
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() { | ||
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) | ||
} | ||
|
||
if orgCleanup != nil { | ||
orgCleanup() | ||
} | ||
} | ||
} | ||
|
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same 'return' concern as above |
||
} | ||
|
||
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() | ||
|
||
|
@@ -1271,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() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this error is used (And if I understand the point of the error, the value should be "registry-providers")