CWL spec -> CWL standards
[arvados.git] / lib / controller / federation / federation_test.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package federation
6
7 import (
8         "context"
9         "net/url"
10         "os"
11         "testing"
12
13         "git.arvados.org/arvados.git/lib/controller/router"
14         "git.arvados.org/arvados.git/lib/controller/rpc"
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/auth"
18         "git.arvados.org/arvados.git/sdk/go/ctxlog"
19         "git.arvados.org/arvados.git/sdk/go/httpserver"
20         check "gopkg.in/check.v1"
21 )
22
23 // Gocheck boilerplate
24 func Test(t *testing.T) {
25         check.TestingT(t)
26 }
27
28 // FederationSuite does some generic setup/teardown. Don't add Test*
29 // methods to FederationSuite itself.
30 type FederationSuite struct {
31         cluster *arvados.Cluster
32         ctx     context.Context
33         fed     *Conn
34 }
35
36 func (s *FederationSuite) SetUpTest(c *check.C) {
37         s.cluster = &arvados.Cluster{
38                 ClusterID:       "aaaaa",
39                 SystemRootToken: arvadostest.SystemRootToken,
40                 RemoteClusters: map[string]arvados.RemoteCluster{
41                         "aaaaa": arvados.RemoteCluster{
42                                 Host: os.Getenv("ARVADOS_API_HOST"),
43                         },
44                 },
45         }
46         arvadostest.SetServiceURL(&s.cluster.Services.RailsAPI, "https://"+os.Getenv("ARVADOS_TEST_API_HOST"))
47         s.cluster.TLS.Insecure = true
48         s.cluster.API.MaxItemsPerResponse = 3
49
50         ctx := context.Background()
51         ctx = ctxlog.Context(ctx, ctxlog.TestLogger(c))
52         ctx = auth.NewContext(ctx, &auth.Credentials{Tokens: []string{arvadostest.ActiveTokenV2}})
53         s.ctx = ctx
54
55         s.fed = New(s.cluster)
56 }
57
58 func (s *FederationSuite) addDirectRemote(c *check.C, id string, backend backend) {
59         s.cluster.RemoteClusters[id] = arvados.RemoteCluster{
60                 Host: "in-process.local",
61         }
62         s.fed.remotes[id] = backend
63 }
64
65 func (s *FederationSuite) addHTTPRemote(c *check.C, id string, backend backend) {
66         srv := httpserver.Server{Addr: ":"}
67         srv.Handler = router.New(backend)
68         c.Check(srv.Start(), check.IsNil)
69         s.cluster.RemoteClusters[id] = arvados.RemoteCluster{
70                 Scheme: "http",
71                 Host:   srv.Addr,
72                 Proxy:  true,
73         }
74         s.fed.remotes[id] = rpc.NewConn(id, &url.URL{Scheme: "http", Host: srv.Addr}, true, saltedTokenProvider(s.fed.local, id))
75 }