diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 942081d..1c2ccea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,7 @@ jobs: run: make fmtcheck - name: Linter - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v8 build: name: test diff --git a/.golangci.yml b/.golangci.yml index 46111a6..20101ee 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,8 +1,6 @@ +version: "2" run: timeout: 5m -linters: +formatters: enable: - goimports - - revive - - ineffassign - - errcheck diff --git a/Makefile b/Makefile index 2237bce..b2432e6 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ clean: if [ -f "${NAME}" ] ; then rm ${NAME} ; fi lint: - docker run --rm -v $(PWD):/app -w /app golangci/golangci-lint:v1.59.1 golangci-lint run -v + docker run --rm -v $(PWD):/app -w /app golangci/golangci-lint:v2.1.6 golangci-lint run -v fmtcheck: tools.goimports @echo "--> checking code formatting with 'goimports' tool" diff --git a/backend/s3backend.go b/backend/s3backend.go index 90b60c8..7bf517c 100644 --- a/backend/s3backend.go +++ b/backend/s3backend.go @@ -40,7 +40,7 @@ func newS3Backend(config []S3BackendConfig) (*S3Backend, error) { var s3BackendConfig S3BackendConfig if len((config)) > 1 { - return nil, errors.New("One config max. allowed") + return nil, errors.New("one config max. allowed") } else if len(config) == 1 { s3BackendConfig = config[0] s3Config = &aws.Config{ diff --git a/s3proxytest/s3proxytest.go b/s3proxytest/s3proxytest.go index 2f1e16c..1314a59 100644 --- a/s3proxytest/s3proxytest.go +++ b/s3proxytest/s3proxytest.go @@ -322,7 +322,11 @@ func httpCall(t *testing.T, httpMethod string, url string, contentType string, a var bytes []byte if response != nil { - defer response.Body.Close() + defer func() { + if err := response.Body.Close(); err != nil { + t.Errorf("failed to close response body while calling %s", url) + } + }() statusCode = response.StatusCode @@ -535,10 +539,18 @@ func checkCopy(t *testing.T, s3proxyHost string, sourceBucket string, sourceKey require.Empty(t, message) sourceFile := checkUpload(t, s3proxyHost, sourceBucket+sourceKey, "") - defer os.Remove(sourceFile.Name()) + defer func() { + if err := os.Remove(sourceFile.Name()); err != nil { + log.Errorf("failed to remove source file %s: %v", sourceFile.Name(), err) + } + }() destinationFile := checkDownload(t, s3proxyHost, destBucket+destKey, http.StatusOK, "") - defer os.Remove(destinationFile.Name()) + defer func() { + if err := os.Remove(destinationFile.Name()); err != nil { + log.Errorf("failed to remove destination file %s: %v", destinationFile.Name(), err) + } + }() // Verify the files are the same require.True(t, verifyFileCheckSumEquality(t, sourceFile, destinationFile)) @@ -563,7 +575,11 @@ func checkBatchDelete(t *testing.T, s3proxyHost string, bucket string, keys []st // Last check, try to download again the file // should return 404 because the file has been deleted file := checkDownload(t, s3proxyHost, bucket+key, http.StatusNotFound, "") - defer os.Remove(file.Name()) + defer func() { + if err := os.Remove(file.Name()); err != nil { + log.Errorf("failed to remove downloaded file %s: %v", file.Name(), err) + } + }() } } @@ -583,22 +599,38 @@ func RunSimpleScenarioForS3proxy(t *testing.T, s3proxyHost string) { // UPLOAD a temporary file to the s3 backend uploadedFile := checkUpload(t, s3proxyHost, fullKey, "") - defer os.Remove(uploadedFile.Name()) + defer func() { + if err := os.Remove(uploadedFile.Name()); err != nil { + log.Errorf("failed to remove uploaded file %s: %v", uploadedFile.Name(), err) + } + }() // DOWNLOAD the file previously uploaded downloadedFile := checkDownload(t, s3proxyHost, fullKey, http.StatusOK, "") - defer os.Remove(downloadedFile.Name()) + defer func() { + if err := os.Remove(downloadedFile.Name()); err != nil { + log.Errorf("failed to remove downloaded file %s: %v", downloadedFile.Name(), err) + } + }() // Verify the files are the same require.True(t, verifyFileCheckSumEquality(t, uploadedFile, downloadedFile)) // UPLOAD a temporary file to the s3 backend with expiration getUploadFileWithExpiration := checkUpload(t, s3proxyHost, fullKey, "25m") - defer os.Remove(getUploadFileWithExpiration.Name()) + defer func() { + if err := os.Remove(getUploadFileWithExpiration.Name()); err != nil { + log.Errorf("failed to remove uploaded file with expiration %s: %v", getUploadFileWithExpiration.Name(), err) + } + }() // DOWNLOAD the file previously uploaded with expiration getDownloadFileWithExpiration := checkDownload(t, s3proxyHost, fullKey, http.StatusOK, "25m") - defer os.Remove(getDownloadFileWithExpiration.Name()) + defer func() { + if err := os.Remove(getDownloadFileWithExpiration.Name()); err != nil { + log.Errorf("failed to remove downloaded file with expiration %s: %v", getDownloadFileWithExpiration.Name(), err) + } + }() // Verify the expiration param is taken into account require.True(t, verifyFileCheckSumEquality(t, getUploadFileWithExpiration, getDownloadFileWithExpiration)) @@ -607,7 +639,11 @@ func RunSimpleScenarioForS3proxy(t *testing.T, s3proxyHost string) { checkCopy(t, s3proxyHost, bucket, key, bucket, key+"2") copiedFile := checkDownload(t, s3proxyHost, fullKey+"2", http.StatusOK, "") - defer os.Remove(copiedFile.Name()) + defer func() { + if err := os.Remove(copiedFile.Name()); err != nil { + log.Errorf("failed to remove copied file %s: %v", copiedFile.Name(), err) + } + }() // DELETE object checkDelete(t, s3proxyHost, fullKey+"2")