-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathprebuiltconfigs_test.go
More file actions
269 lines (251 loc) · 9.06 KB
/
prebuiltconfigs_test.go
File metadata and controls
269 lines (251 loc) · 9.06 KB
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package prebuiltconfigs
import (
"slices"
"testing"
"github.com/google/go-cmp/cmp"
)
var expectedToolSources = []string{
"alloydb-omni",
"alloydb-postgres-admin",
"alloydb-postgres-observability",
"alloydb-postgres",
"conversational-analytics-with-data-agent",
"bigquery",
"clickhouse",
"cloud-healthcare",
"cloud-sql-mssql-admin",
"cloud-sql-mssql-observability",
"cloud-sql-mssql",
"cloud-sql-mysql-admin",
"cloud-sql-mysql-observability",
"cloud-sql-mysql",
"cloud-sql-postgres-admin",
"cloud-sql-postgres-observability",
"cloud-sql-postgres",
"dataplex",
"dataproc",
"firestore",
"elasticsearch",
"looker-conversational-analytics",
"looker-dev",
"looker",
"mindsdb",
"mssql",
"mysql",
"neo4j",
"oceanbase",
"oracledb",
"postgres",
"serverless-spark",
"singlestore",
"snowflake",
"spanner-postgres",
"spanner",
"sqlite",
}
func TestGetPrebuiltSources(t *testing.T) {
t.Run("Test Get Prebuilt Sources", func(t *testing.T) {
sources := GetPrebuiltSources()
slices.Sort(expectedToolSources)
slices.Sort(sources)
if diff := cmp.Diff(expectedToolSources, sources); diff != "" {
t.Fatalf("incorrect sources parse: diff %v", diff)
}
})
}
func TestLoadPrebuiltToolYAMLs(t *testing.T) {
test_name := "test load prebuilt configs"
expectedKeys := expectedToolSources
t.Run(test_name, func(t *testing.T) {
configsMap, keys, err := loadPrebuiltToolYAMLs()
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
foundExpectedKeys := make(map[string]bool)
if len(expectedKeys) != len(configsMap) {
t.Fatalf("Failed to load all prebuilt tools.")
}
for _, expectedKey := range expectedKeys {
_, ok := configsMap[expectedKey]
if !ok {
t.Fatalf("Prebuilt tools for '%s' was NOT FOUND in the loaded map.", expectedKey)
} else {
foundExpectedKeys[expectedKey] = true // Mark as found
}
}
t.Log(expectedKeys)
t.Log(keys)
slices.Sort(expectedKeys)
slices.Sort(keys)
if diff := cmp.Diff(expectedKeys, keys); diff != "" {
t.Fatalf("incorrect sources parse: diff %v", diff)
}
})
}
func TestGetPrebuiltTool(t *testing.T) {
alloydb_omni_config := getOrFatal(t, "alloydb-omni")
alloydb_admin_config := getOrFatal(t, "alloydb-postgres-admin")
alloydb_observability_config := getOrFatal(t, "alloydb-postgres-observability")
alloydb_config := getOrFatal(t, "alloydb-postgres")
bigquery_config := getOrFatal(t, "bigquery")
conversational_analytics_config := getOrFatal(t, "conversational-analytics-with-data-agent")
clickhouse_config := getOrFatal(t, "clickhouse")
cloudsqlpg_observability_config := getOrFatal(t, "cloud-sql-postgres-observability")
cloudsqlpg_config := getOrFatal(t, "cloud-sql-postgres")
cloudsqlpg_admin_config := getOrFatal(t, "cloud-sql-postgres-admin")
cloudsqlmysql_admin_config := getOrFatal(t, "cloud-sql-mysql-admin")
cloudsqlmssql_admin_config := getOrFatal(t, "cloud-sql-mssql-admin")
cloudsqlmysql_observability_config := getOrFatal(t, "cloud-sql-mysql-observability")
cloudsqlmysql_config := getOrFatal(t, "cloud-sql-mysql")
cloudsqlmssql_observability_config := getOrFatal(t, "cloud-sql-mssql-observability")
cloudsqlmssql_config := getOrFatal(t, "cloud-sql-mssql")
dataplex_config := getOrFatal(t, "dataplex")
firestoreconfig := getOrFatal(t, "firestore")
looker_config := getOrFatal(t, "looker")
lookerca_config := getOrFatal(t, "looker-conversational-analytics")
mysql_config := getOrFatal(t, "mysql")
mssql_config := getOrFatal(t, "mssql")
oceanbase_config := getOrFatal(t, "oceanbase")
postgresconfig := getOrFatal(t, "postgres")
singlestore_config := getOrFatal(t, "singlestore")
serverlessspark_config := getOrFatal(t, "serverless-spark")
spanner_config := getOrFatal(t, "spanner")
spannerpg_config := getOrFatal(t, "spanner-postgres")
mindsdb_config := getOrFatal(t, "mindsdb")
sqlite_config := getOrFatal(t, "sqlite")
neo4jconfig := getOrFatal(t, "neo4j")
oracle_config := getOrFatal(t, "oracledb")
healthcare_config := getOrFatal(t, "cloud-healthcare")
snowflake_config := getOrFatal(t, "snowflake")
if len(alloydb_omni_config) <= 0 {
t.Fatalf("unexpected error: could not fetch alloydb omni prebuilt tools yaml")
}
if len(alloydb_admin_config) <= 0 {
t.Fatalf("unexpected error: could not fetch alloydb admin prebuilt tools yaml")
}
if len(alloydb_config) <= 0 {
t.Fatalf("unexpected error: could not fetch alloydb prebuilt tools yaml")
}
if len(alloydb_observability_config) <= 0 {
t.Fatalf("unexpected error: could not fetch alloydb-observability prebuilt tools yaml")
}
if len(bigquery_config) <= 0 {
t.Fatalf("unexpected error: could not fetch bigquery prebuilt tools yaml")
}
if len(conversational_analytics_config) <= 0 {
t.Fatalf("unexpected error: could not fetch bigquery conversational analytics prebuilt tools yaml")
}
if len(clickhouse_config) <= 0 {
t.Fatalf("unexpected error: could not fetch clickhouse prebuilt tools yaml")
}
if len(cloudsqlpg_observability_config) <= 0 {
t.Fatalf("unexpected error: could not fetch cloud sql pg observability prebuilt tools yaml")
}
if len(cloudsqlpg_config) <= 0 {
t.Fatalf("unexpected error: could not fetch cloud sql pg prebuilt tools yaml")
}
if len(cloudsqlpg_admin_config) <= 0 {
t.Fatalf("unexpected error: could not fetch cloud sql pg admin prebuilt tools yaml")
}
if len(cloudsqlmysql_admin_config) <= 0 {
t.Fatalf("unexpected error: could not fetch cloud sql mysql admin prebuilt tools yaml")
}
if len(cloudsqlmysql_observability_config) <= 0 {
t.Fatalf("unexpected error: could not fetch cloud sql mysql observability prebuilt tools yaml")
}
if len(cloudsqlmysql_config) <= 0 {
t.Fatalf("unexpected error: could not fetch cloud sql mysql prebuilt tools yaml")
}
if len(cloudsqlmssql_observability_config) <= 0 {
t.Fatalf("unexpected error: could not fetch cloud sql mssql observability prebuilt tools yaml")
}
if len(cloudsqlmssql_admin_config) <= 0 {
t.Fatalf("unexpected error: could not fetch cloud sql mssql admin prebuilt tools yaml")
}
if len(cloudsqlmssql_config) <= 0 {
t.Fatalf("unexpected error: could not fetch cloud sql mssql prebuilt tools yaml")
}
if len(dataplex_config) <= 0 {
t.Fatalf("unexpected error: could not fetch dataplex prebuilt tools yaml")
}
if len(firestoreconfig) <= 0 {
t.Fatalf("unexpected error: could not fetch firestore prebuilt tools yaml")
}
if len(looker_config) <= 0 {
t.Fatalf("unexpected error: could not fetch looker prebuilt tools yaml")
}
if len(lookerca_config) <= 0 {
t.Fatalf("unexpected error: could not fetch looker-conversational-analytics prebuilt tools yaml")
}
if len(mysql_config) <= 0 {
t.Fatalf("unexpected error: could not fetch mysql prebuilt tools yaml")
}
if len(mssql_config) <= 0 {
t.Fatalf("unexpected error: could not fetch mssql prebuilt tools yaml")
}
if len(oceanbase_config) <= 0 {
t.Fatalf("unexpected error: could not fetch oceanbase prebuilt tools yaml")
}
if len(postgresconfig) <= 0 {
t.Fatalf("unexpected error: could not fetch postgres prebuilt tools yaml")
}
if len(singlestore_config) <= 0 {
t.Fatalf("unexpected error: could not fetch singlestore prebuilt tools yaml")
}
if len(serverlessspark_config) <= 0 {
t.Fatalf("unexpected error: could not fetch serverless spark prebuilt tools yaml")
}
if len(snowflake_config) <= 0 {
t.Fatalf("unexpected error: could not fetch snowflake prebuilt tools yaml")
}
if len(spanner_config) <= 0 {
t.Fatalf("unexpected error: could not fetch spanner prebuilt tools yaml")
}
if len(spannerpg_config) <= 0 {
t.Fatalf("unexpected error: could not fetch spanner pg prebuilt tools yaml")
}
if len(mindsdb_config) <= 0 {
t.Fatalf("unexpected error: could not fetch spanner pg prebuilt tools yaml")
}
if len(sqlite_config) <= 0 {
t.Fatalf("unexpected error: could not fetch sqlite prebuilt tools yaml")
}
if len(neo4jconfig) <= 0 {
t.Fatalf("unexpected error: could not fetch neo4j prebuilt tools yaml")
}
if len(healthcare_config) <= 0 {
t.Fatalf("unexpected error: could not fetch healthcare prebuilt tools yaml")
}
if len(snowflake_config) <= 0 {
t.Fatalf("unexpected error: could not fetch snowflake prebuilt tools yaml")
}
if len(oracle_config) <= 0 {
t.Fatalf("unexpected error: could not fetch oracle prebuilt tools yaml")
}
}
func TestFailGetPrebuiltTool(t *testing.T) {
_, err := Get("sql")
if err == nil {
t.Fatalf("unexpected an error but got nil.")
}
}
func getOrFatal(t *testing.T, prebuiltSourceConfig string) []byte {
bytes, err := Get(prebuiltSourceConfig)
if err != nil {
t.Fatalf("Cannot get prebuilt config for %q, error %v", prebuiltSourceConfig, err)
}
return bytes
}