Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Marcin Białoń <[email protected]>
  • Loading branch information
mbialon committed Jul 5, 2024
1 parent 3bc9c80 commit 4d5311d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
30 changes: 30 additions & 0 deletions spacelift/data_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,36 @@ func TestModuleData(t *testing.T) {
},
})
})

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

testSteps(t, []resource.TestStep{
{
Config: fmt.Sprintf(`
resource "spacelift_module" "test" {
name = "test-module-%s"
administrative = false
branch = "main"
repository = "terraform-bacon-tasty"
raw_git {
namespace = "bacon"
url = "https://github.com/bacon/terraform-bacon-tasty.git"
}
}
data "spacelift_module" "test" {
module_id = spacelift_module.test.id
}
`, randomID),
Check: Resource(
"data.spacelift_module.test",
Attribute("raw_git.namespace", Equals("bacon")),
Attribute("raw_git.url", Equals("https://github.com/bacon/terraform-bacon-tasty.git")),
),
},
})
})
}

func TestModuleDataSpace(t *testing.T) {
Expand Down
35 changes: 33 additions & 2 deletions spacelift/resource_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestModuleResource(t *testing.T) {
Check: Resource(
"spacelift_module.test",
Attribute("id", Equals(fmt.Sprintf("terraform-default-github-module-%s", randomID))),
Attribute("administrative", Equals("true")),
Attribute("raw.git", Equals("true")),
Attribute("branch", Equals("master")),
Attribute("description", Equals("old description")),
SetEquals("labels", "one", "two"),
Expand All @@ -61,14 +61,45 @@ func TestModuleResource(t *testing.T) {
Config: config("new description", false, true),
Check: Resource(
"spacelift_module.test",
Attribute("description", Equals("new description")),
Attribute("raw_git.namespace", Equals("new description")),
Attribute("enable_local_preview", Equals("true")),
Attribute("protect_from_deletion", Equals("false")),
),
},
})
})

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

config := func() string {
return fmt.Sprintf(`
resource "spacelift_module" "test" {
name = "raw-git-%s"
administrative = false
branch = "main"
repository = "terraform-bacon-tasty"
raw_git {
namespace = "bacon"
url = "https://github.com/bacon/terraform-bacon-tasty.git"
}
}
`, randomID)
}

testSteps(t, []resource.TestStep{
{
Config: config(),
Check: Resource(
"spacelift_module.test",
Attribute("raw_git.namespace", Equals("bacon")),
Attribute("raw_git.url", Equals("https://github.com/bacon/terraform-bacon-tasty.git")),
),
},
})
})

t.Run("project root and custom name", func(t *testing.T) {
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)

Expand Down

0 comments on commit 4d5311d

Please sign in to comment.