1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
14 "git.curoverse.com/arvados.git/sdk/go/arvados"
15 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
16 check "gopkg.in/check.v1"
19 var _ = check.Suite(&serverSuite{})
21 type serverSuite struct {
27 func (s *serverSuite) SetUpTest(c *check.C) {
28 s.cfg = s.testConfig()
29 s.srv = &server{wsConfig: s.cfg}
32 func (*serverSuite) testConfig() *wsConfig {
33 cfg := defaultConfig()
34 cfg.Client = *(arvados.NewClientFromEnv())
35 cfg.Postgres = testDBConfig()
37 cfg.ManagementToken = arvadostest.ManagementToken
41 // TestBadDB ensures Run() returns an error (instead of panicking or
42 // deadlocking) if it can't connect to the database server at startup.
43 func (s *serverSuite) TestBadDB(c *check.C) {
44 s.cfg.Postgres["password"] = "1234"
50 c.Check(err, check.NotNil)
59 done := make(chan bool)
66 case <-time.After(10 * time.Second):
71 func (s *serverSuite) TestHealth(c *check.C) {
75 for _, token := range []string{"", "foo", s.cfg.ManagementToken} {
76 req, err := http.NewRequest("GET", "http://"+s.srv.listener.Addr().String()+"/_health/ping", nil)
77 c.Assert(err, check.IsNil)
79 req.Header.Add("Authorization", "Bearer "+token)
81 resp, err := http.DefaultClient.Do(req)
82 c.Check(err, check.IsNil)
83 if token == s.cfg.ManagementToken {
84 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
85 buf, err := ioutil.ReadAll(resp.Body)
86 c.Check(err, check.IsNil)
87 c.Check(string(buf), check.Equals, `{"health":"OK"}`+"\n")
89 c.Check(resp.StatusCode, check.Not(check.Equals), http.StatusOK)
94 func (s *serverSuite) TestStatus(c *check.C) {
98 req, err := http.NewRequest("GET", "http://"+s.srv.listener.Addr().String()+"/status.json", nil)
99 c.Assert(err, check.IsNil)
100 resp, err := http.DefaultClient.Do(req)
101 c.Check(err, check.IsNil)
102 c.Check(resp.StatusCode, check.Equals, http.StatusOK)
103 var status map[string]interface{}
104 err = json.NewDecoder(resp.Body).Decode(&status)
105 c.Check(err, check.IsNil)
106 c.Check(status["Version"], check.Not(check.Equals), "")
109 func (s *serverSuite) TestHealthDisabled(c *check.C) {
110 s.cfg.ManagementToken = ""
116 for _, token := range []string{"", "foo", arvadostest.ManagementToken} {
117 req, err := http.NewRequest("GET", "http://"+s.srv.listener.Addr().String()+"/_health/ping", nil)
118 c.Assert(err, check.IsNil)
119 req.Header.Add("Authorization", "Bearer "+token)
120 resp, err := http.DefaultClient.Do(req)
121 c.Check(err, check.IsNil)
122 c.Check(resp.StatusCode, check.Equals, http.StatusNotFound)