Skip to content

Commit ae9e910

Browse files
feat: added test for cloud gateway add-on
1 parent 004ddbf commit ae9e910

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package tests
2+
3+
import (
4+
"testing"
5+
6+
"github.com/Kong/shared-speakeasy/hclbuilder"
7+
"github.com/hashicorp/terraform-plugin-framework/providerserver"
8+
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
9+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
10+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
11+
"github.com/kong/terraform-provider-konnect-beta/internal/provider"
12+
"github.com/stretchr/testify/require"
13+
)
14+
15+
var (
16+
providerFactoryBeta = map[string]func() (tfprotov6.ProviderServer, error){
17+
"konnect-beta": providerserver.NewProtocol6WithError(provider.New("")()),
18+
}
19+
)
20+
21+
func TestCloudGatewayAddOn(t *testing.T) {
22+
t.Run("Cloud Gateways AddOns", func(t *testing.T) {
23+
builder := hclbuilder.New()
24+
cp, err := hclbuilder.FromString(`
25+
resource "konnect_gateway_control_plane" "test_cp" {
26+
name = "tf-test-cp-us-external"
27+
cloud_gateway = true
28+
}
29+
`)
30+
require.NoError(t, err)
31+
addon, err := hclbuilder.FromString(`
32+
resource "konnect_cloud_gateway_add_on" "my_addon" {
33+
provider = konnect-beta
34+
name = "tf-test-add-on"
35+
36+
config = {
37+
managed_cache = {
38+
kind = "managed-cache.v0"
39+
40+
capacity_config = {
41+
tiered = {
42+
kind = "tiered"
43+
tier = "small"
44+
}
45+
}
46+
}
47+
}
48+
owner = {
49+
control_plane = {
50+
kind = "control-plane"
51+
control_plane_geo = "us"
52+
control_plane_id = konnect_gateway_control_plane.test_cp.id
53+
}
54+
}
55+
}
56+
`)
57+
require.NoError(t, err)
58+
59+
fullConfig := builder.
60+
Upsert(cp).
61+
Upsert(addon).
62+
Build()
63+
64+
resource.Test(t, resource.TestCase{
65+
ProtoV6ProviderFactories: providerFactoryBeta,
66+
ExternalProviders: map[string]resource.ExternalProvider{
67+
"konnect": {Source: "kong/konnect"},
68+
},
69+
Steps: []resource.TestStep{
70+
{
71+
Config: fullConfig,
72+
ConfigPlanChecks: resource.ConfigPlanChecks{
73+
PreApply: []plancheck.PlanCheck{
74+
plancheck.ExpectResourceAction(
75+
"konnect_cloud_gateway_add_on.my_addon",
76+
plancheck.ResourceActionCreate,
77+
),
78+
},
79+
},
80+
},
81+
{
82+
Config: fullConfig,
83+
ConfigPlanChecks: resource.ConfigPlanChecks{
84+
PreApply: []plancheck.PlanCheck{
85+
plancheck.ExpectEmptyPlan(),
86+
},
87+
},
88+
},
89+
},
90+
})
91+
})
92+
}

0 commit comments

Comments
 (0)