From 6bd3eadfb42e188d41be39af5ff891390392965d Mon Sep 17 00:00:00 2001 From: Rexredinger Date: Tue, 22 Mar 2022 17:32:31 -0400 Subject: [PATCH] _Apply_ variable sets --- variable_set.go | 14 +++++++------- variable_set_test.go | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/variable_set.go b/variable_set.go index d4b50feb0..b2415501d 100644 --- a/variable_set.go +++ b/variable_set.go @@ -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 { @@ -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. @@ -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 } diff --git a/variable_set_test.go b/variable_set_test.go index 23129c7e2..d57363ef0 100644 --- a/variable_set_test.go +++ b/variable_set_test.go @@ -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() @@ -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))