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) TearDownSuite(c *check.C) {
35 // Undo any changes/additions to the user database so they
36 // don't affect subsequent tests.
37 arvadostest.ResetEnv()
38 c.Check(arvados.NewClientFromEnv().RequestAndDecode(nil, "POST", "database/reset", nil, nil), check.IsNil)
41 func (s *localdbSuite) SetUpTest(c *check.C) {
43 s.ctx, s.cancel = context.WithCancel(context.Background())
44 cfg, err := config.NewLoader(nil, ctxlog.TestLogger(c)).Load()
45 c.Assert(err, check.IsNil)
46 s.cluster, err = cfg.GetCluster("")
47 c.Assert(err, check.IsNil)
48 s.dbConnector = &ctrlctx.DBConnector{PostgreSQL: s.cluster.PostgreSQL}
49 s.db, err = s.dbConnector.GetDB(s.ctx)
50 c.Assert(err, check.IsNil)
51 s.ctx, s.txFinish = ctrlctx.New(s.ctx, s.dbConnector.GetDB)
52 s.tx, err = ctrlctx.CurrentTx(s.ctx)
53 c.Assert(err, check.IsNil)
54 s.localdb = NewConn(s.ctx, s.cluster, s.dbConnector.GetDB)
55 s.railsSpy = arvadostest.NewProxy(c, s.cluster.Services.RailsAPI)
56 *s.localdb.railsProxy = *rpc.NewConn(s.cluster.ClusterID, s.railsSpy.URL, true, rpc.PassthroughTokenProvider)
57 s.userctx = ctrlctx.NewWithToken(s.ctx, s.cluster, arvadostest.ActiveTokenV2)
60 var errRollbackAfterTest = errors.New("rollback after test")
62 func (s *localdbSuite) TearDownTest(c *check.C) {
66 if s.txFinish != nil {
67 s.txFinish(&errRollbackAfterTest)
69 if s.railsSpy != nil {
72 if s.dbConnector != nil {
78 func (s *localdbSuite) setUpVocabulary(c *check.C, testVocabulary string) {
79 if testVocabulary == "" {
85 "labels": [{"label": "Importance"}, {"label": "Priority"}],
87 "IDVALIMPORTANCES1": { "labels": [{"label": "Critical"}, {"label": "Urgent"}, {"label": "High"}] },
88 "IDVALIMPORTANCES2": { "labels": [{"label": "Normal"}, {"label": "Moderate"}] },
89 "IDVALIMPORTANCES3": { "labels": [{"label": "Low"}] }
95 voc, err := arvados.NewVocabulary([]byte(testVocabulary), []string{})
96 c.Assert(err, check.IsNil)
97 s.localdb.vocabularyCache = voc
98 s.cluster.API.VocabularyPath = "foo"