Skip to content

Commit

Permalink
Merge branch 'develop' into fix/SCALRCORE-18723
Browse files Browse the repository at this point in the history
  • Loading branch information
ablik committed Aug 25, 2021
2 parents a344793 + 8e91044 commit 2102a58
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
9 changes: 5 additions & 4 deletions helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,11 @@ func createVariable(t *testing.T, client *Client, ws *Workspace) (*Variable, fun

ctx := context.Background()
v, err := client.Variables.Create(ctx, VariableCreateOptions{
Key: String(randomString(t)),
Value: String(randomString(t)),
Category: Category(CategoryTerraform),
Workspace: ws,
Key: String(randomString(t)),
Value: String(randomString(t)),
Category: Category(CategoryTerraform),
Description: String("Create by go-scalr test helper."),
Workspace: ws,
})
if err != nil {
t.Fatal(err)
Expand Down
21 changes: 14 additions & 7 deletions variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ type VariableList struct {

// Variable represents a Scalr variable.
type Variable struct {
ID string `jsonapi:"primary,vars"`
Key string `jsonapi:"attr,key"`
Value string `jsonapi:"attr,value"`
Category CategoryType `jsonapi:"attr,category"`
HCL bool `jsonapi:"attr,hcl"`
Sensitive bool `jsonapi:"attr,sensitive"`
Final bool `jsonapi:"attr,final"`
ID string `jsonapi:"primary,vars"`
Key string `jsonapi:"attr,key"`
Value string `jsonapi:"attr,value"`
Category CategoryType `jsonapi:"attr,category"`
Description string `jsonapi:"attr,description"`
HCL bool `jsonapi:"attr,hcl"`
Sensitive bool `jsonapi:"attr,sensitive"`
Final bool `jsonapi:"attr,final"`

// Relations
Workspace *Workspace `jsonapi:"relation,workspace"`
Expand All @@ -82,6 +83,9 @@ type VariableCreateOptions struct {
// Whether this is a Terraform or environment variable.
Category *CategoryType `jsonapi:"attr,category"`

// Variable description.
Description *string `jsonapi:"attr,description"`

// Whether to evaluate the value of the variable as a string of HCL code.
HCL *bool `jsonapi:"attr,hcl,omitempty"`

Expand Down Expand Up @@ -177,6 +181,9 @@ type VariableUpdateOptions struct {
// The value of the variable.
Value *string `jsonapi:"attr,value,omitempty"`

// The description of the variable.
Description *string `jsonapi:"attr,description,omitempty"`

// Whether to evaluate the value of the variable as a string of HCL code.
HCL *bool `jsonapi:"attr,hcl,omitempty"`

Expand Down
19 changes: 12 additions & 7 deletions variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ func TestVariablesCreate(t *testing.T) {

t.Run("when options has an empty string value", func(t *testing.T) {
options := VariableCreateOptions{
Key: String(randomVariableKey(t)),
Value: String(""),
Category: Category(CategoryShell),
Workspace: wsTest,
Key: String(randomVariableKey(t)),
Value: String(""),
Category: Category(CategoryShell),
Description: String("random variable test"),
Workspace: wsTest,
}

v, err := client.Variables.Create(ctx, options)
Expand All @@ -33,6 +34,7 @@ func TestVariablesCreate(t *testing.T) {
assert.Equal(t, *options.Key, v.Key)
assert.Equal(t, *options.Value, v.Value)
assert.Equal(t, *options.Category, v.Category)
assert.Equal(t, *options.Description, v.Description)
})

t.Run("when options is missing value", func(t *testing.T) {
Expand Down Expand Up @@ -156,6 +158,7 @@ func TestVariablesRead(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, vTest.ID, v.ID)
assert.Equal(t, vTest.Category, v.Category)
assert.Equal(t, vTest.Description, v.Description)
assert.Equal(t, vTest.HCL, v.HCL)
assert.Equal(t, vTest.Key, v.Key)
assert.Equal(t, vTest.Sensitive, v.Sensitive)
Expand Down Expand Up @@ -191,9 +194,10 @@ func TestVariablesUpdate(t *testing.T) {

t.Run("with valid options", func(t *testing.T) {
options := VariableUpdateOptions{
Key: String("newname"),
Value: String("newvalue"),
HCL: Bool(true),
Key: String("newname"),
Value: String("newvalue"),
Description: String("newdescription"),
HCL: Bool(true),
}

v, err := client.Variables.Update(ctx, vTest.ID, options)
Expand All @@ -202,6 +206,7 @@ func TestVariablesUpdate(t *testing.T) {
assert.Equal(t, *options.Key, v.Key)
assert.Equal(t, *options.HCL, v.HCL)
assert.Equal(t, *options.Value, v.Value)
assert.Equal(t, *options.Description, v.Description)
})

t.Run("when updating a subset of values", func(t *testing.T) {
Expand Down

0 comments on commit 2102a58

Please sign in to comment.