-
Notifications
You must be signed in to change notification settings - Fork 8
/
acceptance_datasource_connection_test.go
181 lines (158 loc) · 5.78 KB
/
acceptance_datasource_connection_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package provider
import (
"fmt"
"regexp"
"testing"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)
func TestAccDatasourceConnection_basic(t *testing.T) {
nameSpace := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactories,
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: testAccDatasourceConnection(nameSpace),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.materialize_connection.test_database", "database_name", nameSpace),
resource.TestCheckNoResourceAttr("data.materialize_connection.test_database", "schema_name"),
resource.TestCheckResourceAttr("data.materialize_connection.test_database", "connections.#", "3"),
resource.TestCheckResourceAttr("data.materialize_connection.test_database_schema", "database_name", nameSpace),
resource.TestCheckResourceAttr("data.materialize_connection.test_database_schema", "schema_name", nameSpace),
resource.TestCheckResourceAttr("data.materialize_connection.test_database_schema", "connections.#", "3"),
resource.TestCheckResourceAttr("data.materialize_connection.test_database_2", "database_name", nameSpace+"_2"),
resource.TestCheckNoResourceAttr("data.materialize_connection.test_database_2", "schema_name"),
resource.TestCheckResourceAttr("data.materialize_connection.test_database_2", "connections.#", "2"),
resource.TestCheckNoResourceAttr("data.materialize_connection.test_all", "database_name"),
resource.TestCheckNoResourceAttr("data.materialize_connection.test_all", "schema_name"),
// Test the specific connection
// TODO: Test intermittently fails
// resource.TestCheckResourceAttr("data.materialize_connection.specific", "connection_id", "u1"),
// resource.TestCheckResourceAttr("data.materialize_connection.specific", "connections.#", "1"),
// resource.TestCheckResourceAttr("data.materialize_connection.specific", "connections.0.id", "u1"),
// resource.TestCheckResourceAttr("data.materialize_connection.specific", "connections.0.name", "privatelink_conn"),
// Cannot ensure the exact number of objects with parallel tests
// Ensuring minimum
resource.TestMatchResourceAttr("data.materialize_connection.test_all", "connections.#", regexp.MustCompile("([5-9]|\\d{2,})")),
),
},
},
})
}
func testAccDatasourceConnection(nameSpace string) string {
return fmt.Sprintf(`
resource "materialize_database" "test" {
name = "%[1]s"
}
resource "materialize_database" "test_2" {
name = "%[1]s_2"
}
resource "materialize_schema" "public_schema" {
name = "public"
database_name = materialize_database.test.name
}
resource "materialize_schema" "public_schema2" {
name = "public"
database_name = materialize_database.test_2.name
}
resource "materialize_schema" "test" {
name = "%[1]s"
database_name = materialize_database.test.name
}
# data "materialize_connection" "specific" {
# connection_id = "u1"
# }
resource "materialize_connection_kafka" "a" {
name = "%[1]s_a"
database_name = materialize_database.test.name
schema_name = materialize_schema.test.name
security_protocol = "PLAINTEXT"
kafka_broker {
broker = "redpanda:9092"
}
validate = true
}
resource "materialize_connection_kafka" "b" {
name = "%[1]s_b"
database_name = materialize_database.test.name
schema_name = materialize_schema.test.name
security_protocol = "PLAINTEXT"
kafka_broker {
broker = "redpanda:9092"
}
validate = true
}
resource "materialize_connection_kafka" "c" {
name = "%[1]s_c"
database_name = materialize_database.test.name
schema_name = materialize_schema.test.name
security_protocol = "PLAINTEXT"
kafka_broker {
broker = "redpanda:9092"
}
validate = true
}
resource "materialize_connection_kafka" "d" {
name = "%[1]s_d"
database_name = materialize_database.test_2.name
schema_name = materialize_schema.public_schema2.name
security_protocol = "PLAINTEXT"
kafka_broker {
broker = "redpanda:9092"
}
validate = true
}
resource "materialize_connection_kafka" "e" {
name = "%[1]s_e"
database_name = materialize_database.test_2.name
schema_name = materialize_schema.public_schema2.name
security_protocol = "PLAINTEXT"
kafka_broker {
broker = "redpanda:9092"
}
validate = true
}
data "materialize_connection" "test_all" {
depends_on = [
materialize_connection_kafka.a,
materialize_connection_kafka.b,
materialize_connection_kafka.c,
materialize_connection_kafka.d,
materialize_connection_kafka.e,
]
}
data "materialize_connection" "test_database" {
database_name = materialize_database.test.name
depends_on = [
materialize_connection_kafka.a,
materialize_connection_kafka.b,
materialize_connection_kafka.c,
materialize_connection_kafka.d,
materialize_connection_kafka.e,
]
}
data "materialize_connection" "test_database_schema" {
database_name = materialize_database.test.name
schema_name = materialize_schema.test.name
depends_on = [
materialize_connection_kafka.a,
materialize_connection_kafka.b,
materialize_connection_kafka.c,
materialize_connection_kafka.d,
materialize_connection_kafka.e,
]
}
data "materialize_connection" "test_database_2" {
database_name = materialize_database.test_2.name
depends_on = [
materialize_connection_kafka.a,
materialize_connection_kafka.b,
materialize_connection_kafka.c,
materialize_connection_kafka.d,
materialize_connection_kafka.e,
]
}
`, nameSpace)
}