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