Skip to content

Commit

Permalink
Modified TestCode
Browse files Browse the repository at this point in the history
  • Loading branch information
haiqingchq committed Nov 22, 2024
1 parent 2ae83dd commit da14758
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions internal/apps/dop/dicehub/release/release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,12 +578,14 @@ version: "2.0"
func TestReleaseServiceGC(t *testing.T) {
testCase := []struct {
name string
dbDir string
dbPath string
dbEngine string
releases []db.Release
}{
{
name: "baseTest",
dbDir: "./testdata",
dbPath: "./testdata/test.db",
dbEngine: "sqlite3",
releases: []db.Release{
Expand Down Expand Up @@ -620,11 +622,13 @@ func TestReleaseServiceGC(t *testing.T) {
}
for _, tt := range testCase {
t.Run(tt.name, func(t *testing.T) {
if _, err := os.Stat(tt.dbDir); os.IsNotExist(err) {
err = os.Mkdir(tt.dbDir, 0755)
assert.NoError(t, err)
}
if _, err := os.Stat(tt.dbPath); os.IsNotExist(err) {
_, err = os.Create(tt.dbPath)
if err != nil {
t.Fatal(err)
}
assert.NoError(t, err)
}
dbClient, err := gorm.Open("sqlite3", "./testdata/test.db")
if err != nil {
Expand All @@ -647,10 +651,9 @@ func TestReleaseServiceGC(t *testing.T) {
err = rs.RemoveDeprecatedsReleases(now)
assert.NoError(t, err)
dbClient.Exec("delete from dice_release")
err = os.Remove(tt.dbPath)
if err != nil {
t.Fatal(err)
}
// delete db dir
err = os.RemoveAll(tt.dbDir)
assert.NoError(t, err)
})
}
}

0 comments on commit da14758

Please sign in to comment.