discovery/marathon: make test use separate instances of config

So tests can be executed in parallel without producing races.

Signed-off-by: Mateusz Gozdek <mgozdekof@gmail.com>
This commit is contained in:
Mateusz Gozdek 2021-10-25 09:19:18 +02:00 committed by Julien Pivotto
parent 2cf7479622
commit fedcb8999b
1 changed files with 6 additions and 10 deletions

View File

@ -29,11 +29,14 @@ import (
var (
marathonValidLabel = map[string]string{"prometheus": "yes"}
testServers = []string{"http://localhost:8080"}
conf = SDConfig{Servers: testServers}
)
func testConfig() SDConfig {
return SDConfig{Servers: testServers}
}
func testUpdateServices(client appListClient) ([]*targetgroup.Group, error) {
md, err := NewDiscovery(conf, nil)
md, err := NewDiscovery(testConfig(), nil)
if err != nil {
return nil, err
}
@ -126,7 +129,7 @@ func TestMarathonSDSendGroup(t *testing.T) {
}
func TestMarathonSDRemoveApp(t *testing.T) {
md, err := NewDiscovery(conf, nil)
md, err := NewDiscovery(testConfig(), nil)
if err != nil {
t.Fatalf("%s", err)
}
@ -278,13 +281,6 @@ func Test500ErrorHttpResponseWithValidJSONBody(t *testing.T) {
// Create a test server with mock HTTP handler.
ts := httptest.NewServer(http.HandlerFunc(respHandler))
defer ts.Close()
// Backup conf for future tests.
backupConf := conf
defer func() {
conf = backupConf
}()
// Setup conf for the test case.
conf = SDConfig{Servers: []string{ts.URL}}
// Execute test case and validate behavior.
_, err := testUpdateServices(nil)
if err == nil {