Skip to content

Commit

Permalink
Add test case for nil GeoRestrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbednarz committed Jun 25, 2020
1 parent 94b9e37 commit 7956ce0
Showing 1 changed file with 31 additions and 33 deletions.
64 changes: 31 additions & 33 deletions cloudflare/resource_cloudflare_custom_ssl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,39 +102,37 @@ func testAccCheckCloudflareCustomSSLExists(n string, customSSL *cloudflare.ZoneC
}
}

func TestFlattenCustomSSLOptionsOmitsEmptyGeoRestrictions(t *testing.T) {
customSSLOptions := cloudflare.ZoneCustomSSLOptions{
Certificate: "cert",
PrivateKey: "key",
BundleMethod: "method",
GeoRestrictions: nil,
Type: "type",
}

flattenedSettings := flattenCustomSSLOptions(customSSLOptions)
if _, ok := flattenedSettings["geo_restrictions"]; ok {
t.Error("Expected flattenCustomSSLOptions to omit geo_restrictions when nil")
}
}

func TestFlattenCustomSSLOptionsIncludesGeoRestrictions(t *testing.T) {
customSSLOptions := cloudflare.ZoneCustomSSLOptions{
Certificate: "cert",
PrivateKey: "key",
BundleMethod: "method",
GeoRestrictions: &cloudflare.ZoneCustomSSLGeoRestrictions{
Label: "label",
func TestAccCloudflareCustomSSLWithEmptyGeoRestrictions(t *testing.T) {
t.Parallel()
var customSSL cloudflare.ZoneCustomSSL
zoneID := os.Getenv("CLOUDFLARE_ZONE_ID")
rnd := generateRandomResourceName()
resourceName := "cloudflare_custom_ssl." + rnd
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckCloudflareCustomSSLDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckCloudflareCustomSSLWithEmptyGeoRestrictions(zoneID, rnd),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudflareCustomSSLExists(resourceName, &customSSL),
resource.TestCheckNoResourceAttr(resourceName, "custom_ssl_options.geo_restrictions"),
),
},
},
Type: "type",
}

flattenedSettings := flattenCustomSSLOptions(customSSLOptions)
geoRestrictions, ok := flattenedSettings["geo_restrictions"]
if !ok {
t.Error("Expected flattenCustomSSLOptions to include geo_restrictions when not nil")
}
})
}

if geoRestrictions != "label" {
t.Error("Expected value of geo_restrictions to match the Label property of provided ZoneCustomSSLGeoRestrictions struct")
}
func testAccCheckCloudflareCustomSSLWithEmptyGeoRestrictions(zoneID string, rName string) string {
return fmt.Sprintf(`
resource "cloudflare_custom_ssl" "%[2]s" {
zone_id = "%[1]s"
custom_ssl_options = {
certificate = "-----BEGIN CERTIFICATE-----\nMIIEsTCCA5mgAwIBAgISA53fvg2BvlK2QXSkdZewcNo4MA0GCSqGSIb3DQEBCwUA\nMEoxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MSMwIQYDVQQD\nExpMZXQncyBFbmNyeXB0IEF1dGhvcml0eSBYMzAeFw0yMDA2MjUyMTAzNDdaFw0y\nMDA5MjMyMTAzNDdaMB4xHDAaBgNVBAMTE3RlcnJhZm9ybS5jZmFwaS5uZXQwdjAQ\nBgcqhkjOPQIBBgUrgQQAIgNiAASBYi00+H4E7uUeogweuutTWvuAz8TC6ClQYemH\nCGA6xKrvSgWwjhvVM9joPhGlbUDbINKhVMdZd7q3DgBinVu9GjjKf1Ajxnr6nEsK\naq37tZmtUFawbqnJHAI+O3uTan+jggJpMIICZTAOBgNVHQ8BAf8EBAMCB4AwHQYD\nVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMAwGA1UdEwEB/wQCMAAwHQYDVR0O\nBBYEFACS0TnEhBjGvOG127Yn2O1/UCOoMB8GA1UdIwQYMBaAFKhKamMEfd265tE5\nt6ZFZe/zqOyhMG8GCCsGAQUFBwEBBGMwYTAuBggrBgEFBQcwAYYiaHR0cDovL29j\nc3AuaW50LXgzLmxldHNlbmNyeXB0Lm9yZzAvBggrBgEFBQcwAoYjaHR0cDovL2Nl\ncnQuaW50LXgzLmxldHNlbmNyeXB0Lm9yZy8wHgYDVR0RBB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vSgWwjhvVM9joPhGlbUDbINKhVMdZd7q3DgBinVu9GjjKf1Ajxnr6\nnEsKaq37tZmtUFawbqnJHAI+O3uTan8=\n-----END EC PRIVATE KEY-----\n"
bundle_method = "ubiquitous"
type = "legacy_custom"
}
}`, zoneID, rName)
}

0 comments on commit 7956ce0

Please sign in to comment.