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