15295: Fix test
[arvados.git] / lib / controller / server_test.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package controller
6
7 import (
8         "net/http"
9         "os"
10         "path/filepath"
11
12         "git.curoverse.com/arvados.git/sdk/go/arvados"
13         "git.curoverse.com/arvados.git/sdk/go/arvadostest"
14         "git.curoverse.com/arvados.git/sdk/go/ctxlog"
15         "git.curoverse.com/arvados.git/sdk/go/httpserver"
16         check "gopkg.in/check.v1"
17 )
18
19 func integrationTestCluster() *arvados.Cluster {
20         cfg, err := arvados.GetConfig(filepath.Join(os.Getenv("WORKSPACE"), "tmp", "arvados.yml"))
21         if err != nil {
22                 panic(err)
23         }
24         cc, err := cfg.GetCluster("zzzzz")
25         if err != nil {
26                 panic(err)
27         }
28         return cc
29 }
30
31 // Return a new unstarted controller server, using the Rails API
32 // provided by the integration-testing environment.
33 func newServerFromIntegrationTestEnv(c *check.C) *httpserver.Server {
34         log := ctxlog.TestLogger(c)
35
36         handler := &Handler{Cluster: &arvados.Cluster{
37                 ClusterID:  "zzzzz",
38                 PostgreSQL: integrationTestCluster().PostgreSQL,
39                 TLS:        arvados.TLS{Insecure: true},
40         }}
41         arvadostest.SetServiceURL(&handler.Cluster.Services.RailsAPI, "https://"+os.Getenv("ARVADOS_TEST_API_HOST"))
42         arvadostest.SetServiceURL(&handler.Cluster.Services.Controller, "http://localhost:/")
43
44         srv := &httpserver.Server{
45                 Server: http.Server{
46                         Handler: httpserver.AddRequestIDs(httpserver.LogRequests(log, handler)),
47                 },
48                 Addr: ":",
49         }
50         return srv
51 }