Skip to content

Commit 3176283

Browse files
committed
Fix artifact db unit test setup
The unit tests which asserts artifact db initialization failures will result in errors was failing likely for previous good initialization of the database. Signed-off-by: Austin Vazquez <[email protected]>
1 parent 926f17e commit 3176283

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

soci/artifacts_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package soci
1818

1919
import (
2020
"os"
21+
"sync"
2122
"testing"
2223

2324
bolt "go.etcd.io/bbolt"
@@ -98,6 +99,12 @@ func TestGetIndexArtifactEntries(t *testing.T) {
9899
}
99100

100101
func TestArtifactDB_DoesNotExist(t *testing.T) {
102+
resetArtifactDBInit()
103+
t.Cleanup(resetArtifactDBInit)
104+
once.Do(func() {
105+
// Fail db initialization.
106+
db = nil
107+
})
101108
_, err := NewDB(ArtifactsDbPath())
102109
if err == nil {
103110
t.Fatalf("getArtifactEntry should fail since artifacts.db doesn't exist")
@@ -208,3 +215,8 @@ func newTestableDb() (*ArtifactsDb, error) {
208215
}
209216
return &ArtifactsDb{db: db}, nil
210217
}
218+
219+
func resetArtifactDBInit() {
220+
once = sync.Once{}
221+
db = nil
222+
}

0 commit comments

Comments
 (0)