13493: Merge branch 'master' into 13493-federation-proxy
[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
11         "git.curoverse.com/arvados.git/sdk/go/arvados"
12         "git.curoverse.com/arvados.git/sdk/go/httpserver"
13         "github.com/Sirupsen/logrus"
14         check "gopkg.in/check.v1"
15 )
16
17 // logWriter is an io.Writer that writes by calling a "write log"
18 // function, typically (*check.C)Log().
19 type logWriter struct {
20         logfunc func(...interface{})
21 }
22
23 func (tl *logWriter) Write(buf []byte) (int, error) {
24         tl.logfunc(string(buf))
25         return len(buf), nil
26 }
27
28 // Return a new unstarted controller server, using the Rails API
29 // provided by the integration-testing environment.
30 func newServerFromIntegrationTestEnv(c *check.C) *httpserver.Server {
31         log := logrus.New()
32         log.Formatter = &logrus.JSONFormatter{}
33         log.Out = &logWriter{c.Log}
34
35         nodeProfile := arvados.NodeProfile{
36                 Controller: arvados.SystemServiceInstance{Listen: ":"},
37                 RailsAPI:   arvados.SystemServiceInstance{Listen: os.Getenv("ARVADOS_TEST_API_HOST"), TLS: true, Insecure: true},
38         }
39         handler := &Handler{Cluster: &arvados.Cluster{
40                 ClusterID: "zzzzz",
41                 NodeProfiles: map[string]arvados.NodeProfile{
42                         "*": nodeProfile,
43                 },
44         }, NodeProfile: &nodeProfile}
45
46         srv := &httpserver.Server{
47                 Server: http.Server{
48                         Handler: httpserver.AddRequestIDs(httpserver.LogRequests(log, handler)),
49                 },
50                 Addr: nodeProfile.Controller.Listen,
51         }
52         return srv
53 }