From e17ef61d03cfa492b456d24a3587a8bd0507e7bb Mon Sep 17 00:00:00 2001 From: Simo Kinnunen Date: Sat, 7 Dec 2024 03:58:52 +0900 Subject: [PATCH] feat: convert static_ips data source tests --- checkly/data_source_static_ips_test.go | 135 -------------- .../static_ips_data_source_test.go | 173 ++++++++++++++++++ 2 files changed, 173 insertions(+), 135 deletions(-) delete mode 100644 checkly/data_source_static_ips_test.go create mode 100644 internal/provider/datasources/static_ips_data_source_test.go diff --git a/checkly/data_source_static_ips_test.go b/checkly/data_source_static_ips_test.go deleted file mode 100644 index 0ba4bf4..0000000 --- a/checkly/data_source_static_ips_test.go +++ /dev/null @@ -1,135 +0,0 @@ -package checkly - -import ( - "regexp" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" -) - -func TestAccStaticIPsAll(t *testing.T) { - config := `data "checkly_static_ips" "test" {}` - - accTestCase(t, []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "data.checkly_static_ips.test", - "addresses.#", - "162", - ), - ), - }, - }) -} - -func TestAccStaticIPsTwoRegionsOnly(t *testing.T) { - config := `data "checkly_static_ips" "test" { - locations = ["us-east-1","ap-southeast-1"] - }` - - accTestCase(t, []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "data.checkly_static_ips.test", - "addresses.#", - "20", - ), - ), - }, - }) -} - -func TestAccStaticIPsIPv6Only(t *testing.T) { - config := `data "checkly_static_ips" "test" { - ip_family = "IPv6" - }` - - accTestCase(t, []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "data.checkly_static_ips.test", - "addresses.#", - "22", - ), - ), - }, - }) -} - -func TestAccStaticIPsIPv4Only(t *testing.T) { - config := `data "checkly_static_ips" "test" { - ip_family = "IPv4" - }` - - accTestCase(t, []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "data.checkly_static_ips.test", - "addresses.#", - "140", - ), - ), - }, - }) -} - -func TestAccStaticIPsIPv6AndOneRegionOnly(t *testing.T) { - config := `data "checkly_static_ips" "test" { - ip_family = "IPv6" - locations = ["us-east-1"] - }` - - accTestCase(t, []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "data.checkly_static_ips.test", - "addresses.#", - "1", - ), - ), - }, - }) -} - -func TestAccStaticIPsIPv4AndOneRegionOnly(t *testing.T) { - config := `data "checkly_static_ips" "test" { - ip_family = "IPv4" - locations = ["us-east-1"] - }` - - accTestCase(t, []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "data.checkly_static_ips.test", - "addresses.#", - "12", - ), - ), - }, - }) -} - -func TestAccStaticIPsInvalidIPFamily(t *testing.T) { - config := `data "checkly_static_ips" "test" { - ip_family = "invalid" - }` - - accTestCase(t, []resource.TestStep{ - { - Config: config, - ExpectError: regexp.MustCompile(`"ip_family" must be either "IPv6" or "IPv4"`), - }, - }) -} diff --git a/internal/provider/datasources/static_ips_data_source_test.go b/internal/provider/datasources/static_ips_data_source_test.go new file mode 100644 index 0000000..4f0a2bd --- /dev/null +++ b/internal/provider/datasources/static_ips_data_source_test.go @@ -0,0 +1,173 @@ +package datasources_test + +import ( + "regexp" + "testing" + + "github.com/checkly/terraform-provider-checkly/internal/provider" + "github.com/checkly/terraform-provider-checkly/internal/provider/globalregistry" + "github.com/hashicorp/terraform-plugin-framework/providerserver" + "github.com/hashicorp/terraform-plugin-go/tfprotov6" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func protoV6ProviderFactories() map[string]func() (tfprotov6.ProviderServer, error) { + return map[string]func() (tfprotov6.ProviderServer, error){ + "checkly": providerserver.NewProtocol6WithError(provider.New("test", globalregistry.Registry)()), + } +} + +func TestAccStaticIPsAll(t *testing.T) { + resource.UnitTest(t, resource.TestCase{ + ProtoV6ProviderFactories: protoV6ProviderFactories(), + + Steps: []resource.TestStep{ + { + Config: ` + data "checkly_static_ips" "test" {} + `, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr( + "data.checkly_static_ips.test", + "addresses.#", + "162", + ), + ), + }, + }, + }) +} + +func TestAccStaticIPsTwoRegionsOnly(t *testing.T) { + resource.UnitTest(t, resource.TestCase{ + ProtoV6ProviderFactories: protoV6ProviderFactories(), + + Steps: []resource.TestStep{ + { + Config: ` + data "checkly_static_ips" "test" { + locations = ["us-east-1","ap-southeast-1"] + } + `, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr( + "data.checkly_static_ips.test", + "addresses.#", + "20", + ), + ), + }, + }, + }) +} + +func TestAccStaticIPsIPv6Only(t *testing.T) { + resource.UnitTest(t, resource.TestCase{ + ProtoV6ProviderFactories: protoV6ProviderFactories(), + + Steps: []resource.TestStep{ + { + Config: ` + data "checkly_static_ips" "test" { + ip_family = "IPv6" + } + `, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr( + "data.checkly_static_ips.test", + "addresses.#", + "22", + ), + ), + }, + }, + }) +} + +func TestAccStaticIPsIPv4Only(t *testing.T) { + resource.UnitTest(t, resource.TestCase{ + ProtoV6ProviderFactories: protoV6ProviderFactories(), + + Steps: []resource.TestStep{ + { + Config: ` + data "checkly_static_ips" "test" { + ip_family = "IPv4" + } + `, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr( + "data.checkly_static_ips.test", + "addresses.#", + "140", + ), + ), + }, + }, + }) +} + +func TestAccStaticIPsIPv6AndOneRegionOnly(t *testing.T) { + resource.UnitTest(t, resource.TestCase{ + ProtoV6ProviderFactories: protoV6ProviderFactories(), + + Steps: []resource.TestStep{ + { + Config: ` + data "checkly_static_ips" "test" { + ip_family = "IPv6" + locations = ["us-east-1"] + } + `, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr( + "data.checkly_static_ips.test", + "addresses.#", + "1", + ), + ), + }, + }, + }) +} + +func TestAccStaticIPsIPv4AndOneRegionOnly(t *testing.T) { + resource.UnitTest(t, resource.TestCase{ + ProtoV6ProviderFactories: protoV6ProviderFactories(), + + Steps: []resource.TestStep{ + { + Config: ` + data "checkly_static_ips" "test" { + ip_family = "IPv4" + locations = ["us-east-1"] + } + `, + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr( + "data.checkly_static_ips.test", + "addresses.#", + "12", + ), + ), + }, + }, + }) +} + +func TestAccStaticIPsInvalidIPFamily(t *testing.T) { + resource.UnitTest(t, resource.TestCase{ + ProtoV6ProviderFactories: protoV6ProviderFactories(), + + Steps: []resource.TestStep{ + { + Config: ` + data "checkly_static_ips" "test" { + ip_family = "invalid" + } + `, + ExpectError: regexp.MustCompile(`Invalid Attribute Value Match`), + }, + }, + }) +}