-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP/Ideas] Config matrices for integration tests #7957
Changes from 8 commits
f67d8d7
39cb492
1f12a3e
56729d7
ce4ab51
c2b8060
166709d
0f1a8d6
89f5f0e
57e11ea
d7fe343
d71d210
938ba32
4301a8d
a572279
180e31f
8dd0a98
38cc081
b3981f7
b6735ea
17c3f2a
f9f0cd1
a7382e6
760cdc3
9b9f5be
f45c67e
88f3ff8
821f71a
d1321cc
12f1e20
f2896de
13252a6
0117461
2ca7e84
113f947
2246ccb
5e4335c
9a21006
edc7982
a322c5f
476530a
46bc089
4a036b7
084e28e
9d93da7
9368483
26e33a6
fb97295
ba2cac4
44a8772
6881d7b
eb3c9fe
22367be
b3f09e0
3fcd7b8
fcfb663
f0f9954
6c0f666
c14c93e
39d3b1b
082801d
ab3a368
e1d587c
267a561
263ec8a
513976b
8d3ed55
23d4e7f
a337d77
e4b209f
45e1950
972e304
ad8d2bc
47fe928
1973703
7a4a29d
78a9fe1
605e642
3fc2715
fd4fcd6
58c4e28
8c890bf
58981e5
a0d8c3e
a7191c0
95696e5
4e6904a
6ba4e9d
7a0c524
494aa29
345e4cc
1f0bb6f
77e24a7
d80c4d4
fc39b36
27f457d
0de565e
a200df2
76a402c
fae8cda
ffe2062
dfd3e0d
86cc04b
90a9e0f
64dfd65
2c9cd97
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you 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 compose | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
"os" | ||
"sort" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
func init() { | ||
rand.Seed(time.Now().UnixNano()) | ||
} | ||
|
||
type TestRunner struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported type TestRunner should have comment or be unexported There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported type TestRunner should have comment or be unexported |
||
Service string | ||
Options map[string][]string | ||
Parallel bool | ||
Timeout int | ||
} | ||
|
||
type Suite map[string]func(t *testing.T, host string) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exported type Suite should have comment or be unexported |
||
|
||
func (r *TestRunner) scenarios() []map[string]string { | ||
n := 1 | ||
for _, values := range r.Options { | ||
n *= len(values) | ||
} | ||
|
||
scenarios := make([]map[string]string, n) | ||
for variable, values := range r.Options { | ||
v := 0 | ||
for i, s := range scenarios { | ||
if s == nil { | ||
s = make(map[string]string) | ||
scenarios[i] = s | ||
} | ||
s[variable] = values[v] | ||
v = (v + 1) % len(values) | ||
} | ||
} | ||
|
||
return scenarios | ||
} | ||
|
||
func (r *TestRunner) Run(t *testing.T, tests Suite) { | ||
jsoriano marked this conversation as resolved.
Show resolved
Hide resolved
jsoriano marked this conversation as resolved.
Show resolved
Hide resolved
jsoriano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
timeout := r.Timeout | ||
if timeout == 0 { | ||
timeout = 300 | ||
} | ||
|
||
for _, s := range r.scenarios() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to still have something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have just added something like this, look at 89f5f0e I prefer to do it as a host override instead of only a feature disable for two reasons:
|
||
var vars []string | ||
for k, v := range s { | ||
os.Setenv(k, v) | ||
vars = append(vars, fmt.Sprintf("%s=%s", k, v)) | ||
} | ||
sort.Strings(vars) | ||
desc := strings.Join(vars, ",") | ||
|
||
seq := make([]byte, 16) | ||
rand.Read(seq) | ||
name := fmt.Sprintf("%s_%x", r.Service, seq) | ||
|
||
project, err := getComposeProject(name) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
project.SetParameters(s) | ||
|
||
t.Run(desc, func(t *testing.T) { | ||
if r.Parallel { | ||
t.Parallel() | ||
} | ||
|
||
err := project.Start(r.Service) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer project.Down() | ||
|
||
err = project.Wait(timeout, r.Service) | ||
if err != nil { | ||
t.Fatal(errors.Wrapf(err, "waiting for %s/%s", r.Service, desc)) | ||
} | ||
|
||
host, err := project.Host(r.Service) | ||
if err != nil { | ||
t.Fatal(errors.Wrapf(err, "getting host for %s/%s", r.Service, desc)) | ||
} | ||
|
||
for name, test := range tests { | ||
t.Run(name, func(t *testing.T) { test(t, host) }) | ||
} | ||
}) | ||
|
||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version: "2.4" | ||
|
||
services: | ||
redis: | ||
image: redis:${REDIS_VERSION:-4.0.11}-${IMAGE_OS:-alpine} | ||
healthcheck: | ||
test: | ||
- "CMD-SHELL" | ||
- "nc -z localhost 6379" | ||
interval: 1s | ||
retries: 90 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported type TestRunner should have comment or be unexported