1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
13 "git.arvados.org/arvados.git/lib/config"
14 "git.arvados.org/arvados.git/lib/controller/router"
15 "git.arvados.org/arvados.git/lib/controller/rpc"
16 "git.arvados.org/arvados.git/lib/ctrlctx"
17 "git.arvados.org/arvados.git/sdk/go/arvados"
18 "git.arvados.org/arvados.git/sdk/go/arvadostest"
19 "git.arvados.org/arvados.git/sdk/go/auth"
20 "git.arvados.org/arvados.git/sdk/go/ctxlog"
21 "git.arvados.org/arvados.git/sdk/go/httpserver"
22 "github.com/jmoiron/sqlx"
23 check "gopkg.in/check.v1"
26 // Gocheck boilerplate
27 func Test(t *testing.T) {
31 // FederationSuite does some generic setup/teardown. Don't add Test*
32 // methods to FederationSuite itself.
33 type FederationSuite struct {
34 integrationTestCluster *arvados.Cluster
35 cluster *arvados.Cluster
41 func (s *FederationSuite) SetUpSuite(c *check.C) {
42 cfg, err := config.NewLoader(nil, ctxlog.TestLogger(c)).Load()
43 c.Assert(err, check.IsNil)
44 s.integrationTestCluster, err = cfg.GetCluster("")
45 c.Assert(err, check.IsNil)
48 func (s *FederationSuite) SetUpTest(c *check.C) {
49 s.cluster = &arvados.Cluster{
51 SystemRootToken: arvadostest.SystemRootToken,
52 RemoteClusters: map[string]arvados.RemoteCluster{
54 Host: os.Getenv("ARVADOS_API_HOST"),
57 PostgreSQL: s.integrationTestCluster.PostgreSQL,
59 arvadostest.SetServiceURL(&s.cluster.Services.RailsAPI, "https://"+os.Getenv("ARVADOS_TEST_API_HOST"))
60 s.cluster.TLS.Insecure = true
61 s.cluster.API.MaxItemsPerResponse = 3
63 tx, err := arvadostest.DB(c, s.cluster).Beginx()
64 c.Assert(err, check.IsNil)
67 ctx := context.Background()
68 ctx = ctxlog.Context(ctx, ctxlog.TestLogger(c))
69 ctx = auth.NewContext(ctx, &auth.Credentials{Tokens: []string{arvadostest.ActiveTokenV2}})
70 ctx = ctrlctx.NewWithTransaction(ctx, s.tx)
73 s.fed = New(ctx, s.cluster, nil, (&ctrlctx.DBConnector{PostgreSQL: s.cluster.PostgreSQL}).GetDB)
76 func (s *FederationSuite) TearDownTest(c *check.C) {
80 func (s *FederationSuite) addDirectRemote(c *check.C, id string, backend backend) {
81 s.cluster.RemoteClusters[id] = arvados.RemoteCluster{
82 Host: "in-process.local",
84 s.fed.remotes[id] = backend
87 func (s *FederationSuite) addHTTPRemote(c *check.C, id string, backend backend) {
88 srv := httpserver.Server{Addr: ":"}
89 srv.Handler = router.New(backend, router.Config{})
90 c.Check(srv.Start(), check.IsNil)
91 s.cluster.RemoteClusters[id] = arvados.RemoteCluster{
96 s.fed.remotes[id] = rpc.NewConn(id, &url.URL{Scheme: "http", Host: srv.Addr}, true, saltedTokenProvider(s.cluster, s.fed.local, id))