15954: Add comments.
[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         "context"
9         "net/http"
10         "os"
11         "path/filepath"
12
13         "git.arvados.org/arvados.git/sdk/go/arvados"
14         "git.arvados.org/arvados.git/sdk/go/arvadostest"
15         "git.arvados.org/arvados.git/sdk/go/ctxlog"
16         "git.arvados.org/arvados.git/sdk/go/httpserver"
17         check "gopkg.in/check.v1"
18 )
19
20 func integrationTestCluster() *arvados.Cluster {
21         cfg, err := arvados.GetConfig(filepath.Join(os.Getenv("WORKSPACE"), "tmp", "arvados.yml"))
22         if err != nil {
23                 panic(err)
24         }
25         cc, err := cfg.GetCluster("zzzzz")
26         if err != nil {
27                 panic(err)
28         }
29         return cc
30 }
31
32 // Return a new unstarted controller server, using the Rails API
33 // provided by the integration-testing environment.
34 func newServerFromIntegrationTestEnv(c *check.C) *httpserver.Server {
35         log := ctxlog.TestLogger(c)
36
37         handler := &Handler{Cluster: &arvados.Cluster{
38                 ClusterID:        "zzzzz",
39                 PostgreSQL:       integrationTestCluster().PostgreSQL,
40                 ForceLegacyAPI14: forceLegacyAPI14,
41         }}
42         handler.Cluster.TLS.Insecure = true
43         arvadostest.SetServiceURL(&handler.Cluster.Services.RailsAPI, "https://"+os.Getenv("ARVADOS_TEST_API_HOST"))
44         arvadostest.SetServiceURL(&handler.Cluster.Services.Controller, "http://localhost:/")
45
46         srv := &httpserver.Server{
47                 Server: http.Server{
48                         Handler: httpserver.HandlerWithContext(
49                                 ctxlog.Context(context.Background(), log),
50                                 httpserver.AddRequestIDs(httpserver.LogRequests(handler))),
51                 },
52                 Addr: ":",
53         }
54         return srv
55 }