-
Notifications
You must be signed in to change notification settings - Fork 102
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
[WAYP-2742] Support no-code workspace upgrades #935
Changes from all commits
e69da9f
bad5fdb
4972402
db938f5
e38f481
1ab7107
713c235
f2ef3aa
ca91a51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -385,3 +385,118 @@ func TestRegistryNoCodeModulesCreateWorkspace(t *testing.T) { | |
r.Error(err) | ||
}) | ||
} | ||
|
||
func TestRegistryNoCodeModuleWorkspaceUpgrade(t *testing.T) { | ||
skipUnlessBeta(t) | ||
|
||
client := testClient(t) | ||
ctx := context.Background() | ||
r := require.New(t) | ||
|
||
orgTest, orgTestCleanup := createOrganization(t, client) | ||
defer orgTestCleanup() | ||
|
||
org, err := client.Organizations.Read(ctx, orgTest.Name) | ||
r.NoError(err) | ||
r.NotNil(org) | ||
|
||
githubIdentifier := os.Getenv("GITHUB_REGISTRY_NO_CODE_MODULE_IDENTIFIER") | ||
if githubIdentifier == "" { | ||
t.Skip("Export a valid GITHUB_REGISTRY_NO_CODE_MODULE_IDENTIFIER before running this test") | ||
} | ||
|
||
token, cleanupToken := createOAuthToken(t, client, org) | ||
defer cleanupToken() | ||
|
||
rmOpts := RegistryModuleCreateWithVCSConnectionOptions{ | ||
VCSRepo: &RegistryModuleVCSRepoOptions{ | ||
OrganizationName: String(org.Name), | ||
Identifier: String(githubIdentifier), | ||
Tags: Bool(true), | ||
OAuthTokenID: String(token.ID), | ||
DisplayIdentifier: String(githubIdentifier), | ||
}, | ||
InitialVersion: String("1.0.0"), | ||
} | ||
|
||
// create the module | ||
rm, err := client.RegistryModules.CreateWithVCSConnection(ctx, rmOpts) | ||
r.NoError(err) | ||
|
||
// create the no-code module | ||
ncm, err := client.RegistryNoCodeModules.Create(ctx, org.Name, RegistryNoCodeModuleCreateOptions{ | ||
RegistryModule: rm, | ||
Enabled: Bool(true), | ||
VariableOptions: nil, | ||
}) | ||
r.NoError(err) | ||
r.NotNil(ncm) | ||
|
||
// We sleep for 10 seconds to let the module finish getting ready | ||
time.Sleep(time.Second * 10) | ||
|
||
// update the module's pinned version to be 1.0.0 | ||
// NOTE: This is done here as an update instead of at create time, because | ||
// that results in the following error: | ||
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. Is that behavior expected? 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 am unsure - I am new to using that API endpoint; however, it seems like it should work with the version # provided. |
||
// Validation failed: Provided version pin is not equal to latest or provided | ||
// string does not represent an existing version of the module. | ||
uncm, err := client.RegistryNoCodeModules.Update(ctx, ncm.ID, RegistryNoCodeModuleUpdateOptions{ | ||
RegistryModule: rm, | ||
VersionPin: "1.0.0", | ||
}) | ||
r.NoError(err) | ||
r.NotNil(uncm) | ||
|
||
// create a workspace, which will be attempted to be updated during the test | ||
wn := fmt.Sprintf("foo-%s", randomString(t)) | ||
sn := "my-app" | ||
su := "http://my-app.com" | ||
w, err := client.RegistryNoCodeModules.CreateWorkspace( | ||
ctx, | ||
uncm.ID, | ||
&RegistryNoCodeModuleCreateWorkspaceOptions{ | ||
Name: wn, | ||
SourceName: String(sn), | ||
SourceURL: String(su), | ||
}, | ||
) | ||
r.NoError(err) | ||
r.NotNil(w) | ||
|
||
// update the module's pinned version | ||
uncm, err = client.RegistryNoCodeModules.Update(ctx, ncm.ID, RegistryNoCodeModuleUpdateOptions{ | ||
VersionPin: "1.0.1", | ||
}) | ||
r.NoError(err) | ||
r.NotNil(uncm) | ||
|
||
t.Run("test upgrading a workspace via a no-code module", func(t *testing.T) { | ||
_, err = client.RegistryNoCodeModules.UpgradeWorkspace( | ||
ctx, | ||
ncm.ID, | ||
w.ID, | ||
&RegistryNoCodeModuleUpgradeWorkspaceOptions{}, | ||
) | ||
r.NoError(err) | ||
}) | ||
|
||
t.Run("fail to upgrade workspace with invalid no-code module", func(t *testing.T) { | ||
_, err = client.RegistryNoCodeModules.UpgradeWorkspace( | ||
ctx, | ||
ncm.ID+"-invalid", | ||
w.ID, | ||
&RegistryNoCodeModuleUpgradeWorkspaceOptions{}, | ||
) | ||
r.Error(err) | ||
}) | ||
|
||
t.Run("fail to upgrade workspace with invalid workspace ID", func(t *testing.T) { | ||
_, err = client.RegistryNoCodeModules.UpgradeWorkspace( | ||
ctx, | ||
ncm.ID, | ||
w.ID+"-invalid", | ||
&RegistryNoCodeModuleUpgradeWorkspaceOptions{}, | ||
) | ||
r.Error(err) | ||
}) | ||
} |
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.
Can we also add a comment/description on top of this method?
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.
Updated!