github.com/decred/politeia@v1.4.0/politeiad/backendv2/tstorebe/tstore/testing.go (about) 1 // Copyright (c) 2020-2021 The Decred developers 2 // Use of this source code is governed by an ISC 3 // license that can be found in the LICENSE file. 4 5 package tstore 6 7 import ( 8 "os" 9 "testing" 10 11 "github.com/decred/politeia/politeiad/backendv2/tstorebe/store/localdb" 12 "github.com/decred/politeia/politeiad/backendv2/tstorebe/tlog" 13 ) 14 15 // NewTestTstore returns a tstore instance that is setup for testing. 16 func NewTestTstore(t *testing.T, dataDir string) *Tstore { 17 t.Helper() 18 19 // Setup datadir for this tstore instance 20 dataDir, err := os.MkdirTemp(dataDir, "tstore.test") 21 if err != nil { 22 t.Fatal(err) 23 } 24 25 // Setup key-value store 26 fp, err := os.MkdirTemp(dataDir, "kv") 27 if err != nil { 28 t.Fatal(err) 29 } 30 store, err := localdb.New(dataDir, fp) 31 if err != nil { 32 t.Fatal(err) 33 } 34 35 return &Tstore{ 36 tlog: tlog.NewTestClient(t), 37 store: store, 38 } 39 }