Skip to content

Commit

Permalink
Added: New Optimized Acceptance Tests (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
willguibr authored Apr 19, 2022
1 parent 0cd8c6a commit b8454fd
Show file tree
Hide file tree
Showing 14 changed files with 235 additions and 94 deletions.
8 changes: 2 additions & 6 deletions zia/common/testing/variable/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,8 @@ const (

// Traffic Forwarding VPN Credentials resource/datasource
const (
VPNCredentialComments = "this is an acceptance test"
VPNCredentialTypeUFQDN = "UFQDN"
VPNCredentialFQDN = "test@securitygeek.io"
VPNCredentialPreSharedKey = "Password@123!"
VPNCredentialTypeIP = "IP"
VPNCredentialIPAddress = "118.189.211.221"
VPNCredentialTypeUFQDN = "UFQDN"
VPNCredentialTypeIP = "IP"
)

// Traffic Forwarding Location Management
Expand Down
12 changes: 10 additions & 2 deletions zia/data_source_zia_location_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strconv"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/willguibr/terraform-provider-zia/zia/common/resourcetype"
"github.com/willguibr/terraform-provider-zia/zia/common/testing/method"
Expand All @@ -13,13 +14,20 @@ import (
func TestAccDataSourceLocationManagement_Basic(t *testing.T) {
resourceTypeAndName, dataSourceTypeAndName, generatedName := method.GenerateRandomSourcesTypeAndName(resourcetype.TrafficFilteringLocManagement)

rIP, _ := acctest.RandIpAddress("121.234.54.0/25")
staticIPTypeAndName, _, staticIPGeneratedName := method.GenerateRandomSourcesTypeAndName(resourcetype.TrafficFilteringStaticIP)
staticIPResourceHCL := testAccCheckTrafficForwardingStaticIPConfigure(staticIPTypeAndName, staticIPGeneratedName, rIP, variable.StaticRoutableIP, variable.StaticGeoOverride)

vpnCredentialTypeAndName, _, vpnCredentialGeneratedName := method.GenerateRandomSourcesTypeAndName(resourcetype.TrafficFilteringVPNCredentials)
vpnCredentialResourceHCL := testAccCheckTrafficForwardingVPNCredentialsIPConfigure(vpnCredentialTypeAndName, vpnCredentialGeneratedName, variable.VPNCredentialTypeIP, "", "")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckLocationManagementDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckLocationManagementConfigure(resourceTypeAndName, generatedName, variable.LocName, variable.LocDesc),
Config: testAccCheckLocationManagementConfigure(resourceTypeAndName, generatedName, staticIPResourceHCL, staticIPTypeAndName, vpnCredentialResourceHCL, vpnCredentialTypeAndName, variable.LocAuthRequired, variable.LocSurrogateIP, variable.LocXFF, variable.LocOFW, variable.LocIPS),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceTypeAndName, "id", resourceTypeAndName, "id"),
resource.TestCheckResourceAttrPair(dataSourceTypeAndName, "name", resourceTypeAndName, "name"),
Expand All @@ -35,7 +43,7 @@ func TestAccDataSourceLocationManagement_Basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceTypeAndName, "ofw_enabled", strconv.FormatBool(variable.LocOFW)),
resource.TestCheckResourceAttr(resourceTypeAndName, "ips_control", strconv.FormatBool(variable.LocIPS)),
resource.TestCheckResourceAttr(dataSourceTypeAndName, "ip_addresses.#", "1"),
resource.TestCheckResourceAttr(dataSourceTypeAndName, "vpn_credentials.#", "1"),
// resource.TestCheckResourceAttr(dataSourceTypeAndName, "vpn_credentials.#", "1"),
),
},
},
Expand Down
16 changes: 15 additions & 1 deletion zia/data_source_zia_traffic_forwarding_vpn_credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,41 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/willguibr/terraform-provider-zia/zia/common/resourcetype"
"github.com/willguibr/terraform-provider-zia/zia/common/testing/method"
"github.com/willguibr/terraform-provider-zia/zia/common/testing/variable"
)

func TestAccDataSourceTrafficForwardingVPNCredentials_Basic(t *testing.T) {
resourceTypeAndName, dataSourceTypeAndName, generatedName := method.GenerateRandomSourcesTypeAndName(resourcetype.TrafficFilteringVPNCredentials)
rEmail := acctest.RandomWithPrefix("tf-acc-test-")
rSharedKey := acctest.RandString(20)

rIP, _ := acctest.RandIpAddress("121.234.54.0/25")
staticIPTypeAndName, _, staticIPGeneratedName := method.GenerateRandomSourcesTypeAndName(resourcetype.TrafficFilteringStaticIP)
staticIPResourceHCL := testAccCheckTrafficForwardingStaticIPConfigure(staticIPTypeAndName, staticIPGeneratedName, rIP, variable.StaticRoutableIP, variable.StaticGeoOverride)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckTrafficForwardingVPNCredentialsDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckTrafficForwardingVPNCredentialsConfigure(resourceTypeAndName, generatedName, rEmail, rSharedKey),
Config: testAccCheckTrafficForwardingVPNCredentialsUFQDNConfigure(resourceTypeAndName, generatedName, rEmail, rSharedKey),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceTypeAndName, "id", resourceTypeAndName, "id"),
resource.TestCheckResourceAttrPair(dataSourceTypeAndName, "comments", resourceTypeAndName, "comments"),
resource.TestCheckResourceAttrPair(dataSourceTypeAndName, "type", resourceTypeAndName, "type"),
resource.TestCheckResourceAttrPair(dataSourceTypeAndName, "fqdn", resourceTypeAndName, "fqdn"),
),
},
{
Config: testAccCheckTrafficForwardingVPNCredentialsIPConfigure(resourceTypeAndName, generatedName, staticIPResourceHCL, staticIPTypeAndName, rSharedKey),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceTypeAndName, "id", resourceTypeAndName, "id"),
resource.TestCheckResourceAttrPair(dataSourceTypeAndName, "comments", resourceTypeAndName, "comments"),
resource.TestCheckResourceAttrPair(dataSourceTypeAndName, "type", resourceTypeAndName, "type"),
resource.TestCheckResourceAttrPair(dataSourceTypeAndName, "ip_address", resourceTypeAndName, "ip_address"),
),
},
},
})
}
8 changes: 4 additions & 4 deletions zia/resource_zia_dlp_dictionaries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestAccResourceDLPDictionariesBasic(t *testing.T) {
Config: testAccCheckDLPDictionariesConfigure(resourceTypeAndName, generatedName, variable.DLPDictionaryDescription),
Check: resource.ComposeTestCheckFunc(
testAccCheckDLPDictionariesExists(resourceTypeAndName, &dictionary),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", variable.DLPDictionaryResourceName),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", "tf-acc-test-"+generatedName),
resource.TestCheckResourceAttr(resourceTypeAndName, "description", variable.DLPDictionaryDescription),
resource.TestCheckResourceAttr(resourceTypeAndName, "phrases.#", "2"),
resource.TestCheckResourceAttr(resourceTypeAndName, "patterns.#", "2"),
Expand All @@ -39,7 +39,7 @@ func TestAccResourceDLPDictionariesBasic(t *testing.T) {
Config: testAccCheckDLPDictionariesConfigure(resourceTypeAndName, generatedName, variable.DLPDictionaryDescription),
Check: resource.ComposeTestCheckFunc(
testAccCheckDLPDictionariesExists(resourceTypeAndName, &dictionary),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", variable.DLPDictionaryResourceName),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", "tf-acc-test-"+generatedName),
resource.TestCheckResourceAttr(resourceTypeAndName, "description", variable.DLPDictionaryDescription),
resource.TestCheckResourceAttr(resourceTypeAndName, "phrases.#", "2"),
resource.TestCheckResourceAttr(resourceTypeAndName, "patterns.#", "2"),
Expand Down Expand Up @@ -108,7 +108,7 @@ func testAccCheckDLPDictionariesExists(resource string, dictionary *dlpdictionar
func testAccCheckDLPDictionariesConfigure(resourceTypeAndName, generatedName, description string) string {
return fmt.Sprintf(`
resource "%s" "%s" {
name = "%s"
name = "tf-acc-test-%s"
description = "%s"
phrases {
action = "PHRASE_COUNT_TYPE_ALL"
Expand Down Expand Up @@ -138,7 +138,7 @@ data "%s" "%s" {
// resource variables
resourcetype.DLPDictionaries,
generatedName,
variable.DLPDictionaryResourceName,
generatedName,
description,

// data source variables
Expand Down
7 changes: 4 additions & 3 deletions zia/resource_zia_dlp_web_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestAccResourceDlpWebRulesBasic(t *testing.T) {
Config: testAccCheckDlpWebRulesConfigure(resourceTypeAndName, generatedName, variable.DLPWebRuleDesc, variable.DLPRuleResourceAction, variable.DLPRuleResourceState),
Check: resource.ComposeTestCheckFunc(
testAccCheckDlpWebRulesExists(resourceTypeAndName, &rules),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", variable.FWRuleResourceName),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", "tf-acc-test-"+generatedName),
resource.TestCheckResourceAttr(resourceTypeAndName, "description", variable.DLPWebRuleDesc),
resource.TestCheckResourceAttr(resourceTypeAndName, "action", variable.DLPRuleResourceAction),
resource.TestCheckResourceAttr(resourceTypeAndName, "state", variable.DLPRuleResourceState),
Expand All @@ -45,6 +45,7 @@ func TestAccResourceDlpWebRulesBasic(t *testing.T) {
Config: testAccCheckDlpWebRulesConfigure(resourceTypeAndName, generatedName, variable.DLPWebRuleDesc, variable.DLPRuleResourceAction, variable.DLPRuleResourceState),
Check: resource.ComposeTestCheckFunc(
testAccCheckDlpWebRulesExists(resourceTypeAndName, &rules),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", "tf-acc-test-"+generatedName),
resource.TestCheckResourceAttr(resourceTypeAndName, "description", variable.DLPWebRuleDesc),
resource.TestCheckResourceAttr(resourceTypeAndName, "action", variable.DLPRuleResourceAction),
resource.TestCheckResourceAttr(resourceTypeAndName, "state", variable.DLPRuleResourceState),
Expand Down Expand Up @@ -120,7 +121,7 @@ func testAccCheckDlpWebRulesConfigure(resourceTypeAndName, generatedName, descri
return fmt.Sprintf(`
resource "%s" "%s" {
name = "%s"
name = "tf-acc-test-%s"
description = "%s"
action = "%s"
state = "%s"
Expand All @@ -144,7 +145,7 @@ data "%s" "%s" {
// resource variables
resourcetype.DLPWebRules,
generatedName,
variable.DLPWebRuleName,
generatedName,
description,
action,
state,
Expand Down
8 changes: 4 additions & 4 deletions zia/resource_zia_fw_filtering_ip_destination_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestAccResourceFWIPDestinationGroupsBasic(t *testing.T) {
Config: testAccCheckFWIPDestinationGroupsConfigure(resourceTypeAndName, generatedName, variable.FWDSTGroupDescription, variable.FWDSTGroupTypeDSTNFQDN),
Check: resource.ComposeTestCheckFunc(
testAccCheckFWIPDestinationGroupsExists(resourceTypeAndName, &groups),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", variable.FWDSTGroupName),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", "tf-acc-test-"+generatedName),
resource.TestCheckResourceAttr(resourceTypeAndName, "description", variable.FWDSTGroupDescription),
resource.TestCheckResourceAttr(resourceTypeAndName, "type", variable.FWDSTGroupTypeDSTNFQDN),
resource.TestCheckResourceAttr(resourceTypeAndName, "addresses.#", "3"),
Expand All @@ -39,7 +39,7 @@ func TestAccResourceFWIPDestinationGroupsBasic(t *testing.T) {
Config: testAccCheckFWIPDestinationGroupsConfigure(resourceTypeAndName, generatedName, variable.FWDSTGroupDescription, variable.FWDSTGroupTypeDSTNFQDN),
Check: resource.ComposeTestCheckFunc(
testAccCheckFWIPDestinationGroupsExists(resourceTypeAndName, &groups),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", variable.FWDSTGroupName),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", "tf-acc-test-"+generatedName),
resource.TestCheckResourceAttr(resourceTypeAndName, "description", variable.FWDSTGroupDescription),
resource.TestCheckResourceAttr(resourceTypeAndName, "type", variable.FWDSTGroupTypeDSTNFQDN),
resource.TestCheckResourceAttr(resourceTypeAndName, "addresses.#", "3"),
Expand Down Expand Up @@ -108,7 +108,7 @@ func testAccCheckFWIPDestinationGroupsExists(resource string, rule *ipdestinatio
func testAccCheckFWIPDestinationGroupsConfigure(resourceTypeAndName, generatedName, description, dst_type string) string {
return fmt.Sprintf(`
resource "%s" "%s" {
name = "%s"
name = "tf-acc-test-%s"
description = "%s"
type = "%s"
addresses = [ "test1.acme.com", "test2.acme.com", "test3.acme.com" ]
Expand All @@ -121,7 +121,7 @@ data "%s" "%s" {
// resource variables
resourcetype.FWFilteringDestinationGroup,
generatedName,
variable.FWDSTGroupName,
generatedName,
description,
dst_type,

Expand Down
8 changes: 4 additions & 4 deletions zia/resource_zia_fw_filtering_ip_source_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestAccResourceFWIPSourceGroupsBasic(t *testing.T) {
Config: testAccCheckFWIPSourceGroupsConfigure(resourceTypeAndName, generatedName, variable.FWSRCGroupDescription),
Check: resource.ComposeTestCheckFunc(
testAccCheckFWIPSourceGroupsExists(resourceTypeAndName, &groups),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", variable.FWSRCGroupName),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", "tf-acc-test-"+generatedName),
resource.TestCheckResourceAttr(resourceTypeAndName, "description", variable.FWSRCGroupDescription),
resource.TestCheckResourceAttr(resourceTypeAndName, "ip_addresses.#", "3"),
),
Expand All @@ -38,7 +38,7 @@ func TestAccResourceFWIPSourceGroupsBasic(t *testing.T) {
Config: testAccCheckFWIPSourceGroupsConfigure(resourceTypeAndName, generatedName, variable.FWSRCGroupDescription),
Check: resource.ComposeTestCheckFunc(
testAccCheckFWIPSourceGroupsExists(resourceTypeAndName, &groups),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", variable.FWSRCGroupName),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", "tf-acc-test-"+generatedName),
resource.TestCheckResourceAttr(resourceTypeAndName, "description", variable.FWSRCGroupDescription),
resource.TestCheckResourceAttr(resourceTypeAndName, "ip_addresses.#", "3"),
),
Expand Down Expand Up @@ -106,7 +106,7 @@ func testAccCheckFWIPSourceGroupsExists(resource string, rule *ipsourcegroups.IP
func testAccCheckFWIPSourceGroupsConfigure(resourceTypeAndName, generatedName, description string) string {
return fmt.Sprintf(`
resource "%s" "%s" {
name = "%s"
name = "tf-acc-test-%s"
description = "%s"
ip_addresses = ["192.168.1.1", "192.168.1.2", "192.168.1.3"]
}
Expand All @@ -119,7 +119,7 @@ resource "%s" "%s" {
// resource variables
resourcetype.FWFilteringSourceGroup,
generatedName,
variable.FWSRCGroupName,
generatedName,
description,

// data source variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestAccResourceFWNetworkApplicationGroupsBasic(t *testing.T) {
Config: testAccCheckFWNetworkApplicationGroupsConfigure(resourceTypeAndName, generatedName, variable.FWAppGroupDescription),
Check: resource.ComposeTestCheckFunc(
testAccCheckFWNetworkApplicationGroupsExists(resourceTypeAndName, &appGroups),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", variable.FWAppGroupName),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", "tf-acc-test-"+generatedName),
resource.TestCheckResourceAttr(resourceTypeAndName, "description", variable.FWAppGroupDescription),
resource.TestCheckResourceAttr(resourceTypeAndName, "network_applications.#", "11"),
),
Expand All @@ -38,7 +38,7 @@ func TestAccResourceFWNetworkApplicationGroupsBasic(t *testing.T) {
Config: testAccCheckFWNetworkApplicationGroupsConfigure(resourceTypeAndName, generatedName, variable.FWAppGroupDescription),
Check: resource.ComposeTestCheckFunc(
testAccCheckFWNetworkApplicationGroupsExists(resourceTypeAndName, &appGroups),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", variable.FWAppGroupName),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", "tf-acc-test-"+generatedName),
resource.TestCheckResourceAttr(resourceTypeAndName, "description", variable.FWAppGroupDescription),
resource.TestCheckResourceAttr(resourceTypeAndName, "network_applications.#", "11"),
),
Expand Down Expand Up @@ -106,7 +106,7 @@ func testAccCheckFWNetworkApplicationGroupsExists(resource string, rule *network
func testAccCheckFWNetworkApplicationGroupsConfigure(resourceTypeAndName, generatedName, description string) string {
return fmt.Sprintf(`
resource "%s" "%s" {
name = "%s"
name = "tf-acc-test-%s"
description = "%s"
network_applications = [
"YAMMER",
Expand All @@ -130,7 +130,7 @@ data "%s" "%s" {
// resource variables
resourcetype.FWFilteringNetworkAppGroups,
generatedName,
variable.FWAppGroupName,
generatedName,
description,

// data source variables
Expand Down
8 changes: 4 additions & 4 deletions zia/resource_zia_fw_filtering_network_services_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestAccResourceFWNetworkServiceGroupsBasic(t *testing.T) {
Config: testAccCheckFWNetworkServiceGroupsConfigure(resourceTypeAndName, generatedName, variable.FWNetworkServicesGroupDescription),
Check: resource.ComposeTestCheckFunc(
testAccCheckFWNetworkServiceGroupsExists(resourceTypeAndName, &services),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", variable.FWNetworkServicesGroupName),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", "tf-acc-test-"+generatedName),
resource.TestCheckResourceAttr(resourceTypeAndName, "description", variable.FWNetworkServicesGroupDescription),
resource.TestCheckResourceAttr(resourceTypeAndName, "services.#", "1"),
),
Expand All @@ -38,7 +38,7 @@ func TestAccResourceFWNetworkServiceGroupsBasic(t *testing.T) {
Config: testAccCheckFWNetworkServiceGroupsConfigure(resourceTypeAndName, generatedName, variable.FWNetworkServicesGroupDescription),
Check: resource.ComposeTestCheckFunc(
testAccCheckFWNetworkServiceGroupsExists(resourceTypeAndName, &services),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", variable.FWNetworkServicesGroupName),
resource.TestCheckResourceAttr(resourceTypeAndName, "name", "tf-acc-test-"+generatedName),
resource.TestCheckResourceAttr(resourceTypeAndName, "description", variable.FWNetworkServicesGroupDescription),
resource.TestCheckResourceAttr(resourceTypeAndName, "services.#", "1"),
),
Expand Down Expand Up @@ -115,7 +115,7 @@ data "zia_firewall_filtering_network_service" "example2" {
}
resource "%s" "%s" {
name = "%s"
name = "tf-acc-test-%s"
description = "%s"
services {
id = [
Expand All @@ -132,7 +132,7 @@ data "%s" "%s" {
// resource variables
resourcetype.FWFilteringNetworkServiceGroups,
generatedName,
variable.FWNetworkServicesGroupName,
generatedName,
description,

// data source variables
Expand Down
Loading

0 comments on commit b8454fd

Please sign in to comment.