Skip to content

Commit

Permalink
depends_on and better checks
Browse files Browse the repository at this point in the history
  • Loading branch information
pkazmierczak committed Jul 31, 2024
1 parent baa7995 commit 552686d
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions nomad/resource_namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,17 @@ func TestResourceNamespace_deleteNSWithQuota(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testResourceNamespace_configWithQuota(nsName, quotaName),
Check: testResourceNamespace_initialCheck(nsName),
Check: resource.ComposeTestCheckFunc(
testResourceNamespace_initialCheck(nsName),
testResourceNamespaceWithQuota_check(nsName, quotaName),
),
},
},

CheckDestroy: testResourceNamespace_checkDestroy(nsName),
CheckDestroy: resource.ComposeTestCheckFunc(
testResourceNamespace_checkDestroy(nsName),
testResourceQuotaSpecification_checkDestroy(quotaName),
),
})
}

Expand Down Expand Up @@ -245,6 +251,7 @@ resource "nomad_namespace" "test" {
name = "%[1]s"
description = "A Terraform acctest namespace"
quota = "%[2]s"
depends_on = "test_quota"
meta = {
key = "value",
Expand Down Expand Up @@ -317,6 +324,21 @@ func testResourceNamespace_initialCheck(name string) resource.TestCheckFunc {
}
}

func testResourceNamespaceWithQuota_check(name, quota string) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := testProvider.Meta().(ProviderConfig).client
namespace, _, err := client.Namespaces().Info(name, nil)
if err != nil {
return fmt.Errorf("error reading back namespace %q: %s", name, err)
}

if namespace.Quota != quota {
return fmt.Errorf("expected quota spec to be %q, is %q in API", quota, namespace.Quota)
}
return nil
}
}

func testResourceNamespace_checkExists(name string) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := testProvider.Meta().(ProviderConfig).client
Expand Down

0 comments on commit 552686d

Please sign in to comment.