Skip to content

Commit caa4d5f

Browse files
committed
Add accceptance test generation
1 parent 2c4acf5 commit caa4d5f

33 files changed

+3023
-1
lines changed

provider/gen/connections/connections.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func GenerateConnections() error {
149149
})
150150
}
151151

152-
if !r.SkipTest {
152+
if !r.SkipTest && r.Resource {
153153
err := writeConnectionTest(r)
154154
if err != nil {
155155
return err

provider/gen/connections/connections.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ connections:
144144
config: polytomic.S3Configuration
145145
resource: true
146146
datasource: true
147+
skip_test: true
147148
attributes:
148149
- name: AwsAccessKeyID
149150
type: string
@@ -197,6 +198,7 @@ connections:
197198
config: polytomic.AthenaConfiguration
198199
resource: true
199200
datasource: true
201+
skip_test: true
200202
attributes:
201203
- name: AccessKeyID
202204
type: string
@@ -337,6 +339,7 @@ connections:
337339
config: polytomic.MarketoConfiguration
338340
datasource: true
339341
resource: true
342+
skip_test: true
340343
attributes:
341344
- name: ClientID
342345
type: string
@@ -396,6 +399,7 @@ connections:
396399
config: polytomic.ChargeBeeConnectionConfiguration
397400
datasource: true
398401
resource: true
402+
skip_test: true
399403
attributes:
400404
- name: Site
401405
type: string
@@ -415,6 +419,7 @@ connections:
415419
config: polytomic.CloudSQLConnectionConfiguration
416420
datasource: true
417421
resource: true
422+
skip_test: true
418423
attributes:
419424
- name: ConnectionName
420425
type: string
@@ -672,6 +677,7 @@ connections:
672677
config: polytomic.RedshiftConnectionConfiguration
673678
datasource: true
674679
resource: true
680+
skip_test: true
675681
attributes:
676682
- name: Hostname
677683
type: string
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package provider
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"regexp"
7+
"testing"
8+
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
11+
)
12+
13+
func TestAccAffinityConnection(t *testing.T) {
14+
name := "TestAcc"
15+
resource.Test(t, resource.TestCase{
16+
PreCheck: func() { testAccPreCheck(t) },
17+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
18+
Steps: []resource.TestStep{
19+
// Missing configuration
20+
{
21+
Config: testAccAffinityConnectionResourceNoConfig(name),
22+
ExpectError: regexp.MustCompile("The argument \"configuration\" is required, but no definition was found."),
23+
},
24+
// Empty configuration
25+
{
26+
Config: testAccAffinityConnectionResourceMissingRequired(name),
27+
ExpectError: regexp.MustCompile("Inappropriate value for attribute \"configuration\":"),
28+
},
29+
{
30+
Config: testAccAffinityConnectionResource(name),
31+
Check: resource.ComposeTestCheckFunc(
32+
// Check if the resource exists
33+
testAccAffinityConnectionExists(name),
34+
// Check the name
35+
resource.TestCheckResourceAttr("polytomic_affinity_connection.test", "name", name),
36+
),
37+
},
38+
},
39+
})
40+
}
41+
42+
func testAccAffinityConnectionExists(name string) resource.TestCheckFunc {
43+
return func(s *terraform.State) error {
44+
_, ok := s.RootModule().Resources["polytomic_affinity_connection.test"]
45+
if !ok {
46+
return fmt.Errorf("not found: %s", "polytomic_affinity_connection.test")
47+
}
48+
49+
client := testClient()
50+
connections, err := client.Connections().List(context.TODO())
51+
if err != nil {
52+
return err
53+
}
54+
var found bool
55+
for _, connection := range connections {
56+
if connection.Name == name {
57+
found = true
58+
break
59+
}
60+
}
61+
62+
if !found {
63+
return fmt.Errorf("connection %s not found", name)
64+
}
65+
66+
return nil
67+
68+
}
69+
}
70+
71+
func testAccAffinityConnectionResource(name string) string {
72+
return fmt.Sprintf(`
73+
resource "polytomic_affinity_connection" "test" {
74+
name = "%s"
75+
configuration = {
76+
api_key = "my-api-key"
77+
}
78+
}
79+
`, name)
80+
}
81+
82+
func testAccAffinityConnectionResourceNoConfig(name string) string {
83+
return fmt.Sprintf(`
84+
resource "polytomic_affinity_connection" "test" {
85+
name = "%s"
86+
}
87+
`, name)
88+
}
89+
90+
func testAccAffinityConnectionResourceMissingRequired(name string) string {
91+
return fmt.Sprintf(`
92+
resource "polytomic_affinity_connection" "test" {
93+
name = "%s"
94+
configuration = {}
95+
}`, name)
96+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package provider
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"regexp"
7+
"testing"
8+
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
11+
)
12+
13+
func TestAccAmplitudeConnection(t *testing.T) {
14+
name := "TestAcc"
15+
resource.Test(t, resource.TestCase{
16+
PreCheck: func() { testAccPreCheck(t) },
17+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
18+
Steps: []resource.TestStep{
19+
// Missing configuration
20+
{
21+
Config: testAccAmplitudeConnectionResourceNoConfig(name),
22+
ExpectError: regexp.MustCompile("The argument \"configuration\" is required, but no definition was found."),
23+
},
24+
// Empty configuration
25+
{
26+
Config: testAccAmplitudeConnectionResourceMissingRequired(name),
27+
ExpectError: regexp.MustCompile("Inappropriate value for attribute \"configuration\":"),
28+
},
29+
{
30+
Config: testAccAmplitudeConnectionResource(name),
31+
Check: resource.ComposeTestCheckFunc(
32+
// Check if the resource exists
33+
testAccAmplitudeConnectionExists(name),
34+
// Check the name
35+
resource.TestCheckResourceAttr("polytomic_amplitude_connection.test", "name", name),
36+
),
37+
},
38+
},
39+
})
40+
}
41+
42+
func testAccAmplitudeConnectionExists(name string) resource.TestCheckFunc {
43+
return func(s *terraform.State) error {
44+
_, ok := s.RootModule().Resources["polytomic_amplitude_connection.test"]
45+
if !ok {
46+
return fmt.Errorf("not found: %s", "polytomic_amplitude_connection.test")
47+
}
48+
49+
client := testClient()
50+
connections, err := client.Connections().List(context.TODO())
51+
if err != nil {
52+
return err
53+
}
54+
var found bool
55+
for _, connection := range connections {
56+
if connection.Name == name {
57+
found = true
58+
break
59+
}
60+
}
61+
62+
if !found {
63+
return fmt.Errorf("connection %s not found", name)
64+
}
65+
66+
return nil
67+
68+
}
69+
}
70+
71+
func testAccAmplitudeConnectionResource(name string) string {
72+
return fmt.Sprintf(`
73+
resource "polytomic_amplitude_connection" "test" {
74+
name = "%s"
75+
configuration = {
76+
api_key = "my-api-key"
77+
secret_key = "my-secret-key"
78+
}
79+
}
80+
`, name)
81+
}
82+
83+
func testAccAmplitudeConnectionResourceNoConfig(name string) string {
84+
return fmt.Sprintf(`
85+
resource "polytomic_amplitude_connection" "test" {
86+
name = "%s"
87+
}
88+
`, name)
89+
}
90+
91+
func testAccAmplitudeConnectionResourceMissingRequired(name string) string {
92+
return fmt.Sprintf(`
93+
resource "polytomic_amplitude_connection" "test" {
94+
name = "%s"
95+
configuration = {}
96+
}`, name)
97+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package provider
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"regexp"
7+
"testing"
8+
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
11+
)
12+
13+
func TestAccAscendConnection(t *testing.T) {
14+
name := "TestAcc"
15+
resource.Test(t, resource.TestCase{
16+
PreCheck: func() { testAccPreCheck(t) },
17+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
18+
Steps: []resource.TestStep{
19+
// Missing configuration
20+
{
21+
Config: testAccAscendConnectionResourceNoConfig(name),
22+
ExpectError: regexp.MustCompile("The argument \"configuration\" is required, but no definition was found."),
23+
},
24+
// Empty configuration
25+
{
26+
Config: testAccAscendConnectionResourceMissingRequired(name),
27+
ExpectError: regexp.MustCompile("Inappropriate value for attribute \"configuration\":"),
28+
},
29+
{
30+
Config: testAccAscendConnectionResource(name),
31+
Check: resource.ComposeTestCheckFunc(
32+
// Check if the resource exists
33+
testAccAscendConnectionExists(name),
34+
// Check the name
35+
resource.TestCheckResourceAttr("polytomic_ascend_connection.test", "name", name),
36+
),
37+
},
38+
},
39+
})
40+
}
41+
42+
func testAccAscendConnectionExists(name string) resource.TestCheckFunc {
43+
return func(s *terraform.State) error {
44+
_, ok := s.RootModule().Resources["polytomic_ascend_connection.test"]
45+
if !ok {
46+
return fmt.Errorf("not found: %s", "polytomic_ascend_connection.test")
47+
}
48+
49+
client := testClient()
50+
connections, err := client.Connections().List(context.TODO())
51+
if err != nil {
52+
return err
53+
}
54+
var found bool
55+
for _, connection := range connections {
56+
if connection.Name == name {
57+
found = true
58+
break
59+
}
60+
}
61+
62+
if !found {
63+
return fmt.Errorf("connection %s not found", name)
64+
}
65+
66+
return nil
67+
68+
}
69+
}
70+
71+
func testAccAscendConnectionResource(name string) string {
72+
return fmt.Sprintf(`
73+
resource "polytomic_ascend_connection" "test" {
74+
name = "%s"
75+
configuration = {
76+
api_key = "my-api-key"
77+
}
78+
}
79+
`, name)
80+
}
81+
82+
func testAccAscendConnectionResourceNoConfig(name string) string {
83+
return fmt.Sprintf(`
84+
resource "polytomic_ascend_connection" "test" {
85+
name = "%s"
86+
}
87+
`, name)
88+
}
89+
90+
func testAccAscendConnectionResourceMissingRequired(name string) string {
91+
return fmt.Sprintf(`
92+
resource "polytomic_ascend_connection" "test" {
93+
name = "%s"
94+
configuration = {}
95+
}`, name)
96+
}

0 commit comments

Comments
 (0)