Skip to content

Commit

Permalink
feat: convert static_ips data source tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sorccu committed Dec 6, 2024
1 parent 44e087a commit e17ef61
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 135 deletions.
135 changes: 0 additions & 135 deletions checkly/data_source_static_ips_test.go

This file was deleted.

173 changes: 173 additions & 0 deletions internal/provider/datasources/static_ips_data_source_test.go
Original file line number Diff line number Diff line change
@@ -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`),
},
},
})
}

0 comments on commit e17ef61

Please sign in to comment.