Skip to content

Commit

Permalink
Merge pull request hashicorp#64 from hashicorp/variables-create-allow…
Browse files Browse the repository at this point in the history
…-empty-string

Allow creation of variables with no value
  • Loading branch information
justincampbell authored Mar 22, 2019
2 parents ddfaa5e + 4278110 commit 9dd9fcc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
3 changes: 0 additions & 3 deletions variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ func (o VariableCreateOptions) valid() error {
if !validString(o.Key) {
return errors.New("key is required")
}
if !validString(o.Value) {
return errors.New("value is required")
}
if o.Category == nil {
return errors.New("category is required")
}
Expand Down
30 changes: 28 additions & 2 deletions variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,41 @@ func TestVariablesCreate(t *testing.T) {
assert.EqualError(t, err, "key is required")
})

t.Run("when options has an empty key", func(t *testing.T) {
options := VariableCreateOptions{
Key: String(""),
Value: String(randomString(t)),
Category: Category(CategoryTerraform),
Workspace: wTest,
}

_, err := client.Variables.Create(ctx, options)
assert.EqualError(t, err, "key is required")
})

t.Run("when options is missing value", func(t *testing.T) {
options := VariableCreateOptions{
Key: String(randomString(t)),
Category: Category(CategoryTerraform),
Workspace: wTest,
}

_, err := client.Variables.Create(ctx, options)
assert.EqualError(t, err, "value is required")
v, err := client.Variables.Create(ctx, options)
require.NoError(t, err)
assert.Equal(t, "", v.Value)
})

t.Run("when options has an empty string value", func(t *testing.T) {
options := VariableCreateOptions{
Key: String(randomString(t)),
Value: String(""),
Category: Category(CategoryTerraform),
Workspace: wTest,
}

v, err := client.Variables.Create(ctx, options)
require.NoError(t, err)
assert.Equal(t, *options.Value, v.Value)
})

t.Run("when options is missing category", func(t *testing.T) {
Expand Down

0 comments on commit 9dd9fcc

Please sign in to comment.