Skip to content

Commit

Permalink
feat: Enhaced acceptance test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
willguibr committed Oct 25, 2023
1 parent e055465 commit 230312e
Show file tree
Hide file tree
Showing 33 changed files with 553 additions and 171 deletions.
1 change: 1 addition & 0 deletions zpa/common/resourcetype/resource_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ const (
ZPALSSController = "zpa_lss_config_controller"
ZPAInspectionCustomControl = "zpa_inspection_custom_controls"
ZPAInspectionProfile = "zpa_inspection_profile"
ZPAMicrotenant = "zpa_microtenant_controller"
)
34 changes: 33 additions & 1 deletion zpa/common/testing/variable/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ const (
UseInDrMode = false
)

// App Connector Group Update
const (
AppConnectorResourceNameUpdate = "testAcc_app_connector_group"
AppConnectorDescriptionUpdate = "this is update app connector group test"
AppConnectorEnabledUpdate = true
AppConnectorOverrideProfileUpdate = true
TCPQuickAckAppUpdate = true
TCPQuickAckAssistantUpdate = true
TCPQuickAckReadAssistantUpdate = true
UseInDrModeUpdate = false
)

// Service Edge Group
const (
ServiceEdgeResourceName = "testAcc_service_edge_group"
Expand Down Expand Up @@ -51,16 +63,28 @@ const (
const (
ServerGroupResourceName = "testAcc_server_group"
ServerGroupDescription = "testAcc_server_group"
ServerGroupEnabled = true
ServerGroupEnabled = false
ServerGroupDynamicDiscovery = true
)

// Segment Group Update
const (
ServerGroupDescriptionUpdate = "this update the server group test"
ServerGroupEnabledUpdate = true
)

// Segment Group
const (
SegmentGroupDescription = "testAcc_segment_group"
SegmentGroupEnabled = true
)

// Segment Group Update
const (
SegmentGroupDescriptionUpdate = "testAcc_segment_group"
SegmentGroupEnabledUpdate = true
)

// Application Segment
const (
AppSegmentResourceName = "testAcc_app_segment"
Expand Down Expand Up @@ -121,3 +145,11 @@ const (
const (
InspectionProfileDescription = "testAcc_access_rule"
)

// Microtenant
const (
MicrotenantName = "testAcc_microtenant_A"
MicrotenantDescription = "testAcc_microtenant_A"
MicrotenantEnabled = true
MicrotenantCriteriaAttribute = "AuthDomain"
)
11 changes: 9 additions & 2 deletions zpa/data_source_zpa_access_policy_client_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ func TestAccDataSourceAccessPolicyClientTypes_Basic(t *testing.T) {
{
Config: (testAccCheckDataSourceAccessPolicyClientTypes_basic),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckNoResourceAttr(
"data.zpa_access_policy_client_types.this", ""),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_client_types.this", "zpn_client_type_exporter"),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_client_types.this", "zpn_client_type_exporter_noauth"),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_client_types.this", "zpn_client_type_browser_isolation"),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_client_types.this", "zpn_client_type_machine_tunnel"),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_client_types.this", "zpn_client_type_ip_anchoring"),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_client_types.this", "zpn_client_type_edge_connector"),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_client_types.this", "zpn_client_type_zapp"),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_client_types.this", "zpn_client_type_slogger"),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_client_types.this", "zpn_client_type_branch_connector"),
),
},
},
Expand Down
9 changes: 6 additions & 3 deletions zpa/data_source_zpa_access_policy_platform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ func TestAccDataSourceAccessPolicyPlatforms_Basic(t *testing.T) {
ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Config: (testAccCheckDataSourceAccessPolicyPlatforms_basic),
Config: testAccCheckDataSourceAccessPolicyPlatforms_basic,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckNoResourceAttr(
"data.zpa_access_policy_platforms.this", ""),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_platforms.this", "linux"),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_platforms.this", "android"),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_platforms.this", "windows"),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_platforms.this", "ios"),
resource.TestCheckResourceAttrSet("data.zpa_access_policy_platforms.this", "mac"),
),
},
},
Expand Down
3 changes: 0 additions & 3 deletions zpa/data_source_zpa_application_segment_inspection_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package zpa

/*
import (
"strconv"
"testing"
Expand Down Expand Up @@ -41,9 +40,7 @@ func TestAccDataSourceApplicationSegmentInspection_Basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceTypeAndName, "common_apps_dto.#", "1"),
resource.TestCheckResourceAttr(dataSourceTypeAndName, "tcp_port_ranges.#", "2"),
),
ExpectNonEmptyPlan: true,
},
},
})
}
*/
8 changes: 8 additions & 0 deletions zpa/data_source_zpa_application_segment_pra.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ func dataSourceApplicationSegmentPRA() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"microtenant_id": {
Type: schema.TypeString,
Computed: true,
},
"microtenant_name": {
Type: schema.TypeString,
Computed: true,
},
"portal": {
Type: schema.TypeBool,
Computed: true,
Expand Down
2 changes: 0 additions & 2 deletions zpa/data_source_zpa_application_segment_pra_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package zpa

/*
import (
"strconv"
"testing"
Expand Down Expand Up @@ -43,4 +42,3 @@ func TestAccDataSourceApplicationSegmentPRA_Basic(t *testing.T) {
},
})
}
*/
53 changes: 28 additions & 25 deletions zpa/data_source_zpa_enrollement_cert_test.go
Original file line number Diff line number Diff line change
@@ -1,50 +1,53 @@
package zpa

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

var enrollementCertNames = []string{
"Root", "Client", "Connector", "Service Edge",
}

func TestAccDataSourceEnrollmentCert_Basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckDataSourceEnrollmentCertConfig_basic,
Config: testAccCheckDataSourceEnrollmentCert_basic(),
Check: resource.ComposeTestCheckFunc(
testAccDataSourceEnrollmentCertCheck("data.zpa_enrollment_cert.root"),
testAccDataSourceEnrollmentCertCheck("data.zpa_enrollment_cert.client"),
testAccDataSourceEnrollmentCertCheck("data.zpa_enrollment_cert.connector"),
testAccDataSourceEnrollmentCertCheck("data.zpa_enrollment_cert.service_edge"),
generateEnrollmentCertChecks()...,
),
},
},
})
}

func testAccDataSourceEnrollmentCertCheck(name string) resource.TestCheckFunc {
return resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(name, "id"),
resource.TestCheckResourceAttrSet(name, "name"),
)
}

var testAccCheckDataSourceEnrollmentCertConfig_basic = `
data "zpa_enrollment_cert" "root" {
name = "Root"
func generateEnrollmentCertChecks() []resource.TestCheckFunc {
var checks []resource.TestCheckFunc
for _, name := range enrollementCertNames {
resourceName := createValidResourceName(name)
checkName := fmt.Sprintf("data.zpa_enrollment_cert.%s", resourceName)
checks = append(checks, resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(checkName, "id"),
resource.TestCheckResourceAttrSet(checkName, "name"),
))
}
return checks
}

data "zpa_enrollment_cert" "client" {
name = "Client"
func testAccCheckDataSourceEnrollmentCert_basic() string {
var configs string
for _, name := range enrollementCertNames {
resourceName := createValidResourceName(name)
configs += fmt.Sprintf(`
data "zpa_enrollment_cert" "%s" {
name = "%s"
}
data "zpa_enrollment_cert" "connector" {
name = "Connector"
}
data "zpa_enrollment_cert" "service_edge" {
name = "Service Edge"
`, resourceName, name)
}
return configs
}
`
72 changes: 28 additions & 44 deletions zpa/data_source_zpa_lss_config_log_types_formats_test.go
Original file line number Diff line number Diff line change
@@ -1,69 +1,53 @@
package zpa

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

var lssConfigLogTypeFormatsNames = []string{
"zpn_ast_comprehensive_stats", "zpn_auth_log", "zpn_pbroker_comprehensive_stats", "zpn_ast_auth_log", "zpn_audit_log",
"zpn_trans_log", "zpn_http_trans_log", "zpn_waf_http_exchanges_log",
}

func TestAccDataSourceLSSLogTypeFormats_Basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckDataSourceLSSLogTypeFormats_basic,
Config: testAccCheckDataSourceLSSLogTypeFormats_basic(),
Check: resource.ComposeTestCheckFunc(
testAccDataSourceLSSLogTypeFormatsCheck("data.zpa_lss_config_log_type_formats.zpn_ast_comprehensive_stats"),
testAccDataSourceLSSLogTypeFormatsCheck("data.zpa_lss_config_log_type_formats.zpn_auth_log"),
testAccDataSourceLSSLogTypeFormatsCheck("data.zpa_lss_config_log_type_formats.zpn_pbroker_comprehensive_stats"),
testAccDataSourceLSSLogTypeFormatsCheck("data.zpa_lss_config_log_type_formats.zpn_ast_auth_log"),
testAccDataSourceLSSLogTypeFormatsCheck("data.zpa_lss_config_log_type_formats.zpn_audit_log"),
testAccDataSourceLSSLogTypeFormatsCheck("data.zpa_lss_config_log_type_formats.zpn_trans_log"),
testAccDataSourceLSSLogTypeFormatsCheck("data.zpa_lss_config_log_type_formats.zpn_http_trans_log"),
testAccDataSourceLSSLogTypeFormatsCheck("data.zpa_lss_config_log_type_formats.zpn_waf_http_exchanges_log"),
generateLSSConfigLogTypeFormatChecks()...,
),
},
},
})
}

func testAccDataSourceLSSLogTypeFormatsCheck(log_type string) resource.TestCheckFunc {
return resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(log_type, "log_type"),
)
}

var testAccCheckDataSourceLSSLogTypeFormats_basic = `
data "zpa_lss_config_log_type_formats" "zpn_ast_comprehensive_stats" {
log_type = "zpn_ast_comprehensive_stats"
}
data "zpa_lss_config_log_type_formats" "zpn_auth_log" {
log_type = "zpn_auth_log"
}
data "zpa_lss_config_log_type_formats" "zpn_pbroker_comprehensive_stats" {
log_type = "zpn_pbroker_comprehensive_stats"
func generateLSSConfigLogTypeFormatChecks() []resource.TestCheckFunc {
var checks []resource.TestCheckFunc
for _, log_type := range lssConfigLogTypeFormatsNames {
resourceName := createValidResourceName(log_type)
checkName := fmt.Sprintf("data.zpa_lss_config_log_type_formats.%s", resourceName)
checks = append(checks, resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(checkName, "log_type"),
))
}
return checks
}

data "zpa_lss_config_log_type_formats" "zpn_ast_auth_log" {
log_type = "zpn_ast_auth_log"
func testAccCheckDataSourceLSSLogTypeFormats_basic() string {
var configs string
for _, log_type := range lssConfigLogTypeFormatsNames {
resourceName := createValidResourceName(log_type)
configs += fmt.Sprintf(`
data "zpa_lss_config_log_type_formats" "%s" {
log_type = "%s"
}
data "zpa_lss_config_log_type_formats" "zpn_audit_log" {
log_type = "zpn_audit_log"
}
data "zpa_lss_config_log_type_formats" "zpn_trans_log" {
log_type = "zpn_trans_log"
}
data "zpa_lss_config_log_type_formats" "zpn_http_trans_log" {
log_type = "zpn_http_trans_log"
}
data "zpa_lss_config_log_type_formats" "zpn_waf_http_exchanges_log" {
log_type = "zpn_waf_http_exchanges_log"
`, resourceName, log_type)
}
return configs
}
`
6 changes: 0 additions & 6 deletions zpa/data_source_zpa_machine_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package zpa

import (
"fmt"
"strings"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
Expand Down Expand Up @@ -53,8 +52,3 @@ data "zpa_machine_group" "%s" {
}
return configs
}

// createValidResourceName converts the given name to a valid Terraform resource name
func createValidResourceName(name string) string {
return strings.ReplaceAll(name, " ", "_")
}
2 changes: 1 addition & 1 deletion zpa/data_source_zpa_microtenant_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func dataSourceMicrotenantController() *schema.Resource {
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Optional: true,
},
"name": {
Type: schema.TypeString,
Expand Down
35 changes: 35 additions & 0 deletions zpa/data_source_zpa_microtenant_controller_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package zpa

/*
import (
"strconv"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/zscaler/terraform-provider-zpa/v3/zpa/common/resourcetype"
"github.com/zscaler/terraform-provider-zpa/v3/zpa/common/testing/method"
"github.com/zscaler/terraform-provider-zpa/v3/zpa/common/testing/variable"
)
func TestAccDataSourceMicrotenant_Basic(t *testing.T) {
resourceTypeAndName, dataSourceTypeAndName, generatedName := method.GenerateRandomSourcesTypeAndName(resourcetype.ZPAMicrotenant)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckMicroTenantDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckMicrotenantConfigure(resourceTypeAndName, generatedName, variable.MicrotenantDescription, variable.MicrotenantCriteriaAttribute, variable.MicrotenantEnabled),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceTypeAndName, "id", resourceTypeAndName, "id"),
resource.TestCheckResourceAttrPair(dataSourceTypeAndName, "name", resourceTypeAndName, "name"),
resource.TestCheckResourceAttrPair(dataSourceTypeAndName, "description", resourceTypeAndName, "description"),
resource.TestCheckResourceAttr(resourceTypeAndName, "enabled", strconv.FormatBool(variable.MicrotenantEnabled)),
resource.TestCheckResourceAttr(resourceTypeAndName, "criteria_attribute", variable.MicrotenantCriteriaAttribute),
),
},
},
})
}
*/
Loading

0 comments on commit 230312e

Please sign in to comment.