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
Feature: add support for applying/removing variable set against workspaces #375
Changes from 8 commits
55d57b8
655808a
37c6607
3087f65
3da9f34
4c0382e
69fd1c5
1e1177a
938724d
1e64cb4
ba9fb5d
9b47554
bd4f215
0fac7ae
1993cd9
8273360
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 |
---|---|---|
|
@@ -190,6 +190,68 @@ func TestVariableSetsDelete(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestVariableSetsApplyToAndRemoveFromWorkspaces(t *testing.T) { | ||
client := testClient(t) | ||
ctx := context.Background() | ||
|
||
orgTest, orgTestCleanup := createOrganization(t, client) | ||
defer orgTestCleanup() | ||
|
||
vsTest, _ := createVariableSet(t, client, orgTest, VariableSetCreateOptions{}) | ||
byronwolfman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
wTest1, _ := createWorkspace(t, client, orgTest) | ||
wTest2, _ := createWorkspace(t, client, orgTest) | ||
|
||
t.Run("with first workspace added", func(t *testing.T) { | ||
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. Would love to see some test cases for invalid options 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. Cheers, will add some more test cases! 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. |
||
options := VariableSetApplyToWorkspacesOptions{ | ||
Workspaces: []*Workspace{wTest1}, | ||
} | ||
|
||
err := client.VariableSets.ApplyToWorkspaces(ctx, vsTest.ID, &options) | ||
require.NoError(t, err) | ||
|
||
vsAfter, err := client.VariableSets.Read(ctx, vsTest.ID, nil) | ||
require.NoError(t, err) | ||
|
||
// Variable set should be applied to [wTest1] | ||
assert.Equal(t, 1, len(vsAfter.Workspaces)) | ||
assert.Equal(t, wTest1.ID, vsAfter.Workspaces[0].ID) | ||
}) | ||
|
||
t.Run("with second workspace added", func(t *testing.T) { | ||
options := VariableSetApplyToWorkspacesOptions{ | ||
Workspaces: []*Workspace{wTest2}, | ||
} | ||
|
||
err := client.VariableSets.ApplyToWorkspaces(ctx, vsTest.ID, &options) | ||
require.NoError(t, err) | ||
|
||
vsAfter, err := client.VariableSets.Read(ctx, vsTest.ID, nil) | ||
require.NoError(t, err) | ||
|
||
// Variable set should be applied to [wTest1, wTest2] | ||
assert.Equal(t, 2, len(vsAfter.Workspaces)) | ||
assert.Equal(t, wTest1.ID, vsAfter.Workspaces[0].ID) | ||
assert.Equal(t, wTest2.ID, vsAfter.Workspaces[1].ID) | ||
}) | ||
|
||
t.Run("with first workspace removed", func(t *testing.T) { | ||
options := VariableSetRemoveFromWorkspacesOptions{ | ||
Workspaces: []*Workspace{wTest1}, | ||
} | ||
|
||
err := client.VariableSets.RemoveFromWorkspaces(ctx, vsTest.ID, &options) | ||
require.NoError(t, err) | ||
|
||
vsAfter, err := client.VariableSets.Read(ctx, vsTest.ID, nil) | ||
require.NoError(t, err) | ||
|
||
// Variable set should be applied to [wTest2] | ||
assert.Equal(t, 1, len(vsAfter.Workspaces)) | ||
assert.Equal(t, wTest2.ID, vsAfter.Workspaces[0].ID) | ||
}) | ||
} | ||
|
||
func TestVariableSetsUpdateWorkspaces(t *testing.T) { | ||
client := testClient(t) | ||
ctx := context.Background() | ||
|
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.
We've established a convention for v1.0 that lays out the structure for any given file: 1) Interface/Struct definitions, 2) Receiver methods and 3) validate/helper methods.
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.
Just to be clear, it should be all structs at the top of the file, followed by receiver methods and so on...
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.
Cheers, happy to move these. To be clear: would you like me to move just these newly-added structs, or all previously-existing ones too? It looks like workspace.tf follows the convention you're describing as a matter of prior art.
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.
Yes if you would not mind reorganizing the file that would be great! 🚀
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.
Addressed, but this may make the diff somewhat more difficult to read. I've split the re-arrangement into its own commit, here: ba9fb5d