From b4dd3ec9b3a60ad094e05674859f343b6eca5beb Mon Sep 17 00:00:00 2001 From: "mac.chenhaiqing" <2538302280@qq.com> Date: Fri, 22 Nov 2024 11:41:59 +0800 Subject: [PATCH] Modified TestCode --- .../apps/dop/dicehub/release/release_test.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/internal/apps/dop/dicehub/release/release_test.go b/internal/apps/dop/dicehub/release/release_test.go index cbf7d258d1c..f5738ba07f7 100644 --- a/internal/apps/dop/dicehub/release/release_test.go +++ b/internal/apps/dop/dicehub/release/release_test.go @@ -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{ @@ -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 { @@ -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) }) } }