Skip to content

Commit

Permalink
feat(api-keys): FIx
Browse files Browse the repository at this point in the history
  • Loading branch information
0michalsokolowski0 committed Aug 12, 2024
1 parent 3930029 commit 3d67dbd
Showing 1 changed file with 100 additions and 33 deletions.
133 changes: 100 additions & 33 deletions spacelift/resource_environment_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
)

func TestEnvironmentVariableResource(t *testing.T) {
t.Run("with a context", func(t *testing.T) {
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
const resourceName = "spacelift_environment_variable.test"

config := func(writeOnly bool) string {
t.Run("with a context", func(t *testing.T) {
config := func(randomID string, writeOnly bool, description string) string {
return fmt.Sprintf(`
resource "spacelift_context" "test" {
name = "My first context %s"
Expand All @@ -25,26 +25,110 @@ func TestEnvironmentVariableResource(t *testing.T) {
name = "BACON"
value = "is tasty"
write_only = %t
description = "Bacon is tasty"
description = %s
}
`, randomID, writeOnly)
`, randomID, writeOnly, description)
}

const resourceName = "spacelift_environment_variable.test"
t.Run("with description", func(t *testing.T) {
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)

testSteps(t, []resource.TestStep{
{
Config: config(randomID, true, "\"Bacon is tasty\""),
Check: Resource(
resourceName,
Attribute("id", IsNotEmpty()),
Attribute("checksum", Equals("4d5d01ea427b10dd483e8fce5b5149fb5a9814e9ee614176b756ca4a65c8f154")),
Attribute("context_id", Contains(randomID)),
Attribute("name", Equals("BACON")),
Attribute("value", Equals("4d5d01ea427b10dd483e8fce5b5149fb5a9814e9ee614176b756ca4a65c8f154")),
Attribute("write_only", Equals("true")),
Attribute("description", Equals("Bacon is tasty")),
AttributeNotPresent("module_id"),
AttributeNotPresent("stack_id"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: config(randomID, false, "\"Bacon is tasty\""),
Check: Resource(
resourceName,
Attribute("value", Equals("is tasty")),
Attribute("write_only", Equals("false")),
Attribute("description", Equals("Bacon is tasty")),
),
},
})
})

t.Run("null description", func(t *testing.T) {
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)

testSteps(t, []resource.TestStep{
{
Config: config(randomID, true, "null"),
Check: Resource(
resourceName,
Attribute("id", IsNotEmpty()),
Attribute("checksum", Equals("4d5d01ea427b10dd483e8fce5b5149fb5a9814e9ee614176b756ca4a65c8f154")),
Attribute("context_id", Contains(randomID)),
Attribute("name", Equals("BACON")),
Attribute("value", Equals("4d5d01ea427b10dd483e8fce5b5149fb5a9814e9ee614176b756ca4a65c8f154")),
Attribute("write_only", Equals("true")),
Attribute("description", IsEmpty()),
AttributeNotPresent("module_id"),
AttributeNotPresent("stack_id"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: config(randomID, false, "\"Bacon is tasty\""),
Check: Resource(
resourceName,
Attribute("value", Equals("is tasty")),
Attribute("write_only", Equals("false")),
Attribute("description", IsEmpty()),
),
},
})
})
})

t.Run("with a module", func(t *testing.T) {
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)

testSteps(t, []resource.TestStep{
{
Config: config(true),
Config: fmt.Sprintf(`
resource "spacelift_module" "test" {
name = "test-module-%s"
branch = "master"
repository = "terraform-bacon-tasty"
}
resource "spacelift_environment_variable" "test" {
module_id = spacelift_module.test.id
name = "BACON"
value = "is tasty"
description = "Bacon is tasty"
}
`, randomID),
Check: Resource(
"spacelift_environment_variable.test",
Attribute("id", IsNotEmpty()),
Attribute("checksum", Equals("4d5d01ea427b10dd483e8fce5b5149fb5a9814e9ee614176b756ca4a65c8f154")),
Attribute("context_id", Contains(randomID)),
Attribute("name", Equals("BACON")),
resourceName,
Attribute("module_id", Equals(fmt.Sprintf("terraform-default-test-module-%s", randomID))),
Attribute("value", Equals("4d5d01ea427b10dd483e8fce5b5149fb5a9814e9ee614176b756ca4a65c8f154")),
Attribute("write_only", Equals("true")),
Attribute("description", Equals("Bacon is tasty")),
AttributeNotPresent("module_id"),
AttributeNotPresent("context_id"),
AttributeNotPresent("stack_id"),
),
},
Expand All @@ -53,23 +137,9 @@ func TestEnvironmentVariableResource(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
{
Config: config(false),
Check: Resource(
"spacelift_environment_variable.test",
Attribute("value", Equals("is tasty")),
Attribute("write_only", Equals("false")),
Attribute("description", Equals("Bacon is tasty")),
),
},
})
})

t.Run("with a module", func(t *testing.T) {
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)

const resourceName = "spacelift_environment_variable.test"

// Without description
testSteps(t, []resource.TestStep{
{
Config: fmt.Sprintf(`
Expand All @@ -83,15 +153,14 @@ func TestEnvironmentVariableResource(t *testing.T) {
module_id = spacelift_module.test.id
name = "BACON"
value = "is tasty"
description = "Bacon is tasty"
}
`, randomID),
Check: Resource(
resourceName,
Attribute("module_id", Equals(fmt.Sprintf("terraform-default-test-module-%s", randomID))),
Attribute("value", Equals("4d5d01ea427b10dd483e8fce5b5149fb5a9814e9ee614176b756ca4a65c8f154")),
Attribute("write_only", Equals("true")),
Attribute("description", Equals("Bacon is tasty")),
Attribute("description", IsEmpty()),
AttributeNotPresent("context_id"),
AttributeNotPresent("stack_id"),
),
Expand All @@ -105,8 +174,6 @@ func TestEnvironmentVariableResource(t *testing.T) {
})

t.Run("with a stack", func(t *testing.T) {
const resourceName = "spacelift_environment_variable.test"

randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)

testSteps(t, []resource.TestStep{
Expand All @@ -126,7 +193,7 @@ func TestEnvironmentVariableResource(t *testing.T) {
}
`, randomID),
Check: Resource(
"spacelift_environment_variable.test",
resourceName,
Attribute("stack_id", StartsWith("test-stack-")),
Attribute("stack_id", Contains(randomID)),
Attribute("value", Equals("4d5d01ea427b10dd483e8fce5b5149fb5a9814e9ee614176b756ca4a65c8f154")),
Expand Down

0 comments on commit 3d67dbd

Please sign in to comment.