Skip to content

Commit

Permalink
fix: Acceptance Test Enhacements (#414)
Browse files Browse the repository at this point in the history
* fix: Acceptance Test Enhancements
* fix: Fixed Policy Access Inspection test
* fix: Fixed cbi integration test
  • Loading branch information
willguibr authored Feb 12, 2024
1 parent 0cda244 commit a67ae41
Show file tree
Hide file tree
Showing 13 changed files with 291 additions and 259 deletions.
6 changes: 3 additions & 3 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ testacc:
build13: GOOS=$(shell go env GOOS)
build13: GOARCH=$(shell go env GOARCH)
ifeq ($(OS),Windows_NT) # is Windows_NT on XP, 2000, 7, Vista, 10...
build13: DESTINATION=$(APPDATA)/terraform.d/plugins/$(ZPA_PROVIDER_NAMESPACE)/3.1.0/$(GOOS)_$(GOARCH)
build13: DESTINATION=$(APPDATA)/terraform.d/plugins/$(ZPA_PROVIDER_NAMESPACE)/3.1.1/$(GOOS)_$(GOARCH)
else
build13: DESTINATION=$(HOME)/.terraform.d/plugins/$(ZPA_PROVIDER_NAMESPACE)/3.1.0/$(GOOS)_$(GOARCH)
build13: DESTINATION=$(HOME)/.terraform.d/plugins/$(ZPA_PROVIDER_NAMESPACE)/3.1.1/$(GOOS)_$(GOARCH)
endif
build13: fmtcheck
@echo "==> Installing plugin to $(DESTINATION)"
@mkdir -p $(DESTINATION)
go build -o $(DESTINATION)/terraform-provider-zpa_v3.1.0
go build -o $(DESTINATION)/terraform-provider-zpa_v3.1.1

coverage: test
@echo "✓ Opening coverage for unit tests ..."
Expand Down
2 changes: 1 addition & 1 deletion zpa/common/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package common

var version = "3.0.5"
var version = "3.1.1"

// Version returns version of provider
func Version() string {
Expand Down
17 changes: 15 additions & 2 deletions zpa/data_source_zpa_inspection_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ func dataSourceInspectionProfileRead(d *schema.ResourceData, m interface{}) erro
}
if resp != nil {
d.SetId(resp.ID)
_ = d.Set("common_global_override_actions_config", resp.CommonGlobalOverrideActionsConfig)
_ = d.Set("creation_time", resp.CreationTime)
_ = d.Set("description", resp.Description)
_ = d.Set("global_control_actions", resp.GlobalControlActions)
Expand All @@ -406,7 +405,21 @@ func dataSourceInspectionProfileRead(d *schema.ResourceData, m interface{}) erro
return err
}

if err := d.Set("web_socket_controls", flattenPredefinedControlsSimple(resp.WebSocketControls)); err != nil {
// Flattening ThreatLabz Controls
threatLabzIDs := make([]string, len(resp.ThreatLabzControls))
for i, control := range resp.ThreatLabzControls {
threatLabzIDs[i] = control.ID
}
if err := d.Set("threatlabz_controls", flattenIDList(threatLabzIDs)); err != nil {
return err
}

// Flattening WebSocket Controls
websocketIDs := make([]string, len(resp.WebSocketControls))
for i, control := range resp.WebSocketControls {
websocketIDs[i] = control.ID
}
if err := d.Set("websocket_controls", flattenIDList(websocketIDs)); err != nil {
return err
}
} else {
Expand Down
37 changes: 19 additions & 18 deletions zpa/provider_sweeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type testClient struct {
}

var testResourcePrefix = "tf-acc-test-"
var updateResourcePrefix = "tf-updated-"

func TestRunForcedSweeper(t *testing.T) {
if os.Getenv("ZPA_VCR_TF_ACC") != "" {
Expand Down Expand Up @@ -109,7 +110,7 @@ func sweepTestAppConnectorGroup(client *testClient) error {
sweeperLogger.Warn(fmt.Sprintf("Found %d resources to sweep", len(group)))
for _, b := range group {
// Check if the resource name has the required prefix before deleting it
if strings.HasPrefix(b.Name, testResourcePrefix) {
if strings.HasPrefix(b.Name, testResourcePrefix) || strings.HasPrefix(b.Name, updateResourcePrefix) {
if _, err := client.sdkClient.appconnectorgroup.Delete(b.ID); err != nil {
errorList = append(errorList, err)
continue
Expand All @@ -136,7 +137,7 @@ func sweepTestApplicationServer(client *testClient) error {
sweeperLogger.Warn(fmt.Sprintf("Found %d resources to sweep", len(server)))
for _, b := range server {
// Check if the resource name has the required prefix before deleting it
if strings.HasPrefix(b.Name, testResourcePrefix) {
if strings.HasPrefix(b.Name, testResourcePrefix) || strings.HasPrefix(b.Name, updateResourcePrefix) {
if _, err := client.sdkClient.appservercontroller.Delete(b.ID); err != nil {
errorList = append(errorList, err)
continue
Expand All @@ -163,7 +164,7 @@ func sweepTestApplicationSegment(client *testClient) error {
sweeperLogger.Warn(fmt.Sprintf("Found %d resources to sweep", len(appSegment)))
for _, b := range appSegment {
// Check if the resource name has the required prefix before deleting it
if strings.HasPrefix(b.Name, testResourcePrefix) {
if strings.HasPrefix(b.Name, testResourcePrefix) || strings.HasPrefix(b.Name, updateResourcePrefix) {
if _, err := client.sdkClient.applicationsegment.Delete(b.ID); err != nil {
errorList = append(errorList, err)
continue
Expand All @@ -190,7 +191,7 @@ func sweepTestApplicationSegmentBA(client *testClient) error {
sweeperLogger.Warn(fmt.Sprintf("Found %d resources to sweep", len(appSegmentBA)))
for _, b := range appSegmentBA {
// Check if the resource name has the required prefix before deleting it
if strings.HasPrefix(b.Name, testResourcePrefix) {
if strings.HasPrefix(b.Name, testResourcePrefix) || strings.HasPrefix(b.Name, updateResourcePrefix) {
if _, err := client.sdkClient.browseraccess.Delete(b.ID); err != nil {
errorList = append(errorList, err)
continue
Expand All @@ -217,7 +218,7 @@ func sweepTestApplicationInspection(client *testClient) error {
sweeperLogger.Warn(fmt.Sprintf("Found %d resources to sweep", len(appInspection)))
for _, b := range appInspection {
// Check if the resource name has the required prefix before deleting it
if strings.HasPrefix(b.Name, testResourcePrefix) {
if strings.HasPrefix(b.Name, testResourcePrefix) || strings.HasPrefix(b.Name, updateResourcePrefix) {
if _, err := client.sdkClient.applicationsegmentinspection.Delete(b.ID); err != nil {
errorList = append(errorList, err)
continue
Expand All @@ -244,7 +245,7 @@ func sweepTestApplicationPRA(client *testClient) error {
sweeperLogger.Warn(fmt.Sprintf("Found %d resources to sweep", len(pra)))
for _, b := range pra {
// Check if the resource name has the required prefix before deleting it
if strings.HasPrefix(b.Name, testResourcePrefix) {
if strings.HasPrefix(b.Name, testResourcePrefix) || strings.HasPrefix(b.Name, updateResourcePrefix) {
if _, err := client.sdkClient.applicationsegmentpra.Delete(b.ID); err != nil {
errorList = append(errorList, err)
continue
Expand All @@ -271,7 +272,7 @@ func sweepTestInspectionCustomControl(client *testClient) error {
sweeperLogger.Warn(fmt.Sprintf("Found %d resources to sweep", len(customControl)))
for _, b := range customControl {
// Check if the resource name has the required prefix before deleting it
if strings.HasPrefix(b.Name, testResourcePrefix) {
if strings.HasPrefix(b.Name, testResourcePrefix) || strings.HasPrefix(b.Name, updateResourcePrefix) {
if _, err := client.sdkClient.inspection_custom_controls.Delete(b.ID); err != nil {
errorList = append(errorList, err)
continue
Expand All @@ -298,7 +299,7 @@ func sweepTestInspectionProfile(client *testClient) error {
sweeperLogger.Warn(fmt.Sprintf("Found %d resources to sweep", len(profile)))
for _, b := range profile {
// Check if the resource name has the required prefix before deleting it
if strings.HasPrefix(b.Name, testResourcePrefix) {
if strings.HasPrefix(b.Name, testResourcePrefix) || strings.HasPrefix(b.Name, updateResourcePrefix) {
if _, err := client.sdkClient.inspection_profile.Delete(b.ID); err != nil {
errorList = append(errorList, err)
continue
Expand Down Expand Up @@ -334,7 +335,7 @@ func sweepTestLSSConfigController(client *testClient) error {

for _, b := range lssConfig {
// Check if the resource name has the required prefix before deleting it
if strings.HasPrefix(b.LSSConfig.Name, testResourcePrefix) {
if strings.HasPrefix(b.LSSConfig.Name, testResourcePrefix) || strings.HasPrefix(b.LSSConfig.Name, updateResourcePrefix) {
// Attempt to delete the resource
_, err := client.sdkClient.lssconfigcontroller.Delete(b.ID)
if err != nil {
Expand Down Expand Up @@ -408,7 +409,7 @@ func sweepTestAccessPolicyRuleByType(client *testClient) error {
}

// Check if the resource name has the required prefix before deleting it
if strings.HasPrefix(rule.Name, testResourcePrefix) {
if strings.HasPrefix(rule.Name, testResourcePrefix) || strings.HasPrefix(rule.Name, updateResourcePrefix) {
// Use the fetched PolicySetID for deletion
if _, err := client.sdkClient.policysetcontroller.Delete(policySetID, rule.ID); err != nil {
errorList = append(errorList, err)
Expand Down Expand Up @@ -436,7 +437,7 @@ func sweepTestProvisioningKey(client *testClient) error {
sweeperLogger.Warn(fmt.Sprintf("Found %d resources to sweep", len(provisioningKey)))
for _, b := range provisioningKey {
// Check if the resource name has the required prefix before deleting it
if strings.HasPrefix(b.Name, testResourcePrefix) {
if strings.HasPrefix(b.Name, testResourcePrefix) || strings.HasPrefix(b.Name, updateResourcePrefix) {
// Assuming 'AssociationType' is a field in the provisioningKey object
if _, err := client.sdkClient.provisioningkey.Delete(b.AssociationType, b.ID); err != nil {
errorList = append(errorList, err)
Expand Down Expand Up @@ -464,7 +465,7 @@ func sweepTestSegmentGroup(client *testClient) error {
sweeperLogger.Warn(fmt.Sprintf("Found %d resources to sweep", len(group)))
for _, b := range group {
// Check if the resource name has the required prefix before deleting it
if strings.HasPrefix(b.Name, testResourcePrefix) {
if strings.HasPrefix(b.Name, testResourcePrefix) || strings.HasPrefix(b.Name, updateResourcePrefix) {
if _, err := client.sdkClient.segmentgroup.Delete(b.ID); err != nil {
errorList = append(errorList, err)
continue
Expand All @@ -491,7 +492,7 @@ func sweepTestServerGroup(client *testClient) error {
sweeperLogger.Warn(fmt.Sprintf("Found %d resources to sweep", len(group)))
for _, b := range group {
// Check if the resource name has the required prefix before deleting it
if strings.HasPrefix(b.Name, testResourcePrefix) {
if strings.HasPrefix(b.Name, testResourcePrefix) || strings.HasPrefix(b.Name, updateResourcePrefix) {
if _, err := client.sdkClient.servergroup.Delete(b.ID); err != nil {
errorList = append(errorList, err)
continue
Expand All @@ -518,7 +519,7 @@ func sweepTestServiceEdgeGroup(client *testClient) error {
sweeperLogger.Warn(fmt.Sprintf("Found %d resources to sweep", len(group)))
for _, b := range group {
// Check if the resource name has the required prefix before deleting it
if strings.HasPrefix(b.Name, testResourcePrefix) {
if strings.HasPrefix(b.Name, testResourcePrefix) || strings.HasPrefix(b.Name, updateResourcePrefix) {
if _, err := client.sdkClient.serviceedgegroup.Delete(b.ID); err != nil {
errorList = append(errorList, err)
continue
Expand All @@ -545,7 +546,7 @@ func sweepTestCBIBanner(client *testClient) error {
sweeperLogger.Warn(fmt.Sprintf("Found %d resources to sweep", len(group)))
for _, b := range group {
// Check if the resource name has the required prefix before deleting it
if strings.HasPrefix(b.Name, testResourcePrefix) {
if strings.HasPrefix(b.Name, testResourcePrefix) || strings.HasPrefix(b.Name, updateResourcePrefix) {
if _, err := client.sdkClient.cbibannercontroller.Delete(b.ID); err != nil {
errorList = append(errorList, err)
continue
Expand All @@ -572,7 +573,7 @@ func sweepTestCBIExternalProfile(client *testClient) error {
sweeperLogger.Warn(fmt.Sprintf("Found %d resources to sweep", len(group)))
for _, b := range group {
// Check if the resource name has the required prefix before deleting it
if strings.HasPrefix(b.Name, testResourcePrefix) {
if strings.HasPrefix(b.Name, testResourcePrefix) || strings.HasPrefix(b.Name, updateResourcePrefix) {
if _, err := client.sdkClient.cbiprofilecontroller.Delete(b.ID); err != nil {
errorList = append(errorList, err)
continue
Expand All @@ -599,7 +600,7 @@ func sweepTestCBICertificate(client *testClient) error {
sweeperLogger.Warn(fmt.Sprintf("Found %d resources to sweep", len(group)))
for _, b := range group {
// Check if the resource name has the required prefix before deleting it
if strings.HasPrefix(b.Name, testResourcePrefix) {
if strings.HasPrefix(b.Name, testResourcePrefix) || strings.HasPrefix(b.Name, updateResourcePrefix) {
if _, err := client.sdkClient.cbicertificatecontroller.Delete(b.ID); err != nil {
errorList = append(errorList, err)
continue
Expand All @@ -626,7 +627,7 @@ func sweepTestBaCertificate(client *testClient) error {
sweeperLogger.Warn(fmt.Sprintf("Found %d resources to sweep", len(group)))
for _, b := range group {
// Check if the resource name has the required prefix before deleting it
if strings.HasPrefix(b.Name, testResourcePrefix) {
if strings.HasPrefix(b.Name, testResourcePrefix) || strings.HasPrefix(b.Name, updateResourcePrefix) {
if _, err := client.sdkClient.bacertificate.Delete(b.ID); err != nil {
errorList = append(errorList, err)
continue
Expand Down
10 changes: 5 additions & 5 deletions zpa/resource_zpa_app_connector_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func TestAccResourceAppConnectorGroupBasic(t *testing.T) {
var groups appconnectorgroup.AppConnectorGroup
resourceTypeAndName, _, generatedName := method.GenerateRandomSourcesTypeAndName(resourcetype.ZPAAppConnectorGroup)

initialName := "tests-" + generatedName
updatedName := "updated-" + generatedName
initialName := "tf-acc-test-" + generatedName
updatedName := "tf-updated-" + generatedName

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -30,7 +30,7 @@ func TestAccResourceAppConnectorGroupBasic(t *testing.T) {
Config: testAccCheckAppConnectorGroupConfigure(resourceTypeAndName, initialName, variable.AppConnectorDescription, variable.AppConnectorEnabled),
Check: resource.ComposeTestCheckFunc(
testAccCheckAppConnectorGroupExists(resourceTypeAndName, &groups),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", "tf-acc-test-"+initialName),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", initialName),
resource.TestCheckResourceAttr(resourceTypeAndName, "description", variable.AppConnectorDescription),
resource.TestCheckResourceAttr(resourceTypeAndName, "enabled", strconv.FormatBool(variable.AppConnectorEnabled)),
resource.TestCheckResourceAttr(resourceTypeAndName, "tcp_quick_ack_app", strconv.FormatBool(variable.TCPQuickAckApp)),
Expand All @@ -45,7 +45,7 @@ func TestAccResourceAppConnectorGroupBasic(t *testing.T) {
Config: testAccCheckAppConnectorGroupConfigure(resourceTypeAndName, updatedName, variable.AppConnectorDescriptionUpdate, variable.AppConnectorEnabledUpdate),
Check: resource.ComposeTestCheckFunc(
testAccCheckAppConnectorGroupExists(resourceTypeAndName, &groups),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", "tf-acc-test-"+updatedName),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", updatedName),
resource.TestCheckResourceAttr(resourceTypeAndName, "description", variable.AppConnectorDescriptionUpdate),
resource.TestCheckResourceAttr(resourceTypeAndName, "enabled", strconv.FormatBool(variable.AppConnectorEnabledUpdate)),
resource.TestCheckResourceAttr(resourceTypeAndName, "tcp_quick_ack_app", strconv.FormatBool(variable.TCPQuickAckAppUpdate)),
Expand Down Expand Up @@ -112,7 +112,7 @@ func testAccCheckAppConnectorGroupConfigure(resourceTypeAndName, generatedName,

return fmt.Sprintf(`
resource "%s" "%s" {
name = "tf-acc-test-%s"
name = "%s"
description = "%s"
enabled = "%s"
country_code = "US"
Expand Down
8 changes: 4 additions & 4 deletions zpa/resource_zpa_app_server_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestAccResourceApplicationServerBasic(t *testing.T) {
resourceTypeAndName, _, generatedName := method.GenerateRandomSourcesTypeAndName(resourcetype.ZPAApplicationServer)

initialName := "tf-acc-test-" + generatedName
updatedName := "updated-" + generatedName
updatedName := "tf-updated-" + generatedName

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -30,7 +30,7 @@ func TestAccResourceApplicationServerBasic(t *testing.T) {
Config: testAccCheckApplicationServerConfigure(resourceTypeAndName, initialName, variable.AppServerDescription, variable.AppServerAddress, variable.AppServerEnabled),
Check: resource.ComposeTestCheckFunc(
testAccCheckApplicationServerExists(resourceTypeAndName, &servers),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", "tf-acc-test-"+initialName),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", initialName),
resource.TestCheckResourceAttr(resourceTypeAndName, "description", variable.AppServerDescription),
resource.TestCheckResourceAttr(resourceTypeAndName, "address", variable.AppServerAddress),
resource.TestCheckResourceAttr(resourceTypeAndName, "enabled", strconv.FormatBool(variable.AppServerEnabled)),
Expand All @@ -42,7 +42,7 @@ func TestAccResourceApplicationServerBasic(t *testing.T) {
Config: testAccCheckApplicationServerConfigure(resourceTypeAndName, updatedName, variable.AppServerDescription, variable.AppServerAddress, variable.AppServerEnabled),
Check: resource.ComposeTestCheckFunc(
testAccCheckApplicationServerExists(resourceTypeAndName, &servers),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", "tf-acc-test-"+updatedName),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", updatedName),
resource.TestCheckResourceAttr(resourceTypeAndName, "description", variable.AppServerDescription),
resource.TestCheckResourceAttr(resourceTypeAndName, "address", variable.AppServerAddress),
resource.TestCheckResourceAttr(resourceTypeAndName, "enabled", strconv.FormatBool(variable.AppServerEnabled)),
Expand Down Expand Up @@ -105,7 +105,7 @@ func testAccCheckApplicationServerConfigure(resourceTypeAndName, generatedName,
resourceName := strings.Split(resourceTypeAndName, ".")[1] // Extract the resource name
return fmt.Sprintf(`
resource "%s" "%s" {
name = "tf-acc-test-%s"
name = "%s"
description = "%s"
address = "%s"
enabled = "%s"
Expand Down
8 changes: 4 additions & 4 deletions zpa/resource_zpa_cloud_browser_isolation_banner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestAccResourceCBIBannersBasic(t *testing.T) {
resourceTypeAndName, _, generatedName := method.GenerateRandomSourcesTypeAndName(resourcetype.ZPACBIBannerController)

initialName := "tf-acc-test-" + generatedName
updatedName := "updated-" + generatedName
updatedName := "tf-updated-" + generatedName

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -30,7 +30,7 @@ func TestAccResourceCBIBannersBasic(t *testing.T) {
Config: testAccCheckCBIBannerConfigure(resourceTypeAndName, initialName, variable.PrimaryColor, variable.TextColor, variable.NotificationTitle, variable.NotificationText, variable.Banner, variable.Persist, variable.Logo),
Check: resource.ComposeTestCheckFunc(
testAccCheckCBIBannerExists(resourceTypeAndName, &cbiBanner),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", "tf-acc-test-"+initialName),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", initialName),
resource.TestCheckResourceAttr(resourceTypeAndName, "primary_color", variable.PrimaryColor),
resource.TestCheckResourceAttr(resourceTypeAndName, "text_color", variable.TextColor),
resource.TestCheckResourceAttr(resourceTypeAndName, "notification_title", variable.NotificationTitle),
Expand All @@ -46,7 +46,7 @@ func TestAccResourceCBIBannersBasic(t *testing.T) {
Config: testAccCheckCBIBannerConfigure(resourceTypeAndName, updatedName, variable.PrimaryColor, variable.TextColor, variable.NotificationTitle, variable.NotificationText, variable.Banner, variable.Persist, variable.Logo),
Check: resource.ComposeTestCheckFunc(
testAccCheckCBIBannerExists(resourceTypeAndName, &cbiBanner),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", "tf-acc-test-"+updatedName),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", updatedName),
resource.TestCheckResourceAttr(resourceTypeAndName, "primary_color", variable.PrimaryColor),
resource.TestCheckResourceAttr(resourceTypeAndName, "text_color", variable.TextColor),
resource.TestCheckResourceAttr(resourceTypeAndName, "notification_title", variable.NotificationTitle),
Expand Down Expand Up @@ -108,7 +108,7 @@ func testAccCheckCBIBannerConfigure(resourceTypeAndName, generatedName, primaryC

return fmt.Sprintf(`
resource "%s" "%s" {
name = "tf-acc-test-%s"
name = "%s"
primary_color = "%s"
text_color = "%s"
notification_title = "%s"
Expand Down
Loading

0 comments on commit a67ae41

Please sign in to comment.