diff --git a/pkg/metricscollector/v1beta1/file-metricscollector/file-metricscollector_test.go b/pkg/metricscollector/v1beta1/file-metricscollector/file-metricscollector_test.go index 0a0fa09bc9d..c286bce6224 100644 --- a/pkg/metricscollector/v1beta1/file-metricscollector/file-metricscollector_test.go +++ b/pkg/metricscollector/v1beta1/file-metricscollector/file-metricscollector_test.go @@ -42,8 +42,9 @@ const ( ) var ( - testJsonDataPath = filepath.Join("testdata", "JSON") - testTextDataPath = filepath.Join("testdata", "TEXT") + testDir = "testdata" + testJsonDataPath = filepath.Join(testDir, "JSON") + testTextDataPath = filepath.Join(testDir, "TEXT") ) func TestCollectObservationLog(t *testing.T) { @@ -56,7 +57,7 @@ func TestCollectObservationLog(t *testing.T) { if err := generateTEXTTestFiles(); err != nil { t.Fatal(err) } - defer deleteTestDirs() + defer os.RemoveAll(testDir) testCases := map[string]struct { filePath string @@ -337,18 +338,6 @@ func generateTestDirs() error { return nil } -func deleteTestDirs() error { - if err := os.RemoveAll(filepath.Dir(testJsonDataPath)); err != nil { - return err - } - - if err := os.RemoveAll(filepath.Dir(testTextDataPath)); err != nil { - return err - } - - return nil -} - func generateJSONTestFiles() error { testData := []struct { fileName string