-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocker-compose-legacy-auth_test.go
More file actions
338 lines (308 loc) · 10.4 KB
/
Copy pathdocker-compose-legacy-auth_test.go
File metadata and controls
338 lines (308 loc) · 10.4 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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
//go:build docker || compose || integration || integrationComposeLegacyAuth
// +build docker compose integration integrationComposeLegacyAuth
package integration
import (
"fmt"
"strings"
"testing"
"path/filepath"
"github.com/gruntwork-io/terratest/modules/docker"
"github.com/gruntwork-io/terratest/modules/logger"
"github.com/gruntwork-io/terratest/modules/random"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"github.com/compose-spec/compose-go/v2/dotenv"
)
const (
dockerLegacyAuthDir = "../../../docker/legacy-auth"
)
var legacyAuthComposeFile = "compose.yaml"
var legacyAuthComposePluginsFile = "compose.plugins.yaml"
var legacyAuthComposeDedicatedPluginsFile = "compose.dedicated-plugins.yaml"
var legacyAuthComposeDelegatedOperationsFile = "compose.delegated-operators.yaml"
var legacyAuthEnvTemplateFilePath = filepath.Join(dockerLegacyAuthDir, "env.template")
type commonServicesLegacyAuthDockerComposeUpTest struct {
suite.Suite
composeFilePath string
dotEnvFiles []string
overrideFiles []string
overrideFilesPlugins []string
overrideFilesDO []string
}
func TestDockerComposeUpLegacyAuth(t *testing.T) {
t.Parallel()
_, err := filepath.Abs(dockerLegacyAuthDir)
require.NoError(t, err)
// Set the override files used for the tests
overrideFiles := []string{
overrideFile,
mongodbComposeFile,
}
// Plugins require overriding the teams-plugin image
var overrideFilesPlugins []string
overrideFilesPlugins = append(overrideFilesPlugins, overrideFiles...)
overrideFilesPlugins = append(overrideFilesPlugins, mongodbComposeFilePlugins)
var overrideFilesDO []string
overrideFilesDO = append(overrideFilesDO, legacyAuthComposePluginsFile)
overrideFilesDO = append(overrideFilesDO, overrideFiles...)
overrideFilesDO = append(overrideFilesDO, mongodbComposeFileDO)
suite.Run(t, &commonServicesLegacyAuthDockerComposeUpTest{
Suite: suite.Suite{},
composeFilePath: dockerLegacyAuthDir,
dotEnvFiles: []string{
legacyAuthEnvTemplateFilePath,
legacyAuthEnvFixtureFilePath,
},
overrideFiles: overrideFiles,
overrideFilesPlugins: overrideFilesPlugins,
overrideFilesDO: overrideFilesDO,
})
}
func (s *commonServicesLegacyAuthDockerComposeUpTest) TestDockerComposeUp() {
testCases := []struct {
name string
composeFile string
overrideFiles []string
envFiles []string // file paths to ".env" files with additional environment variable data
expected []serviceValidations
}{
{
"compose",
legacyAuthComposeFile,
s.overrideFiles,
s.dotEnvFiles,
[]serviceValidations{
{
name: "teams-api",
url: "http://127.0.0.1:8000/health",
responsePayload: `{"status":{"teams":"available"}}`,
httpResponseCode: 200,
log: "FiftyOne Teams API starting up",
},
{
name: "teams-app",
url: "http://127.0.0.1:3000/api/hello",
responsePayload: `{"status":"available"}`,
httpResponseCode: 200,
log: " ✓ Ready in",
},
{
name: "teams-cas",
url: "http://127.0.0.1:3030/cas/api",
responsePayload: `{"status":"available"}`,
httpResponseCode: 200,
log: "FiftyOne CAS starting up",
},
// ordering this last to avoid test flakes where testing for log before the container is running
{
name: "fiftyone-app",
url: "",
responsePayload: "",
httpResponseCode: 200,
log: "Running on http://0.0.0.0:5151",
},
},
},
{
"composePlugins",
legacyAuthComposePluginsFile,
s.overrideFiles,
s.dotEnvFiles,
[]serviceValidations{
{
name: "teams-api",
url: "http://127.0.0.1:8000/health",
responsePayload: `{"status":{"teams":"available"}}`,
httpResponseCode: 200,
log: "FiftyOne Teams API starting up",
},
{
name: "teams-app",
url: "http://127.0.0.1:3000/api/hello",
responsePayload: `{"status":"available"}`,
httpResponseCode: 200,
log: " ✓ Ready in",
},
{
name: "teams-cas",
url: "http://127.0.0.1:3030/cas/api",
responsePayload: `{"status":"available"}`,
httpResponseCode: 200,
log: "FiftyOne CAS starting up",
},
// ordering this last to avoid test flakes where testing for log before the container is running
{
name: "fiftyone-app",
url: "",
responsePayload: "",
httpResponseCode: 200,
log: "Running on http://0.0.0.0:5151",
},
},
},
{
"composeDedicatedPlugins",
legacyAuthComposeDedicatedPluginsFile,
s.overrideFilesPlugins,
s.dotEnvFiles,
[]serviceValidations{
{
name: "teams-api",
url: "http://127.0.0.1:8000/health",
responsePayload: `{"status":{"teams":"available"}}`,
httpResponseCode: 200,
log: "FiftyOne Teams API starting up",
},
{
name: "teams-app",
url: "http://127.0.0.1:3000/api/hello",
responsePayload: `{"status":"available"}`,
httpResponseCode: 200,
log: " ✓ Ready in",
},
{
name: "teams-cas",
url: "http://127.0.0.1:3030/cas/api",
responsePayload: `{"status":"available"}`,
httpResponseCode: 200,
log: "FiftyOne CAS starting up",
},
// ordering this last to avoid test flakes where testing for log before the container is running
{
name: "fiftyone-app",
url: "",
responsePayload: "",
httpResponseCode: 0,
log: "Running on http://0.0.0.0:5151",
},
{
name: "teams-plugins",
url: "",
responsePayload: "",
httpResponseCode: 0,
log: "Running on http://0.0.0.0:5151", // same as fiftyone-app since plugins uses or is based on the fiftyone-app image
},
},
},
{
"composeDelegatedOperations",
legacyAuthComposeDelegatedOperationsFile,
s.overrideFilesDO,
s.dotEnvFiles,
[]serviceValidations{
{
name: "teams-api",
url: "http://127.0.0.1:8000/health",
responsePayload: `{"status":{"teams":"available"}}`,
httpResponseCode: 200,
log: "FiftyOne Teams API starting up",
},
{
name: "teams-app",
url: "http://127.0.0.1:3000/api/hello",
responsePayload: `{"status":"available"}`,
httpResponseCode: 200,
log: " ✓ Ready in",
},
{
name: "teams-cas",
url: "http://127.0.0.1:3030/cas/api",
responsePayload: `{"status":"available"}`,
httpResponseCode: 200,
log: "FiftyOne CAS starting up",
},
// ordering this last to avoid test flakes where testing for log before the container is running
{
name: "fiftyone-app",
url: "",
responsePayload: "",
httpResponseCode: 0,
log: "Running on http://0.0.0.0:5151",
},
{
name: "teams-do",
url: "",
responsePayload: "",
httpResponseCode: 0,
log: "Registering executor builtin",
},
},
},
}
for _, testCase := range testCases {
testCase := testCase
s.Run(testCase.name, func() {
subT := s.T()
// TODO: If we need parallel, dynamically set mongoDB port and configure the env vars with the custom port
// For now, we cannot perform concurrent runs because mongodb will error on port already in use
// subT.Parallel()
// TODO: Should we use `--env-file` instead of the library `dotenv.Read`
// to more closely align to real world usage?
// Something like
//
// ```shell
// docker compose \
// -f tests/fixtures/docker/compose.override.mongodb.yaml \
// --env-file tests/fixtures/docker/integration_legacy_auth.env
// up -d
// ```
//
// Use existing function to get map[string]string of environment variables from .env file(s)
environmentVariables, err := dotenv.Read(testCase.envFiles...)
s.NoError(err)
dockerOptions := &docker.Options{
ProjectName: "fiftyone-" + strings.ToLower(random.UniqueId()),
WorkingDir: dockerLegacyAuthDir,
EnvVars: environmentVariables,
}
// In golang, we cannot mix strings with string slice unpacking.
// Let's create a slice that will later be unpacked and used as an argument
// to the variadic function `docker.RunDockerCompose` parameter `args`.
argsConfig := []string{}
argsUp := []string{}
argsDown := []string{}
args := []string{"-f", testCase.composeFile}
for _, overrideFile := range testCase.overrideFiles {
args = append(args, "-f", overrideFile)
}
argsConfig = append(args, "config")
argsUp = append(argsUp, args...)
argsUp = append(argsUp, "up", "--detach")
argsDown = append(argsDown, args...)
argsDown = append(argsDown, "down", "--remove-orphans", "--timeout", "2")
argsDown = append(argsDown, "--volumes")
// Config
docker.RunDockerCompose(
subT,
dockerOptions,
argsConfig...,
)
// Delete containers after tests complete
defer docker.RunDockerCompose(
subT,
dockerOptions,
argsDown...,
)
// Run containers
output := docker.RunDockerCompose(
subT,
dockerOptions,
argsUp...,
)
// Validate system health
for _, expected := range testCase.expected {
logger.Log(subT, fmt.Sprintf("Validating service %s...", expected.name))
// Compose CLI v2.x emitted two spaces between `-1` and
// `Started`; v5.x emits one. Match either with \s+.
s.Regexp(fmt.Sprintf(`Container %s-%s-1\s+Started`, dockerOptions.ProjectName, expected.name), output, fmt.Sprintf("%s - %s - docker compose output should contain service container started", testCase.name, expected.name))
// Validate endpoint response
// Skip fiftyone-app and teams-plugins because they do not have callable endpoints that return a response payload.
if expected.url != "" {
validate_endpoint(subT, expected.url, expected.responsePayload, expected.httpResponseCode)
}
// Validate log output is expected
checkContainerLogsWithRetries(subT, dockerOptions, expected.name, testCase.name, expected.log)
}
})
}
}