15370: Fix flaky test.
[arvados.git] / sdk / go / keepclient / discover_test.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: Apache-2.0
4
5 package keepclient
6
7 import (
8         "crypto/md5"
9         "fmt"
10         "net/http"
11         "os"
12
13         "gopkg.in/check.v1"
14
15         "git.arvados.org/arvados.git/sdk/go/arvadosclient"
16         "git.arvados.org/arvados.git/sdk/go/arvadostest"
17 )
18
19 func (s *ServerRequiredSuite) TestOverrideDiscovery(c *check.C) {
20         defer os.Setenv("ARVADOS_KEEP_SERVICES", "")
21
22         data := []byte("TestOverrideDiscovery")
23         hash := fmt.Sprintf("%x+%d", md5.Sum(data), len(data))
24         st := StubGetHandler{
25                 c,
26                 hash,
27                 arvadostest.ActiveToken,
28                 http.StatusOK,
29                 data}
30         ks := RunSomeFakeKeepServers(st, 2)
31
32         os.Setenv("ARVADOS_KEEP_SERVICES", "")
33         arv1, err := arvadosclient.MakeArvadosClient()
34         c.Assert(err, check.IsNil)
35         arv1.ApiToken = arvadostest.ActiveToken
36
37         os.Setenv("ARVADOS_KEEP_SERVICES", ks[0].url+"  "+ks[1].url+" ")
38         arv2, err := arvadosclient.MakeArvadosClient()
39         c.Assert(err, check.IsNil)
40         arv2.ApiToken = arvadostest.ActiveToken
41
42         // ARVADOS_KEEP_SERVICES was empty when we created arv1, but
43         // it pointed to our stub servers when we created
44         // arv2. Regardless of what it's set to now, a keepclient for
45         // arv2 should use our stub servers, but one created for arv1
46         // should not.
47
48         kc1, err := MakeKeepClient(arv1)
49         c.Assert(err, check.IsNil)
50         kc2, err := MakeKeepClient(arv2)
51         c.Assert(err, check.IsNil)
52
53         _, _, _, err = kc1.Get(hash)
54         c.Check(err, check.NotNil)
55         _, _, _, err = kc2.Get(hash)
56         c.Check(err, check.IsNil)
57 }