1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
13 "git.curoverse.com/arvados.git/sdk/go/arvados"
14 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
15 check "gopkg.in/check.v1"
18 var _ = check.Suite(&serverSuite{})
20 type serverSuite struct {
26 func (s *serverSuite) SetUpTest(c *check.C) {
27 s.cfg = s.testConfig()
28 s.srv = &server{wsConfig: s.cfg}
31 func (*serverSuite) testConfig() *wsConfig {
32 cfg := defaultConfig()
33 cfg.Client = *(arvados.NewClientFromEnv())
34 cfg.Postgres = testDBConfig()
36 cfg.ManagementToken = arvadostest.ManagementToken
40 // TestBadDB ensures Run() returns an error (instead of panicking or
41 // deadlocking) if it can't connect to the database server at startup.
42 func (s *serverSuite) TestBadDB(c *check.C) {
43 s.cfg.Postgres["password"] = "1234"
49 c.Check(err, check.NotNil)
58 done := make(chan bool)
65 case <-time.After(10 * time.Second):
70 func (s *serverSuite) TestHealth(c *check.C) {
74 for _, token := range []string{"", "foo", s.cfg.ManagementToken} {
75 req, err := http.NewRequest("GET", "http://"+s.srv.listener.Addr().String()+"/_health/ping", nil)
76 c.Assert(err, check.IsNil)
78 req.Header.Add("Authorization", "Bearer "+token)
80 resp, err := http.DefaultClient.Do(req)
81 c.Check(err, check.IsNil)
82 if token == s.cfg.ManagementToken {
83 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
84 buf, err := ioutil.ReadAll(resp.Body)
85 c.Check(err, check.IsNil)
86 c.Check(string(buf), check.Equals, `{"health":"OK"}`+"\n")
88 c.Check(resp.StatusCode, check.Not(check.Equals), http.StatusOK)
93 func (s *serverSuite) TestHealthDisabled(c *check.C) {
94 s.cfg.ManagementToken = ""
100 for _, token := range []string{"", "foo", arvadostest.ManagementToken} {
101 req, err := http.NewRequest("GET", "http://"+s.srv.listener.Addr().String()+"/_health/ping", nil)
102 c.Assert(err, check.IsNil)
103 req.Header.Add("Authorization", "Bearer "+token)
104 resp, err := http.DefaultClient.Do(req)
105 c.Check(err, check.IsNil)
106 c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)