Merge branch '16723-kill-vs-requeue'
[arvados.git] / services / keep-web / status_test.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package main
6
7 import (
8         "encoding/json"
9         "net/http"
10         "net/http/httptest"
11         "net/url"
12
13         "git.arvados.org/arvados.git/sdk/go/arvadostest"
14         "gopkg.in/check.v1"
15 )
16
17 func (s *UnitSuite) TestStatus(c *check.C) {
18         h := handler{Config: newConfig(s.Config)}
19         u, _ := url.Parse("http://keep-web.example/status.json")
20         req := &http.Request{
21                 Method:     "GET",
22                 Host:       u.Host,
23                 URL:        u,
24                 RequestURI: u.RequestURI(),
25         }
26         resp := httptest.NewRecorder()
27         h.ServeHTTP(resp, req)
28         c.Check(resp.Code, check.Equals, http.StatusOK)
29
30         var status map[string]interface{}
31         err := json.NewDecoder(resp.Body).Decode(&status)
32         c.Check(err, check.IsNil)
33         c.Check(status["Version"], check.Not(check.Equals), "")
34 }
35
36 func (s *IntegrationSuite) TestNoStatusFromVHost(c *check.C) {
37         u, _ := url.Parse("http://" + arvadostest.FooCollection + "--keep-web.example/status.json")
38         req := &http.Request{
39                 Method:     "GET",
40                 Host:       u.Host,
41                 URL:        u,
42                 RequestURI: u.RequestURI(),
43                 Header: http.Header{
44                         "Authorization": {"OAuth2 " + arvadostest.ActiveToken},
45                 },
46         }
47         resp := httptest.NewRecorder()
48         s.testServer.Handler.ServeHTTP(resp, req)
49         c.Check(resp.Code, check.Equals, http.StatusNotFound)
50 }