Cleanup duplicate code
This commit is contained in:
parent
777c41e411
commit
8c910d904f
4 changed files with 49 additions and 50 deletions
|
|
@ -17,44 +17,21 @@ package sql
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"garm/config"
|
||||
dbCommon "garm/database/common"
|
||||
runnerErrors "garm/errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"garm/util"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
var (
|
||||
encryptionPassphrase = "bocyasicgatEtenOubwonIbsudNutDom"
|
||||
)
|
||||
|
||||
func getTestSqliteDBConfig(t *testing.T) config.Database {
|
||||
dir, err := os.MkdirTemp("", "garm-config-test")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create temporary directory: %s", err)
|
||||
}
|
||||
t.Cleanup(func() { os.RemoveAll(dir) })
|
||||
|
||||
return config.Database{
|
||||
Debug: false,
|
||||
DbBackend: config.SQLiteBackend,
|
||||
Passphrase: encryptionPassphrase,
|
||||
SQLite: config.SQLite{
|
||||
DBFile: filepath.Join(dir, "garm.db"),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type CtrlTestSuite struct {
|
||||
suite.Suite
|
||||
Store dbCommon.Store
|
||||
}
|
||||
|
||||
func (s *CtrlTestSuite) SetupTest() {
|
||||
db, err := NewSQLDatabase(context.Background(), getTestSqliteDBConfig(s.T()))
|
||||
db, err := NewSQLDatabase(context.Background(), util.GetTestSqliteDBConfig(s.T()))
|
||||
if err != nil {
|
||||
s.FailNow(fmt.Sprintf("failed to create db connection: %s", err))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue