Skip to content

Commit

Permalink
feat: Improved existing acceptance tests (#301)
Browse files Browse the repository at this point in the history
* feat: Improved existing acceptance tests

* feat: Improved integration tests
  • Loading branch information
willguibr authored Dec 15, 2023
1 parent 16e346d commit 63c1675
Show file tree
Hide file tree
Showing 33 changed files with 524 additions and 253 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/hashicorp/go-hclog v1.5.0
github.com/hashicorp/terraform-plugin-sdk v1.17.2
github.com/hashicorp/terraform-plugin-sdk/v2 v2.30.0
github.com/zscaler/zscaler-sdk-go/v2 v2.2.1
github.com/zscaler/zscaler-sdk-go/v2 v2.3.0
)

require (
Expand All @@ -22,7 +22,7 @@ require (
github.com/fatih/color v1.13.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/uuid v1.4.0 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hf
github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Expand All @@ -186,8 +186,8 @@ github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320/go.mod h1:EiZBM
github.com/hashicorp/go-getter v1.5.3/go.mod h1:BrrV/1clo8cCYu6mxvboYg+KutTiFnXjMEgDD8+i7ZI=
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-hclog v1.6.1 h1:pa92nu9bPoAqI7p+uPDCIWGAibUdlCi6TYWJEQQkLf8=
github.com/hashicorp/go-hclog v1.6.1/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
github.com/hashicorp/go-hclog v1.5.0 h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+13c=
github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
Expand Down Expand Up @@ -367,8 +367,8 @@ github.com/zclconf/go-cty v1.14.1 h1:t9fyA35fwjjUMcmL5hLER+e/rEPqrbCK1/OSE4SI9KA
github.com/zclconf/go-cty v1.14.1/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE=
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8=
github.com/zclconf/go-cty-yaml v1.0.2/go.mod h1:IP3Ylp0wQpYm50IHK8OZWKMu6sPJIUgKa8XhiVHura0=
github.com/zscaler/zscaler-sdk-go/v2 v2.2.1 h1:p4hRSyUGKSbz+iiRoAmBqIPTfWhKHWe1JTkAoP9HQEc=
github.com/zscaler/zscaler-sdk-go/v2 v2.2.1/go.mod h1:ZuSr5SoINzMxCVQPV1lh5xBEwsQLDmpEznEV9ey+gHg=
github.com/zscaler/zscaler-sdk-go/v2 v2.3.0 h1:9VbzxjUs/kTtv1HaGkJ5s1ZKSTtYKQDCJ7SGr20BC6E=
github.com/zscaler/zscaler-sdk-go/v2 v2.3.0/go.mod h1:Zv45PZtJr7+ddSCDleQ2NWKbYKi3rHMetQ4cPZAXJl0=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
Expand Down
15 changes: 10 additions & 5 deletions zia/common/testing/variable/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ const (
URLFilteringRuleResourceName = "testAcc_url_filtering_rule"
URLFilteringRuleDescription = "testAcc_url_filtering_rule"
URLFilteringRuleAction = "ALLOW"
URLFilteringRuleActionUpdate = "BLOCK"
URLFilteringRuleState = "ENABLED"
URLFilteringRuleStateUpdate = "DISABLED"
)

// Custom URL Categories resource/datasource
Expand All @@ -19,6 +21,7 @@ const (
FWRuleResourceDescription = "this is an acceptance test"
FWRuleResourceAction = "ALLOW"
FWRuleResourceState = "ENABLED"
FWRuleResourceStateUpdate = "DISABLED"
FWRuleEnableLogging = false
)

Expand Down Expand Up @@ -62,7 +65,7 @@ const (
FowardingControlState = "ENABLED"
)

// Forwarding Control ZPA Gateway
// Forwarding Control Rule
const (
FowardingControlUpdateDescription = "this is an updated acceptance test"
FowardingControlUpdateState = "ENABLED"
Expand All @@ -89,7 +92,9 @@ const (
LocSurrogateIP = true
LocXFF = true
LocOFW = true
LocOFWUpdate = false
LocIPS = true
LocIPSUpdate = false
)

// Traffic Forwarding GRE resource/datasource
Expand Down Expand Up @@ -129,15 +134,15 @@ const (

// Admin Users
const (
AdminUserLoginName = "testAcc@bd-hashicorp.com"
AdminUserName = "Test Acc"
AdminUserEmail = "testAcc@bd-hashicorp.com"
AdminUserLoginName = "tf-acc-test-@bd-hashicorp.com"
AdminUserName = "tf-acc-test-admin"
AdminUserEmail = "tf-acc-test-@bd-hashicorp.com"
AdminUserPassword = "Password@123!"
)

// User Management
const (
UserName = "testAcc TF User"
UserName = "tf-acc-test-user"
)

// Rule Labels
Expand Down
3 changes: 3 additions & 0 deletions zia/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/dlp/dlp_engines"
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/dlp/dlp_exact_data_match"
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/dlp/dlp_icap_servers"
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/dlp/dlp_idm_profile_lite"
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/dlp/dlp_idm_profiles"
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/dlp/dlp_incident_receiver_servers"
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/dlp/dlp_notification_templates"
Expand Down Expand Up @@ -87,6 +88,7 @@ type Client struct {
dlpdictionaries *dlpdictionaries.Service
dlp_engines *dlp_engines.Service
dlp_idm_profiles *dlp_idm_profiles.Service
dlp_idm_profile_lite *dlp_idm_profile_lite.Service
dlp_exact_data_match *dlp_exact_data_match.Service
dlp_icap_servers *dlp_icap_servers.Service
dlp_incident_receiver_servers *dlp_incident_receiver_servers.Service
Expand Down Expand Up @@ -148,6 +150,7 @@ func (c *Config) Client() (*Client, error) {
dlpdictionaries: dlpdictionaries.New(cli),
dlp_engines: dlp_engines.New(cli),
dlp_idm_profiles: dlp_idm_profiles.New(cli),
dlp_idm_profile_lite: dlp_idm_profile_lite.New(cli),
dlp_exact_data_match: dlp_exact_data_match.New(cli),
dlp_icap_servers: dlp_icap_servers.New(cli),
dlp_incident_receiver_servers: dlp_incident_receiver_servers.New(cli),
Expand Down
6 changes: 0 additions & 6 deletions zia/data_source_zia_activation_status_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package zia

/*
import (
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
func TestAccDataSourceActivationStatus_Basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down
4 changes: 2 additions & 2 deletions zia/data_source_zia_dlp_edm_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ func dataSourceDLPEDMSchema() *schema.Resource {
Computed: true,
Description: "The revision number of the CSV file upload to the Index Tool. This attribute is required by PUT requests.",
},
"filename": {
"file_name": {
Type: schema.TypeString,
Computed: true,
Description: "The generated filename, excluding the extention.",
Description: "The generated filename, excluding the extention",
},
"original_file_name": {
Type: schema.TypeString,
Expand Down
53 changes: 53 additions & 0 deletions zia/data_source_zia_dlp_edm_schema_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package zia

import (
"fmt"
"testing"

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

var edmProjectNames = []string{
"BD_EDM_TEMPLATE01", "BD_EDM_TEMPLATE02",
}

func TestAccDataSourceDLPEDMSchema_Basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckDataSourceDLPEDMSchema_basic(),
Check: resource.ComposeTestCheckFunc(
generateDLPEDMSchemaChecks()...,
),
},
},
})
}

func generateDLPEDMSchemaChecks() []resource.TestCheckFunc {
var checks []resource.TestCheckFunc
for _, name := range edmProjectNames {
resourceName := createValidResourceName(name)
checkName := fmt.Sprintf("data.zia_dlp_edm_schema.%s", resourceName)
checks = append(checks, resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(checkName, "id"),
resource.TestCheckResourceAttrSet(checkName, "project_name"),
))
}
return checks
}

func testAccCheckDataSourceDLPEDMSchema_basic() string {
var configs string
for _, name := range edmProjectNames {
resourceName := createValidResourceName(name)
configs += fmt.Sprintf(`
data "zia_dlp_edm_schema" "%s" {
project_name = "%s"
}
`, resourceName, name)
}
return configs
}
18 changes: 13 additions & 5 deletions zia/data_source_zia_dlp_idm_profiles_lite.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/dlp/dlp_idm_profiles"
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/dlp/dlp_idm_profile_lite"
)

func dataSourceDLPIDMProfileLite() *schema.Resource {
Expand Down Expand Up @@ -84,33 +84,41 @@ func dataSourceDLPIDMProfileLite() *schema.Resource {
},
},
},
"active_only": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Filter to include only active IDM profiles",
},
},
}
}

func dataSourceDLPIDMProfileLiteRead(d *schema.ResourceData, m interface{}) error {
zClient := m.(*Client)

var resp *dlp_idm_profiles.DLPIDMProfileLite
var resp *dlp_idm_profile_lite.DLPIDMProfileLite
activeOnly := d.Get("active_only").(bool) // Retrieve the active_only value

profileLiteID, ok := getIntFromResourceData(d, "profile_id")
if ok {
log.Printf("[INFO] Getting data for dlp idm profile id: %d\n", profileLiteID)
res, err := zClient.dlp_idm_profiles.GetDLPProfileLiteID(profileLiteID)
res, err := zClient.dlp_idm_profile_lite.GetDLPProfileLiteID(profileLiteID, activeOnly) // Use activeOnly here
if err != nil {
return err
}
resp = res
}

profileLiteName, _ := d.Get("template_name").(string)
if resp == nil && profileLiteName != "" {
log.Printf("[INFO] Getting data for dlp idm template name: %s\n", profileLiteName)
res, err := zClient.dlp_idm_profiles.GetDLPProfileLiteByName(profileLiteName)
res, err := zClient.dlp_idm_profile_lite.GetDLPProfileLiteByName(profileLiteName, activeOnly) // Use activeOnly here
if err != nil {
return err
}
resp = res
}

if resp != nil {
d.SetId(fmt.Sprintf("%d", resp.ProfileID))
_ = d.Set("profile_id", resp.ProfileID)
Expand Down
53 changes: 53 additions & 0 deletions zia/data_source_zia_dlp_idm_profiles_lite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package zia

import (
"fmt"
"testing"

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

var idmProfileLiteNames = []string{
"BD_IDM_TEMPLATE01",
}

func TestAccDataSourceDLPIDMProfileLite_Basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckDataSourceDLPIDMProfileLite_basic(),
Check: resource.ComposeTestCheckFunc(
generateDLPIDMProfileLiteChecks()...,
),
},
},
})
}

func generateDLPIDMProfileLiteChecks() []resource.TestCheckFunc {
var checks []resource.TestCheckFunc
for _, name := range idmProfileLiteNames {
resourceName := createValidResourceName(name)
checkName := fmt.Sprintf("data.zia_dlp_idm_profile_lite.%s", resourceName)
checks = append(checks, resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(checkName, "id"),
resource.TestCheckResourceAttrSet(checkName, "template_name"),
))
}
return checks
}

func testAccCheckDataSourceDLPIDMProfileLite_basic() string {
var configs string
for _, name := range idmProfileLiteNames {
resourceName := createValidResourceName(name)
configs += fmt.Sprintf(`
data "zia_dlp_idm_profile_lite" "%s" {
template_name = "%s"
}
`, resourceName, name)
}
return configs
}
53 changes: 53 additions & 0 deletions zia/data_source_zia_dlp_idm_profiles_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package zia

import (
"fmt"
"testing"

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

var idmProfileNames = []string{
"BD_IDM_TEMPLATE01",
}

func TestAccDataSourceDLPIDMProfiles_Basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckDataSourceDLPIDMProfiles_basic(),
Check: resource.ComposeTestCheckFunc(
generateDLPIDMProfilesChecks()...,
),
},
},
})
}

func generateDLPIDMProfilesChecks() []resource.TestCheckFunc {
var checks []resource.TestCheckFunc
for _, name := range idmProfileNames {
resourceName := createValidResourceName(name)
checkName := fmt.Sprintf("data.zia_dlp_idm_profiles.%s", resourceName)
checks = append(checks, resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(checkName, "id"),
resource.TestCheckResourceAttrSet(checkName, "profile_name"),
))
}
return checks
}

func testAccCheckDataSourceDLPIDMProfiles_basic() string {
var configs string
for _, name := range idmProfileNames {
resourceName := createValidResourceName(name)
configs += fmt.Sprintf(`
data "zia_dlp_idm_profiles" "%s" {
profile_name = "%s"
}
`, resourceName, name)
}
return configs
}
Loading

0 comments on commit 63c1675

Please sign in to comment.