17944: Vocabulary check errors return status 400 instead of 500.
[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
39         handler := &Handler{Cluster: &arvados.Cluster{
40                 ClusterID:  "zzzzz",
41                 PostgreSQL: integrationTestCluster().PostgreSQL,
42         }}
43         handler.Cluster.TLS.Insecure = true
44         handler.Cluster.Collections.BlobSigning = true
45         handler.Cluster.Collections.BlobSigningKey = arvadostest.BlobSigningKey
46         handler.Cluster.Collections.BlobSigningTTL = arvados.Duration(time.Hour * 24 * 14)
47         arvadostest.SetServiceURL(&handler.Cluster.Services.RailsAPI, "https://"+os.Getenv("ARVADOS_TEST_API_HOST"))
48         arvadostest.SetServiceURL(&handler.Cluster.Services.Controller, "http://localhost:/")
49
50         srv := &httpserver.Server{
51                 Server: http.Server{
52                         BaseContext: func(net.Listener) context.Context {
53                                 return ctxlog.Context(context.Background(), log)
54                         },
55                         Handler: httpserver.AddRequestIDs(httpserver.LogRequests(handler)),
56                 },
57                 Addr: ":",
58         }
59         return srv
60 }