simplified the Expect assertions for true/false and check existing files
diff --git a/api_helper_test.go b/api_helper_test.go index 2ccc9f5..7b83679 100644 --- a/api_helper_test.go +++ b/api_helper_test.go
@@ -21,7 +21,7 @@ raw := getRaw(record) valid, e := validate(raw) - Expect(valid).To(Equal(false)) + Expect(valid).To(BeFalse()) Expect(e.ErrorCode).To(Equal("MISSING_FIELD")) By("payload with clst > clet") @@ -34,7 +34,7 @@ raw = getRaw(record) valid, e = validate(raw) - Expect(valid).To(Equal(false)) + Expect(valid).To(BeFalse()) Expect(e.ErrorCode).To(Equal("BAD_DATA")) Expect(e.Reason).To(Equal("client_received_start_timestamp > client_received_end_timestamp")) @@ -50,7 +50,7 @@ }`) raw := getRaw(record) valid, _ := validate(raw) - Expect(valid).To(Equal(true)) + Expect(valid).To(BeTrue()) }) }) })
diff --git a/buffering_manager_test.go b/buffering_manager_test.go index 1789317..5378604 100644 --- a/buffering_manager_test.go +++ b/buffering_manager_test.go
@@ -122,23 +122,10 @@ time.Sleep(time.Second * 2) expectedDirPath := filepath.Join(localAnalyticsStagingDir, dirName) - status, _ := exists(expectedDirPath) - Expect(status).To(BeTrue()) + Expect(expectedDirPath).To(BeADirectory()) expectedfilePath := filepath.Join(localAnalyticsStagingDir, dirName, fileName) - status, _ = exists(expectedfilePath) - Expect(status).To(BeTrue()) + Expect(expectedfilePath).To(BeAnExistingFile()) }) }) }) - -func exists(path string) (bool, error) { - _, err := os.Stat(path) - if err == nil { - return true, nil - } - if os.IsNotExist(err) { - return false, nil - } - return true, err -}
diff --git a/listener_test.go b/listener_test.go index 279b4f7..ee211ee 100644 --- a/listener_test.go +++ b/listener_test.go
@@ -144,7 +144,7 @@ handler.Handle(&delete) _, exists := tenantCache["i2"] - Expect(exists).To(Equal(false)) + Expect(exists).To(BeFalse()) }) }) })
diff --git a/upload_manager_test.go b/upload_manager_test.go index e0033e9..d8a9089 100644 --- a/upload_manager_test.go +++ b/upload_manager_test.go
@@ -22,8 +22,8 @@ Expect(e).ShouldNot(HaveOccurred()) handleUploadDirStatus(info, true) - status, _ := exists(dirPath) - Expect(status).To(BeFalse()) + Expect(dirPath).ToNot(BeADirectory()) + _, exists := retriesMap[dirName] Expect(exists).To(BeFalse()) }) @@ -43,8 +43,7 @@ for i := 1; i < maxRetries; i++ { handleUploadDirStatus(info, false) - status, _ := exists(dirPath) - Expect(status).To(BeTrue()) + Expect(dirPath).To(BeAnExistingFile()) cnt, exists := retriesMap[dirName] Expect(exists).To(BeTrue()) @@ -55,9 +54,7 @@ handleUploadDirStatus(info, false) failedPath := filepath.Join(localAnalyticsFailedDir, dirName) - - status, _ := exists(failedPath) - Expect(status).To(BeTrue()) + Expect(failedPath).To(BeADirectory()) _, exists := retriesMap[dirName] Expect(exists).To(BeFalse()) @@ -79,11 +76,8 @@ stagingPath := filepath.Join(localAnalyticsStagingDir, dirName) // move from failed to staging directory - status, _ := exists(dirPath) - Expect(status).To(BeFalse()) - - status, _ = exists(stagingPath) - Expect(status).To(BeTrue()) + Expect(dirPath).ToNot(BeADirectory()) + Expect(stagingPath).To(BeADirectory()) }) It("if multiple folders, then move only configured batch at a time", func() { for i := 1; i < (retryFailedDirBatchSize * 2); i++ {
diff --git a/uploader_test.go b/uploader_test.go index b4a6d84..e9af4a1 100644 --- a/uploader_test.go +++ b/uploader_test.go
@@ -44,9 +44,7 @@ status := uploadDir(dir) Expect(status).To(BeTrue()) - - e, _ := exists(fp) - Expect(e).To(BeFalse()) + Expect(fp).ToNot(BeAnExistingFile()) }) }) Context("invalid tenant", func() { @@ -60,9 +58,7 @@ status := uploadDir(dir) Expect(status).To(BeFalse()) - - e, _ := exists(fp) - Expect(e).To(BeTrue()) + Expect(fp).To(BeAnExistingFile()) }) }) }) @@ -86,7 +82,6 @@ url, err := getSignedUrl(tenant, relativeFilePath) Expect(err).ShouldNot(HaveOccurred()) Expect(url).ShouldNot(Equal("")) - log.Debugf(url) }) }) })