Skip to content

Commit

Permalink
Add test case to ensure we remove ACLs from state if they have been r…
Browse files Browse the repository at this point in the history
…emoved outside of terraform
  • Loading branch information
Mongey committed Nov 10, 2022
1 parent deaf6c1 commit 725dbc6
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions kafka/resource_kafka_acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,58 @@ func TestAcc_ACLCreateAndUpdate(t *testing.T) {
aclResourceName := fmt.Sprintf("syslog-%s", u)
bs := testBootstrapServers[0]

r.Test(t, r.TestCase{
ProviderFactories: overrideProviderFactory(),
PreCheck: func() { testAccPreCheck(t) },
CheckDestroy: func(s *terraform.State) error { return testAccCheckAclDestroy(aclResourceName) },
Steps: []r.TestStep{
{
Config: cfg(t, bs, fmt.Sprintf(testResourceACL_initialConfig, aclResourceName)),
Check: testResourceACL_initialCheck,
},
{
Config: cfg(t, bs, fmt.Sprintf(testResourceACL_initialConfig, aclResourceName)),
PlanOnly: true,
PreConfig: func() {
client := testProvider.Meta().(*LazyClient)
acl := StringlyTypedACL{
ACL{
Principal: "User:Alice",
Host: "*",
Operation: "Write",
PermissionType: "Allow",
},
Resource{
Type: "Topic",
Name: aclResourceName,
PatternTypeFilter: "Literal",
},
}
err := client.DeleteACL(acl)
if err != nil {
t.Fatal(err)
}
},
ExpectNonEmptyPlan: true,
Check: func(s *terraform.State) error {
if len(s.Modules[0].Resources) != 0 {
return fmt.Errorf("Expected no resources to exist got %d", len(s.Modules[0].Resources))
}
return nil
},
},
},
})
}

func TestAcc_ACLDeletedOutsideOfTerraform(t *testing.T) {
u, err := uuid.GenerateUUID()
if err != nil {
t.Fatal(err)
}
aclResourceName := fmt.Sprintf("syslog-%s", u)
bs := testBootstrapServers[0]

r.Test(t, r.TestCase{
ProviderFactories: overrideProviderFactory(),
PreCheck: func() { testAccPreCheck(t) },
Expand Down

0 comments on commit 725dbc6

Please sign in to comment.