Skip to content

Commit 458b273

Browse files
authored
Merge pull request #71 from mirakl/upgrade-to-golangci-lint-v2
chore(SOFA-599): upgrade to golangci-lint v2
2 parents 532307c + 1935491 commit 458b273

File tree

5 files changed

+50
-16
lines changed

5 files changed

+50
-16
lines changed

‎.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
run: make fmtcheck
2727

2828
- name: Linter
29-
uses: golangci/golangci-lint-action@v6
29+
uses: golangci/golangci-lint-action@v8
3030

3131
build:
3232
name: test

‎.golangci.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1+
version: "2"
12
run:
23
timeout: 5m
3-
linters:
4+
formatters:
45
enable:
56
- goimports
6-
- revive
7-
- ineffassign
8-
- errcheck

‎Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ clean:
1717
if [ -f "${NAME}" ] ; then rm ${NAME} ; fi
1818

1919
lint:
20-
docker run --rm -v $(PWD):/app -w /app golangci/golangci-lint:v1.59.1 golangci-lint run -v
20+
docker run --rm -v $(PWD):/app -w /app golangci/golangci-lint:v2.1.6 golangci-lint run -v
2121

2222
fmtcheck: tools.goimports
2323
@echo "--> checking code formatting with 'goimports' tool"

‎backend/s3backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func newS3Backend(config []S3BackendConfig) (*S3Backend, error) {
4040
var s3BackendConfig S3BackendConfig
4141

4242
if len((config)) > 1 {
43-
return nil, errors.New("One config max. allowed")
43+
return nil, errors.New("one config max. allowed")
4444
} else if len(config) == 1 {
4545
s3BackendConfig = config[0]
4646
s3Config = &aws.Config{

‎s3proxytest/s3proxytest.go

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,11 @@ func httpCall(t *testing.T, httpMethod string, url string, contentType string, a
322322
var bytes []byte
323323

324324
if response != nil {
325-
defer response.Body.Close()
325+
defer func() {
326+
if err := response.Body.Close(); err != nil {
327+
t.Errorf("failed to close response body while calling %s", url)
328+
}
329+
}()
326330

327331
statusCode = response.StatusCode
328332

@@ -535,10 +539,18 @@ func checkCopy(t *testing.T, s3proxyHost string, sourceBucket string, sourceKey
535539
require.Empty(t, message)
536540

537541
sourceFile := checkUpload(t, s3proxyHost, sourceBucket+sourceKey, "")
538-
defer os.Remove(sourceFile.Name())
542+
defer func() {
543+
if err := os.Remove(sourceFile.Name()); err != nil {
544+
log.Errorf("failed to remove source file %s: %v", sourceFile.Name(), err)
545+
}
546+
}()
539547

540548
destinationFile := checkDownload(t, s3proxyHost, destBucket+destKey, http.StatusOK, "")
541-
defer os.Remove(destinationFile.Name())
549+
defer func() {
550+
if err := os.Remove(destinationFile.Name()); err != nil {
551+
log.Errorf("failed to remove destination file %s: %v", destinationFile.Name(), err)
552+
}
553+
}()
542554

543555
// Verify the files are the same
544556
require.True(t, verifyFileCheckSumEquality(t, sourceFile, destinationFile))
@@ -563,7 +575,11 @@ func checkBatchDelete(t *testing.T, s3proxyHost string, bucket string, keys []st
563575
// Last check, try to download again the file
564576
// should return 404 because the file has been deleted
565577
file := checkDownload(t, s3proxyHost, bucket+key, http.StatusNotFound, "")
566-
defer os.Remove(file.Name())
578+
defer func() {
579+
if err := os.Remove(file.Name()); err != nil {
580+
log.Errorf("failed to remove downloaded file %s: %v", file.Name(), err)
581+
}
582+
}()
567583
}
568584
}
569585

@@ -583,22 +599,38 @@ func RunSimpleScenarioForS3proxy(t *testing.T, s3proxyHost string) {
583599

584600
// UPLOAD a temporary file to the s3 backend
585601
uploadedFile := checkUpload(t, s3proxyHost, fullKey, "")
586-
defer os.Remove(uploadedFile.Name())
602+
defer func() {
603+
if err := os.Remove(uploadedFile.Name()); err != nil {
604+
log.Errorf("failed to remove uploaded file %s: %v", uploadedFile.Name(), err)
605+
}
606+
}()
587607

588608
// DOWNLOAD the file previously uploaded
589609
downloadedFile := checkDownload(t, s3proxyHost, fullKey, http.StatusOK, "")
590-
defer os.Remove(downloadedFile.Name())
610+
defer func() {
611+
if err := os.Remove(downloadedFile.Name()); err != nil {
612+
log.Errorf("failed to remove downloaded file %s: %v", downloadedFile.Name(), err)
613+
}
614+
}()
591615

592616
// Verify the files are the same
593617
require.True(t, verifyFileCheckSumEquality(t, uploadedFile, downloadedFile))
594618

595619
// UPLOAD a temporary file to the s3 backend with expiration
596620
getUploadFileWithExpiration := checkUpload(t, s3proxyHost, fullKey, "25m")
597-
defer os.Remove(getUploadFileWithExpiration.Name())
621+
defer func() {
622+
if err := os.Remove(getUploadFileWithExpiration.Name()); err != nil {
623+
log.Errorf("failed to remove uploaded file with expiration %s: %v", getUploadFileWithExpiration.Name(), err)
624+
}
625+
}()
598626

599627
// DOWNLOAD the file previously uploaded with expiration
600628
getDownloadFileWithExpiration := checkDownload(t, s3proxyHost, fullKey, http.StatusOK, "25m")
601-
defer os.Remove(getDownloadFileWithExpiration.Name())
629+
defer func() {
630+
if err := os.Remove(getDownloadFileWithExpiration.Name()); err != nil {
631+
log.Errorf("failed to remove downloaded file with expiration %s: %v", getDownloadFileWithExpiration.Name(), err)
632+
}
633+
}()
602634

603635
// Verify the expiration param is taken into account
604636
require.True(t, verifyFileCheckSumEquality(t, getUploadFileWithExpiration, getDownloadFileWithExpiration))
@@ -607,7 +639,11 @@ func RunSimpleScenarioForS3proxy(t *testing.T, s3proxyHost string) {
607639
checkCopy(t, s3proxyHost, bucket, key, bucket, key+"2")
608640

609641
copiedFile := checkDownload(t, s3proxyHost, fullKey+"2", http.StatusOK, "")
610-
defer os.Remove(copiedFile.Name())
642+
defer func() {
643+
if err := os.Remove(copiedFile.Name()); err != nil {
644+
log.Errorf("failed to remove copied file %s: %v", copiedFile.Name(), err)
645+
}
646+
}()
611647

612648
// DELETE object
613649
checkDelete(t, s3proxyHost, fullKey+"2")

0 commit comments

Comments
 (0)