1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
11 "git.arvados.org/arvados.git/lib/config"
12 "git.arvados.org/arvados.git/lib/controller/rpc"
13 "git.arvados.org/arvados.git/lib/ctrlctx"
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 "github.com/jmoiron/sqlx"
18 check "gopkg.in/check.v1"
21 type localdbSuite struct {
23 cancel context.CancelFunc
24 cluster *arvados.Cluster
26 dbConnector *ctrlctx.DBConnector
29 userctx context.Context // uses ActiveUser token
31 railsSpy *arvadostest.Proxy
34 func (s *localdbSuite) SetUpSuite(c *check.C) {
35 arvadostest.StartKeep(2, true)
38 func (s *localdbSuite) TearDownSuite(c *check.C) {
39 // Undo any changes/additions to the user database so they
40 // don't affect subsequent tests.
41 arvadostest.ResetEnv()
42 c.Check(arvados.NewClientFromEnv().RequestAndDecode(nil, "POST", "database/reset", nil, nil), check.IsNil)
45 func (s *localdbSuite) SetUpTest(c *check.C) {
47 logger := ctxlog.TestLogger(c)
48 s.ctx, s.cancel = context.WithCancel(context.Background())
49 s.ctx = ctxlog.Context(s.ctx, logger)
50 cfg, err := config.NewLoader(nil, logger).Load()
51 c.Assert(err, check.IsNil)
52 s.cluster, err = cfg.GetCluster("")
53 c.Assert(err, check.IsNil)
54 s.dbConnector = &ctrlctx.DBConnector{PostgreSQL: s.cluster.PostgreSQL}
55 s.db, err = s.dbConnector.GetDB(s.ctx)
56 c.Assert(err, check.IsNil)
57 s.ctx, s.txFinish = ctrlctx.New(s.ctx, s.dbConnector.GetDB)
58 s.tx, err = ctrlctx.CurrentTx(s.ctx)
59 c.Assert(err, check.IsNil)
60 s.localdb = NewConn(s.ctx, s.cluster, s.dbConnector.GetDB)
61 s.railsSpy = arvadostest.NewProxy(c, s.cluster.Services.RailsAPI)
62 *s.localdb.railsProxy = *rpc.NewConn(s.cluster.ClusterID, s.railsSpy.URL, true, rpc.PassthroughTokenProvider)
63 s.userctx = ctrlctx.NewWithToken(s.ctx, s.cluster, arvadostest.ActiveTokenV2)
66 var errRollbackAfterTest = errors.New("rollback after test")
68 func (s *localdbSuite) TearDownTest(c *check.C) {
72 if s.txFinish != nil {
73 s.txFinish(&errRollbackAfterTest)
75 if s.railsSpy != nil {
78 if s.dbConnector != nil {
84 func (s *localdbSuite) setUpVocabulary(c *check.C, testVocabulary string) {
85 if testVocabulary == "" {
91 "labels": [{"label": "Importance"}, {"label": "Priority"}],
93 "IDVALIMPORTANCES1": { "labels": [{"label": "Critical"}, {"label": "Urgent"}, {"label": "High"}] },
94 "IDVALIMPORTANCES2": { "labels": [{"label": "Normal"}, {"label": "Moderate"}] },
95 "IDVALIMPORTANCES3": { "labels": [{"label": "Low"}] }
101 voc, err := arvados.NewVocabulary([]byte(testVocabulary), []string{})
102 c.Assert(err, check.IsNil)
103 s.localdb.vocabularyCache = voc
104 s.cluster.API.VocabularyPath = "foo"