Skip to content

Commit 6058f51

Browse files
authored
Merge pull request #3 from sap-contributions/feature/alioss-linting-fix
Linting Fix
2 parents f2cfffe + 20335a1 commit 6058f51

File tree

5 files changed

+36
-32
lines changed

5 files changed

+36
-32
lines changed

.github/workflows/unit-test.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ jobs:
1616
uses: actions/setup-go@v6
1717
with:
1818
go-version-file: go.mod
19-
# TODO: Re-enable linting after fixing existing issues on alioss
20-
# - name: Lint code
21-
# uses: golangci/golangci-lint-action@v8
19+
- name: Lint code
20+
uses: golangci/golangci-lint-action@v8
2221
- name: Cache Go modules
2322
uses: actions/cache@v4
2423
with:

alioss/client/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (client *AliBlobstore) getMD5(filePath string) (string, error) {
6363
return "", err
6464
}
6565

66-
defer file.Close()
66+
defer file.Close() //nolint:errcheck
6767

6868
hash := md5.New()
6969
_, err = io.Copy(hash, file)

alioss/client/client_test.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ var _ = Describe("Client", func() {
1919
aliBlobstore, err := client.New(&storageClient)
2020
Expect(err).ToNot(HaveOccurred())
2121

22-
tmpFile, err := os.CreateTemp("", "azure-storage-cli-test")
22+
tmpFile, _ := os.CreateTemp("", "azure-storage-cli-test") //nolint:errcheck
2323

24-
aliBlobstore.Put(tmpFile.Name(), "destination_object")
24+
aliBlobstore.Put(tmpFile.Name(), "destination_object") //nolint:errcheck
2525

2626
Expect(storageClient.UploadCallCount()).To(Equal(1))
2727
sourceFilePath, sourceFileMD5, destination := storageClient.UploadArgsForCall(0)
@@ -39,7 +39,7 @@ var _ = Describe("Client", func() {
3939
aliBlobstore, err := client.New(&storageClient)
4040
Expect(err).ToNot(HaveOccurred())
4141

42-
aliBlobstore.Get("source_object", "destination/file/path")
42+
aliBlobstore.Get("source_object", "destination/file/path") //nolint:errcheck
4343

4444
Expect(storageClient.DownloadCallCount()).To(Equal(1))
4545
sourceObject, destinationFilePath := storageClient.DownloadArgsForCall(0)
@@ -56,7 +56,7 @@ var _ = Describe("Client", func() {
5656
aliBlobstore, err := client.New(&storageClient)
5757
Expect(err).ToNot(HaveOccurred())
5858

59-
aliBlobstore.Delete("blob")
59+
aliBlobstore.Delete("blob") //nolint:errcheck
6060

6161
Expect(storageClient.DeleteCallCount()).To(Equal(1))
6262
object := storageClient.DeleteArgsForCall(0)
@@ -70,7 +70,8 @@ var _ = Describe("Client", func() {
7070
storageClient := clientfakes.FakeStorageClient{}
7171
storageClient.ExistsReturns(true, nil)
7272

73-
aliBlobstore, _ := client.New(&storageClient)
73+
aliBlobstore, err := client.New(&storageClient)
74+
Expect(err).NotTo(HaveOccurred())
7475
existsState, err := aliBlobstore.Exists("blob")
7576
Expect(existsState == true).To(BeTrue())
7677
Expect(err).ToNot(HaveOccurred())
@@ -83,7 +84,8 @@ var _ = Describe("Client", func() {
8384
storageClient := clientfakes.FakeStorageClient{}
8485
storageClient.ExistsReturns(false, nil)
8586

86-
aliBlobstore, _ := client.New(&storageClient)
87+
aliBlobstore, err := client.New(&storageClient)
88+
Expect(err).NotTo(HaveOccurred())
8789
existsState, err := aliBlobstore.Exists("blob")
8890
Expect(existsState == false).To(BeTrue())
8991
Expect(err).ToNot(HaveOccurred())
@@ -96,7 +98,8 @@ var _ = Describe("Client", func() {
9698
storageClient := clientfakes.FakeStorageClient{}
9799
storageClient.ExistsReturns(false, errors.New("boom"))
98100

99-
aliBlobstore, _ := client.New(&storageClient)
101+
aliBlobstore, err := client.New(&storageClient)
102+
Expect(err).NotTo(HaveOccurred())
100103
existsState, err := aliBlobstore.Exists("blob")
101104
Expect(existsState == false).To(BeTrue())
102105
Expect(err).To(HaveOccurred())
@@ -111,7 +114,8 @@ var _ = Describe("Client", func() {
111114
storageClient := clientfakes.FakeStorageClient{}
112115
storageClient.SignedUrlGetReturns("https://the-signed-url", nil)
113116

114-
aliBlobstore, _ := client.New(&storageClient)
117+
aliBlobstore, err := client.New(&storageClient)
118+
Expect(err).NotTo(HaveOccurred())
115119
url, err := aliBlobstore.Sign("blob", "get", 100)
116120
Expect(url == "https://the-signed-url").To(BeTrue())
117121
Expect(err).ToNot(HaveOccurred())
@@ -125,7 +129,8 @@ var _ = Describe("Client", func() {
125129
storageClient := clientfakes.FakeStorageClient{}
126130
storageClient.SignedUrlPutReturns("https://the-signed-url", nil)
127131

128-
aliBlobstore, _ := client.New(&storageClient)
132+
aliBlobstore, err := client.New(&storageClient)
133+
Expect(err).NotTo(HaveOccurred())
129134
url, err := aliBlobstore.Sign("blob", "put", 100)
130135
Expect(url == "https://the-signed-url").To(BeTrue())
131136
Expect(err).ToNot(HaveOccurred())
@@ -139,7 +144,8 @@ var _ = Describe("Client", func() {
139144
storageClient := clientfakes.FakeStorageClient{}
140145
storageClient.SignedUrlGetReturns("", errors.New("boom"))
141146

142-
aliBlobstore, _ := client.New(&storageClient)
147+
aliBlobstore, err := client.New(&storageClient)
148+
Expect(err).NotTo(HaveOccurred())
143149
url, err := aliBlobstore.Sign("blob", "unknown", 100)
144150
Expect(url).To(Equal(""))
145151
Expect(err).To(HaveOccurred())

alioss/client/storage_client.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package client
22

33
import (
4-
"fmt"
54
"log"
65

76
"github.com/aliyun/aliyun-oss-go-sdk/oss"
@@ -53,7 +52,7 @@ func (dsc DefaultStorageClient) Upload(
5352
sourceFileMD5 string,
5453
destinationObject string,
5554
) error {
56-
log.Println(fmt.Sprintf("Uploading %s/%s", dsc.storageConfig.BucketName, destinationObject))
55+
log.Printf("Uploading %s/%s\n", dsc.storageConfig.BucketName, destinationObject)
5756

5857
client, err := oss.New(dsc.storageConfig.Endpoint, dsc.storageConfig.AccessKeyID, dsc.storageConfig.AccessKeySecret)
5958
if err != nil {
@@ -72,7 +71,7 @@ func (dsc DefaultStorageClient) Download(
7271
sourceObject string,
7372
destinationFilePath string,
7473
) error {
75-
log.Println(fmt.Sprintf("Downloading %s/%s", dsc.storageConfig.BucketName, sourceObject))
74+
log.Printf("Downloading %s/%s\n", dsc.storageConfig.BucketName, sourceObject)
7675

7776
client, err := oss.New(dsc.storageConfig.Endpoint, dsc.storageConfig.AccessKeyID, dsc.storageConfig.AccessKeySecret)
7877
if err != nil {
@@ -90,7 +89,7 @@ func (dsc DefaultStorageClient) Download(
9089
func (dsc DefaultStorageClient) Delete(
9190
object string,
9291
) error {
93-
log.Println(fmt.Sprintf("Deleting %s/%s", dsc.storageConfig.BucketName, object))
92+
log.Printf("Deleting %s/%s\n", dsc.storageConfig.BucketName, object)
9493

9594
client, err := oss.New(dsc.storageConfig.Endpoint, dsc.storageConfig.AccessKeyID, dsc.storageConfig.AccessKeySecret)
9695
if err != nil {
@@ -106,7 +105,7 @@ func (dsc DefaultStorageClient) Delete(
106105
}
107106

108107
func (dsc DefaultStorageClient) Exists(object string) (bool, error) {
109-
log.Println(fmt.Sprintf("Checking if blob: %s/%s", dsc.storageConfig.BucketName, object))
108+
log.Printf("Checking if blob: %s/%s\n", dsc.storageConfig.BucketName, object)
110109

111110
client, err := oss.New(dsc.storageConfig.Endpoint, dsc.storageConfig.AccessKeyID, dsc.storageConfig.AccessKeySecret)
112111
if err != nil {
@@ -137,7 +136,7 @@ func (dsc DefaultStorageClient) SignedUrlPut(
137136
expiredInSec int64,
138137
) (string, error) {
139138

140-
log.Println(fmt.Sprintf("Getting signed PUT url for blob %s/%s", dsc.storageConfig.BucketName, object))
139+
log.Printf("Getting signed PUT url for blob %s/%s\n", dsc.storageConfig.BucketName, object)
141140

142141
client, err := oss.New(dsc.storageConfig.Endpoint, dsc.storageConfig.AccessKeyID, dsc.storageConfig.AccessKeySecret)
143142
if err != nil {
@@ -157,7 +156,7 @@ func (dsc DefaultStorageClient) SignedUrlGet(
157156
expiredInSec int64,
158157
) (string, error) {
159158

160-
log.Println(fmt.Sprintf("Getting signed GET url for blob %s/%s", dsc.storageConfig.BucketName, object))
159+
log.Printf("Getting signed GET url for blob %s/%s\n", dsc.storageConfig.BucketName, object)
161160

162161
client, err := oss.New(dsc.storageConfig.Endpoint, dsc.storageConfig.AccessKeyID, dsc.storageConfig.AccessKeySecret)
163162
if err != nil {

alioss/integration/general_ali_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package integration_test
22

33
import (
44
"bytes"
5-
"io/ioutil"
5+
66
"os"
77

88
"github.com/cloudfoundry/storage-cli/alioss/config"
@@ -25,8 +25,8 @@ var _ = Describe("General testing for all Ali regions", func() {
2525
})
2626

2727
AfterEach(func() {
28-
defer func() { _ = os.Remove(configPath) }()
29-
defer func() { _ = os.Remove(contentFile) }()
28+
defer func() { _ = os.Remove(configPath) }() //nolint:errcheck
29+
defer func() { _ = os.Remove(contentFile) }() //nolint:errcheck
3030
})
3131

3232
Describe("Invoking `put`", func() {
@@ -55,9 +55,9 @@ var _ = Describe("General testing for all Ali regions", func() {
5555
Expect(cliSession.ExitCode()).To(BeZero())
5656
}()
5757

58-
tmpLocalFile, _ := os.CreateTemp("", "ali-storage-cli-download")
59-
tmpLocalFile.Close()
60-
defer func() { _ = os.Remove(tmpLocalFile.Name()) }()
58+
tmpLocalFile, _ := os.CreateTemp("", "ali-storage-cli-download") //nolint:errcheck
59+
tmpLocalFile.Close() //nolint:errcheck
60+
defer func() { _ = os.Remove(tmpLocalFile.Name()) }() //nolint:errcheck
6161

6262
contentFile = integration.MakeContentFile("initial content")
6363
cliSession, err := integration.RunCli(cliPath, configPath, "put", contentFile, blobName)
@@ -68,7 +68,7 @@ var _ = Describe("General testing for all Ali regions", func() {
6868
Expect(err).ToNot(HaveOccurred())
6969
Expect(cliSession.ExitCode()).To(BeZero())
7070

71-
gottenBytes, _ := os.ReadFile(tmpLocalFile.Name())
71+
gottenBytes, _ := os.ReadFile(tmpLocalFile.Name()) //nolint:errcheck
7272
Expect(string(gottenBytes)).To(Equal("initial content"))
7373

7474
contentFile = integration.MakeContentFile("updated content")
@@ -80,7 +80,7 @@ var _ = Describe("General testing for all Ali regions", func() {
8080
Expect(err).ToNot(HaveOccurred())
8181
Expect(cliSession.ExitCode()).To(BeZero())
8282

83-
gottenBytes, _ = os.ReadFile(tmpLocalFile.Name())
83+
gottenBytes, _ = os.ReadFile(tmpLocalFile.Name()) //nolint:errcheck
8484
Expect(string(gottenBytes)).To(Equal("updated content"))
8585
})
8686

@@ -112,7 +112,7 @@ var _ = Describe("General testing for all Ali regions", func() {
112112
Expect(err).ToNot(HaveOccurred())
113113
Expect(cliSession.ExitCode()).To(BeZero())
114114

115-
_ = os.Remove(outputFilePath)
115+
_ = os.Remove(outputFilePath) //nolint:errcheck
116116
}()
117117

118118
cliSession, err := integration.RunCli(cliPath, configPath, "put", contentFile, blobName)
@@ -123,7 +123,7 @@ var _ = Describe("General testing for all Ali regions", func() {
123123
Expect(err).ToNot(HaveOccurred())
124124
Expect(cliSession.ExitCode()).To(BeZero())
125125

126-
fileContent, _ := ioutil.ReadFile(outputFilePath)
126+
fileContent, _ := os.ReadFile(outputFilePath) //nolint:errcheck
127127
Expect(string(fileContent)).To(Equal("foo"))
128128
})
129129
})
@@ -200,7 +200,7 @@ var _ = Describe("General testing for all Ali regions", func() {
200200
Describe("Invoking `-v`", func() {
201201
It("returns the cli version", func() {
202202
configPath := integration.MakeConfigFile(&defaultConfig)
203-
defer func() { _ = os.Remove(configPath) }()
203+
defer func() { _ = os.Remove(configPath) }() //nolint:errcheck
204204

205205
cliSession, err := integration.RunCli(cliPath, configPath, "-v")
206206
Expect(err).ToNot(HaveOccurred())

0 commit comments

Comments
 (0)