Skip to content

Commit

Permalink
_Apply_ variable sets
Browse files Browse the repository at this point in the history
  • Loading branch information
rexredinger committed Mar 22, 2022
1 parent 7ef83ee commit 6bd3ead
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions variable_set.go
Expand Up @@ -29,8 +29,8 @@ type VariableSets interface {
// Delete a variable set by ID.
Delete(ctx context.Context, variableSetID string) error

// Add and remove workspace assignments to match the supplied list
Assign(ctx context.Context, variableSetID string, options *VariableSetAssignOptions) (*VariableSet, error)
// Update list of workspaces to which the variable set is applied to match the supplied list
Apply(ctx context.Context, variableSetID string, options *VariableSetApplyOptions) (*VariableSet, error)
}

type variableSets struct {
Expand Down Expand Up @@ -234,8 +234,8 @@ func (s *variableSets) Delete(ctx context.Context, variableSetID string) error {
return s.client.do(ctx, req, nil)
}

// VariableSetAssignOptions represents a subset of update options specifically for assigning variable sets to workspaces
type VariableSetAssignOptions struct {
// VariableSetApplyOptions represents a subset of update options specifically for applying variable sets to workspaces
type VariableSetAapplyOptions struct {
// Type is a public field utilized by JSON:API to
// set the resource type via the field tag.
// It is not a user-defined value and does not need to be set.
Expand All @@ -245,12 +245,12 @@ type VariableSetAssignOptions struct {
// Used to set the variable set from Global to not Global if necessary
Global *bool `jsonapi:"attr,global"`

// The workspaces to be assigned to. An empty set means remove all assignments
// The workspaces to be applied to. An empty set means remove all applied
Workspaces []*Workspace `jsonapi:"relation,workspaces"`
}

// Update variable set assignments to match the supplied workspaces list.
func (s *variableSets) Assign(ctx context.Context, variableSetID string, options *VariableSetAssignOptions) (*VariableSet, error) {
// Update variable set to be applied to only the workspaces in the supplied list.
func (s *variableSets) Apply(ctx context.Context, variableSetID string, options *VariableSetApplyOptions) (*VariableSet, error) {
if options == nil || options.Workspaces == nil {
return nil, ErrRequiredWorkspacesList
}
Expand Down
10 changes: 5 additions & 5 deletions variable_set_test.go
Expand Up @@ -190,7 +190,7 @@ func TestVariableSetsDelete(t *testing.T) {
})
}

func TestVariableSetsAssign(t *testing.T) {
func TestVariableSetsApply(t *testing.T) {
client := testClient(t)
ctx := context.Background()

Expand All @@ -202,21 +202,21 @@ func TestVariableSetsAssign(t *testing.T) {
wTest, _ := createWorkspace(t, client, orgTest)

t.Run("with valid workspaces", func(t *testing.T) {
options := VariableSetAssignOptions{
options := VariableSetApplyOptions{
Workspaces: []*Workspace{wTest},
}

vsAfter, err := client.VariableSets.Assign(ctx, vsTest.ID, &options)
vsAfter, err := client.VariableSets.Apply(ctx, vsTest.ID, &options)
require.NoError(t, err)

assert.Equal(t, len(options.Workspaces), len(vsAfter.Workspaces))
assert.Equal(t, options.Workspaces[0].ID, vsAfter.Workspaces[0].ID)

options = VariableSetAssignOptions{
options = VariableSetApplyOptions{
Workspaces: []*Workspace{},
}

vsAfter, err = client.VariableSets.Assign(ctx, vsTest.ID, &options)
vsAfter, err = client.VariableSets.Apply(ctx, vsTest.ID, &options)
require.NoError(t, err)

assert.Equal(t, len(options.Workspaces), len(vsAfter.Workspaces))
Expand Down

0 comments on commit 6bd3ead

Please sign in to comment.