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