-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix tenant config drift and add test cases (#125)
* fix tenant drift and add test cases * fix lint * fix hcl array * fix hcl array * fix ci * fix ci * fix lint * fix ci * fix lint
- Loading branch information
Showing
2 changed files
with
107 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ package pulsar | |
import ( | ||
"fmt" | ||
"regexp" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/apache/pulsar-client-go/pulsaradmin/pkg/admin" | ||
|
@@ -189,3 +190,106 @@ resource "pulsar_tenant" "test" { | |
} | ||
`, url, tname) | ||
} | ||
|
||
const ( | ||
testPulsarTenantWithAdminRoles1 = "pulsar-tenant-admin-role-1" | ||
testPulsarTenantWithAdminRoles2 = "[email protected]" | ||
) | ||
|
||
func TestTenantWithAdminRoles(t *testing.T) { | ||
tName := acctest.RandString(10) | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
testAccPreCheck(t) | ||
}, | ||
ProviderFactories: testAccProviderFactories, | ||
PreventPostDestroyRefresh: false, | ||
CheckDestroy: testPulsarTenantDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: strings.Replace(testPulsarTenantWithAdminRoles, "thanos", tName, 1), | ||
Check: resource.ComposeTestCheckFunc( | ||
testPulsarTenantExists("pulsar_tenant.test"), | ||
resource.TestCheckResourceAttr("pulsar_tenant.test", "admin_roles.#", "2"), | ||
resource.TestCheckTypeSetElemAttr("pulsar_tenant.test", "admin_roles.*", testPulsarTenantWithAdminRoles1), | ||
resource.TestCheckTypeSetElemAttr("pulsar_tenant.test", "admin_roles.*", testPulsarTenantWithAdminRoles2), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestTenantUpdateAdminRoles(t *testing.T) { | ||
tName := acctest.RandString(10) | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProviderFactories: testAccProviderFactories, | ||
PreventPostDestroyRefresh: false, | ||
CheckDestroy: testPulsarTenantDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: strings.Replace(testPulsarTenantWithAdminRoles, "thanos", tName, 1), | ||
Check: resource.ComposeTestCheckFunc( | ||
testPulsarTenantExists("pulsar_tenant.test"), | ||
), | ||
}, | ||
{ | ||
Config: strings.Replace(testPulsarTenantWithAdminRolesUpdated, "thanos", tName, 1), | ||
Check: resource.ComposeTestCheckFunc( | ||
testPulsarTenantExists("pulsar_tenant.test"), | ||
resource.TestCheckResourceAttr("pulsar_tenant.test", "admin_roles.#", "2"), | ||
resource.TestCheckTypeSetElemAttr("pulsar_tenant.test", "admin_roles.*", testPulsarTenantWithAdminRoles1), | ||
resource.TestCheckTypeSetElemAttr("pulsar_tenant.test", "admin_roles.*", testPulsarTenantWithAdminRoles2), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestTenantAdminRolesDrift(t *testing.T) { | ||
tName := acctest.RandString(10) | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProviderFactories: testAccProviderFactories, | ||
PreventPostDestroyRefresh: false, | ||
CheckDestroy: testPulsarTenantDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: strings.Replace(testPulsarTenantWithAdminRoles, "thanos", tName, 1), | ||
Check: resource.ComposeTestCheckFunc( | ||
testPulsarTenantExists("pulsar_tenant.test"), | ||
resource.TestCheckResourceAttr("pulsar_tenant.test", "admin_roles.#", "2"), | ||
resource.TestCheckTypeSetElemAttr("pulsar_tenant.test", "admin_roles.*", testPulsarTenantWithAdminRoles1), | ||
resource.TestCheckTypeSetElemAttr("pulsar_tenant.test", "admin_roles.*", testPulsarTenantWithAdminRoles2), | ||
), | ||
}, | ||
{ | ||
Config: strings.Replace(testPulsarTenantWithAdminRoles, "thanos", tName, 1), | ||
PlanOnly: true, | ||
ExpectNonEmptyPlan: false, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
var testPulsarTenantWithAdminRoles = fmt.Sprintf(` | ||
provider "pulsar" { | ||
web_service_url = "%s" | ||
} | ||
resource "pulsar_tenant" "test" { | ||
tenant = "thanos" | ||
allowed_clusters = ["standalone"] | ||
admin_roles = ["%s", "%s"] | ||
}`, testWebServiceURL, testPulsarTenantWithAdminRoles1, testPulsarTenantWithAdminRoles2) | ||
|
||
var testPulsarTenantWithAdminRolesUpdated = fmt.Sprintf(` | ||
provider "pulsar" { | ||
web_service_url = "%s" | ||
} | ||
resource "pulsar_tenant" "test" { | ||
tenant = "thanos" | ||
allowed_clusters = ["standalone"] | ||
admin_roles = ["%s", "%s"] | ||
}`, testWebServiceURL, testPulsarTenantWithAdminRoles2, testPulsarTenantWithAdminRoles1) |