Skip to content

Commit b04acc4

Browse files
committed
fix: linting errors are fixed
1 parent 006eaa9 commit b04acc4

2 files changed

Lines changed: 28 additions & 39 deletions

File tree

storage/strategy.go

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import (
77
"time"
88
)
99

10-
type NotExistsError struct {
11-
err error
12-
}
10+
type NotExistsError struct{}
1311

1412
func (e *NotExistsError) Error() string {
1513
return "object does not exist"
@@ -32,7 +30,7 @@ func (sty *Strategy) ExecuteCommand(cmd string, nonFlagArgs []string) error {
3230
switch cmd {
3331
case "put":
3432
if len(nonFlagArgs) != 3 {
35-
return fmt.Errorf("Put method expected 3 arguments got %d\n", len(nonFlagArgs))
33+
return fmt.Errorf("put method expected 3 arguments got %d", len(nonFlagArgs))
3634
}
3735
sourceFilePath, dst := nonFlagArgs[1], nonFlagArgs[2]
3836

@@ -44,29 +42,29 @@ func (sty *Strategy) ExecuteCommand(cmd string, nonFlagArgs []string) error {
4442

4543
case "get":
4644
if len(nonFlagArgs) != 3 {
47-
return fmt.Errorf("Get method expected 3 arguments got %d\n", len(nonFlagArgs))
45+
return fmt.Errorf("get method expected 3 arguments got %d", len(nonFlagArgs))
4846
}
4947
src, dst := nonFlagArgs[1], nonFlagArgs[2]
5048
return sty.str.Get(src, dst)
5149

5250
case "copy":
5351
if len(nonFlagArgs) != 3 {
54-
return fmt.Errorf("Copy method expected 3 arguments got %d\n", len(nonFlagArgs))
52+
return fmt.Errorf("copy method expected 3 arguments got %d", len(nonFlagArgs))
5553
}
5654

5755
srcBlob, dstBlob := nonFlagArgs[1], nonFlagArgs[2]
5856
return sty.str.Copy(srcBlob, dstBlob)
5957

6058
case "delete":
6159
if len(nonFlagArgs) != 2 {
62-
return fmt.Errorf("Delete method expected 2 arguments got %d\n", len(nonFlagArgs))
60+
return fmt.Errorf("delete method expected 2 arguments got %d", len(nonFlagArgs))
6361
}
6462
return sty.str.Delete(nonFlagArgs[1])
6563

6664
case "delete-recursive":
6765
var prefix string
6866
if len(nonFlagArgs) > 2 {
69-
return fmt.Errorf("delete-recursive takes at most one argument (prefix) got %d\n", len(nonFlagArgs)-1)
67+
return fmt.Errorf("delete-recursive takes at most one argument (prefix) got %d", len(nonFlagArgs)-1)
7068
} else if len(nonFlagArgs) == 2 {
7169
prefix = nonFlagArgs[1]
7270
} else {
@@ -76,36 +74,36 @@ func (sty *Strategy) ExecuteCommand(cmd string, nonFlagArgs []string) error {
7674

7775
case "exists":
7876
if len(nonFlagArgs) != 2 {
79-
return fmt.Errorf("Exists method expected 2 arguments got %d\n", len(nonFlagArgs))
77+
return fmt.Errorf("exists method expected 2 arguments got %d", len(nonFlagArgs))
8078
}
8179

8280
exists, err := sty.str.Exists(nonFlagArgs[1])
8381
if err == nil && !exists {
8482
return &NotExistsError{}
8583
}
8684
if err != nil {
87-
return fmt.Errorf("Failed to check exist: %w", err)
85+
return fmt.Errorf("failed to check exist: %w", err)
8886
}
8987

9088
case "sign":
9189
if len(nonFlagArgs) != 4 {
92-
return fmt.Errorf("Sign method expects 3 arguments got %d\n", len(nonFlagArgs)-1)
90+
return fmt.Errorf("sign method expects 3 arguments got %d", len(nonFlagArgs)-1)
9391
}
9492

9593
objectID, action := nonFlagArgs[1], nonFlagArgs[2]
9694
action = strings.ToLower(action)
9795
if action != "get" && action != "put" {
98-
return fmt.Errorf("Action not implemented: %s. Available actions are 'get' and 'put'", action)
96+
return fmt.Errorf("action not implemented: %s. Available actions are 'get' and 'put'", action)
9997
}
10098

10199
expiration, err := time.ParseDuration(nonFlagArgs[3])
102100
if err != nil {
103-
return fmt.Errorf("Expiration should be in the format of a duration i.e. 1h, 60m, 3600s. Got: %s", nonFlagArgs[3])
101+
return fmt.Errorf("expiration should be in the format of a duration i.e. 1h, 60m, 3600s. Got: %s", nonFlagArgs[3])
104102
}
105103

106104
signedURL, err := sty.str.Sign(objectID, action, expiration)
107105
if err != nil {
108-
return fmt.Errorf("Failed to sign request: %w", err)
106+
return fmt.Errorf("failed to sign request: %w", err)
109107
}
110108
fmt.Print(signedURL)
111109

@@ -117,13 +115,13 @@ func (sty *Strategy) ExecuteCommand(cmd string, nonFlagArgs []string) error {
117115
} else if len(nonFlagArgs) == 2 {
118116
prefix = nonFlagArgs[1]
119117
} else {
120-
return fmt.Errorf("List method expected 1 or 2 arguments, got %d\n", len(nonFlagArgs)-1)
118+
return fmt.Errorf("list method expected 1 or 2 arguments, got %d", len(nonFlagArgs)-1)
121119
}
122120

123121
var objects []string
124122
objects, err := sty.str.List(prefix)
125123
if err != nil {
126-
return fmt.Errorf("Failed to list objects: %w", err)
124+
return fmt.Errorf("failed to list objects: %w", err)
127125
}
128126

129127
for _, object := range objects {
@@ -132,18 +130,18 @@ func (sty *Strategy) ExecuteCommand(cmd string, nonFlagArgs []string) error {
132130

133131
case "properties":
134132
if len(nonFlagArgs) != 2 {
135-
return fmt.Errorf("Properties method expected 2 arguments got %d\n", len(nonFlagArgs))
133+
return fmt.Errorf("properties method expected 2 arguments got %d", len(nonFlagArgs))
136134
}
137135
return sty.str.Properties(nonFlagArgs[1])
138136

139137
case "ensure-storage-exists":
140138
if len(nonFlagArgs) != 1 {
141-
return fmt.Errorf("EnsureStorageExists method expected 1 arguments got %d\n", len(nonFlagArgs))
139+
return fmt.Errorf("ensureStorageExists method expected 1 arguments got %d", len(nonFlagArgs))
142140
}
143141
return sty.str.EnsureStorageExists()
144142

145143
default:
146-
return fmt.Errorf("unknown command: '%s'\n", cmd)
144+
return fmt.Errorf("unknown command: '%s'", cmd)
147145
}
148146

149147
return nil

storage/strategy_test.go

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@ var _ = Describe("Execute Command", func() {
2121
})
2222

2323
Context("Put", func() {
24-
// BeforeEach(func() {
25-
// tempFile, _ = os.CreateTemp("", sourceFileName) //nolint:errcheck
26-
// tempFile.Close() //nolint:errcheck
27-
// })
28-
29-
// AfterEach(func() {
30-
// os.Remove(tempFile.Name()) //nolint:errcheck
31-
// })
32-
3324
It("Successfull", func() {
3425
tempFile, _ = os.CreateTemp("", sourceFileName) //nolint:errcheck
3526
tempFile.Close() //nolint:errcheck
@@ -49,7 +40,7 @@ var _ = Describe("Execute Command", func() {
4940

5041
It("Wrong number of parameters", func() {
5142
err := strategy.ExecuteCommand("put", []string{"put", "source"})
52-
Expect(err.Error()).To(ContainSubstring("Put method expected 3 arguments got"))
43+
Expect(err.Error()).To(ContainSubstring("put method expected 3 arguments got"))
5344
})
5445

5546
})
@@ -64,7 +55,7 @@ var _ = Describe("Execute Command", func() {
6455

6556
It("Wrong number of parameters", func() {
6657
err := strategy.ExecuteCommand("get", []string{"get", "source"})
67-
Expect(err.Error()).To(ContainSubstring("Get method expected 3 arguments got"))
58+
Expect(err.Error()).To(ContainSubstring("get method expected 3 arguments got"))
6859
})
6960

7061
})
@@ -79,7 +70,7 @@ var _ = Describe("Execute Command", func() {
7970

8071
It("Wrong number of parameters", func() {
8172
err := strategy.ExecuteCommand("copy", []string{"copy", "source"})
82-
Expect(err.Error()).To(ContainSubstring("Copy method expected 3 arguments got"))
73+
Expect(err.Error()).To(ContainSubstring("copy method expected 3 arguments got"))
8374
})
8475

8576
})
@@ -94,7 +85,7 @@ var _ = Describe("Execute Command", func() {
9485

9586
It("Wrong number of parameters", func() {
9687
err := strategy.ExecuteCommand("delete", []string{"delete"})
97-
Expect(err.Error()).To(ContainSubstring("Delete method expected 2 arguments got"))
88+
Expect(err.Error()).To(ContainSubstring("delete method expected 2 arguments got"))
9889
})
9990

10091
})
@@ -163,19 +154,19 @@ var _ = Describe("Execute Command", func() {
163154

164155
It("Wrong action", func() {
165156
err := strategy.ExecuteCommand("sign", []string{"sign", "object", "delete", "10s"})
166-
Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("Action not implemented: %s. Available actions are 'get' and 'put'", "delete")))
157+
Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("action not implemented: %s. Available actions are 'get' and 'put'", "delete")))
167158

168159
})
169160

170161
It("Wrong time format", func() {
171162
err := strategy.ExecuteCommand("sign", []string{"sign", "object", "put", "10"})
172-
Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("Expiration should be in the format of a duration i.e. 1h, 60m, 3600s. Got: %s", "10")))
163+
Expect(err.Error()).To(ContainSubstring(fmt.Sprintf("expiration should be in the format of a duration i.e. 1h, 60m, 3600s. Got: %s", "10")))
173164

174165
})
175166

176167
It("Wrong number of parameters", func() {
177168
err := strategy.ExecuteCommand("sign", []string{"sign", "object", "put"})
178-
Expect(err.Error()).To(ContainSubstring("Sign method expects 3 arguments got"))
169+
Expect(err.Error()).To(ContainSubstring("sign method expects 3 arguments got"))
179170

180171
})
181172

@@ -200,7 +191,7 @@ var _ = Describe("Execute Command", func() {
200191

201192
It("Wrong number of parameters", func() {
202193
err := strategy.ExecuteCommand("list", []string{})
203-
Expect(err.Error()).To(ContainSubstring("List method expected 1 or 2 arguments, got"))
194+
Expect(err.Error()).To(ContainSubstring("list method expected 1 or 2 arguments, got"))
204195
})
205196

206197
})
@@ -215,7 +206,7 @@ var _ = Describe("Execute Command", func() {
215206

216207
It("Wrong number of parameters", func() {
217208
err := strategy.ExecuteCommand("properties", []string{"properties"})
218-
Expect(err.Error()).To(ContainSubstring("Properties method expected 2 arguments got"))
209+
Expect(err.Error()).To(ContainSubstring("properties method expected 2 arguments got"))
219210
})
220211

221212
})
@@ -230,15 +221,15 @@ var _ = Describe("Execute Command", func() {
230221

231222
It("Wrong number of parameters", func() {
232223
err := strategy.ExecuteCommand("ensure-storage-exists", []string{"ensure-storage-exists", "extra-parameter"})
233-
Expect(err.Error()).To(ContainSubstring("EnsureStorageExists method expected 1 arguments got"))
224+
Expect(err.Error()).To(ContainSubstring("ensureStorageExists method expected 1 arguments got"))
234225
})
235226

236227
})
237228

238229
Context("Unsupported command", func() {
239230
It("Successfull", func() {
240231
err := strategy.ExecuteCommand("unsupported-command", []string{"unsupported-command"})
241-
Expect(err.Error()).To(ContainSubstring("unknown command: '%s'\n", "unsupported-command"))
232+
Expect(err.Error()).To(ContainSubstring("unknown command: '%s'", "unsupported-command"))
242233

243234
})
244235

0 commit comments

Comments
 (0)