Skip to content

Commit 0ad0d3a

Browse files
serdarozerrstephanme
authored andcommitted
refactor: strategy name changed to commandexecutor
1 parent cf6c0d5 commit 0ad0d3a

File tree

3 files changed

+37
-37
lines changed

3 files changed

+37
-37
lines changed

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ func main() {
4848
log.Fatalln(err)
4949
}
5050

51-
sty := storage.NewStrategy(client)
51+
cex := storage.NewCommandExecuter(client)
5252

5353
nonFlagArgs := flag.Args()
5454
if len(nonFlagArgs) < 1 {
5555
log.Fatalf("Expected at least 1 argument (command) got 0")
5656
}
5757

5858
cmd := nonFlagArgs[0]
59-
err = sty.ExecuteCommand(cmd, nonFlagArgs[1:])
59+
err = cex.Execute(cmd, nonFlagArgs[1:])
6060
fatalLog(cmd, err)
6161

6262
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ func (e *NotExistsError) Error() string {
1313
return "object does not exist"
1414
}
1515

16-
type Strategy struct {
16+
type CommandExecuter struct {
1717
str Storager
1818
}
1919

20-
func NewStrategy(s Storager) *Strategy {
21-
return &Strategy{str: s}
20+
func NewCommandExecuter(s Storager) *CommandExecuter {
21+
return &CommandExecuter{str: s}
2222
}
2323

24-
func (sty *Strategy) SetStorager(s Storager) {
24+
func (sty *CommandExecuter) SetStorager(s Storager) {
2525
sty.str = s
2626
}
2727

28-
func (sty *Strategy) ExecuteCommand(cmd string, nonFlagArgs []string) error {
28+
func (sty *CommandExecuter) Execute(cmd string, nonFlagArgs []string) error {
2929

3030
switch cmd {
3131
case "put":
Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import (
1010
)
1111

1212
var _ = Describe("Execute Command", func() {
13-
var sourceFileName = "some-source-file-strategy"
14-
var strategy *Strategy
13+
var sourceFileName = "some-source-file-command-executer"
14+
var commandExecuter *CommandExecuter
1515
var fakeStorager *FakeStorager
1616
var tempFile *os.File
1717

1818
BeforeEach(func() {
1919
fakeStorager = &FakeStorager{}
20-
strategy = &Strategy{str: fakeStorager}
20+
commandExecuter = &CommandExecuter{str: fakeStorager}
2121
})
2222

2323
Context("Put", func() {
@@ -27,88 +27,88 @@ var _ = Describe("Execute Command", func() {
2727
DeferCleanup(func() {
2828
os.Remove(tempFile.Name()) //nolint:errcheck
2929
})
30-
err := strategy.ExecuteCommand("put", []string{tempFile.Name(), "destination"})
30+
err := commandExecuter.Execute("put", []string{tempFile.Name(), "destination"})
3131
Expect(fakeStorager.PutCallCount()).To(BeEquivalentTo(1))
3232
Expect(err).ToNot(HaveOccurred())
3333

3434
})
3535

3636
It("No Source File", func() {
37-
err := strategy.ExecuteCommand("put", []string{"source", "destination"})
37+
err := commandExecuter.Execute("put", []string{"source", "destination"})
3838
Expect(errors.Unwrap(err).Error()).To(ContainSubstring("no such file or directory"))
3939
})
4040

4141
It("Wrong number of parameters", func() {
42-
err := strategy.ExecuteCommand("put", []string{"source"})
42+
err := commandExecuter.Execute("put", []string{"source"})
4343
Expect(err.Error()).To(ContainSubstring("put method expected 2 arguments got"))
4444
})
4545

4646
})
4747

4848
Context("Get", func() {
4949
It("Successfull", func() {
50-
err := strategy.ExecuteCommand("get", []string{"source", "destination"})
50+
err := commandExecuter.Execute("get", []string{"source", "destination"})
5151
Expect(fakeStorager.GetCallCount()).To(BeEquivalentTo(1))
5252
Expect(err).ToNot(HaveOccurred())
5353

5454
})
5555

5656
It("Wrong number of parameters", func() {
57-
err := strategy.ExecuteCommand("get", []string{"source"})
57+
err := commandExecuter.Execute("get", []string{"source"})
5858
Expect(err.Error()).To(ContainSubstring("get method expected 2 arguments got"))
5959
})
6060

6161
})
6262

6363
Context("Copy", func() {
6464
It("Successfull", func() {
65-
err := strategy.ExecuteCommand("copy", []string{"source", "destination"})
65+
err := commandExecuter.Execute("copy", []string{"source", "destination"})
6666
Expect(fakeStorager.CopyCallCount()).To(BeEquivalentTo(1))
6767
Expect(err).ToNot(HaveOccurred())
6868

6969
})
7070

7171
It("Wrong number of parameters", func() {
72-
err := strategy.ExecuteCommand("copy", []string{"source"})
72+
err := commandExecuter.Execute("copy", []string{"source"})
7373
Expect(err.Error()).To(ContainSubstring("copy method expected 2 arguments got"))
7474
})
7575

7676
})
7777

7878
Context("Delete", func() {
7979
It("Successfull", func() {
80-
err := strategy.ExecuteCommand("delete", []string{"destination"})
80+
err := commandExecuter.Execute("delete", []string{"destination"})
8181
Expect(fakeStorager.DeleteCallCount()).To(BeEquivalentTo(1))
8282
Expect(err).ToNot(HaveOccurred())
8383

8484
})
8585

8686
It("Wrong number of parameters", func() {
87-
err := strategy.ExecuteCommand("delete", []string{})
87+
err := commandExecuter.Execute("delete", []string{})
8888
Expect(err.Error()).To(ContainSubstring("delete method expected 1 argument got"))
8989
})
9090

9191
})
9292

9393
Context("Delete-Recursive", func() {
9494
It("Successfull", func() {
95-
err := strategy.ExecuteCommand("delete-recursive", []string{})
95+
err := commandExecuter.Execute("delete-recursive", []string{})
9696
Expect(fakeStorager.DeleteRecursiveCallCount()).To(BeEquivalentTo(1))
9797
Expect(fakeStorager.deleteRecursiveArgsForCall[0].arg1).To(Equal(""))
9898
Expect(err).ToNot(HaveOccurred())
9999

100100
})
101101

102102
It("Successfull With Prefix", func() {
103-
err := strategy.ExecuteCommand("delete-recursive", []string{"prefix"})
103+
err := commandExecuter.Execute("delete-recursive", []string{"prefix"})
104104
Expect(fakeStorager.DeleteRecursiveCallCount()).To(BeEquivalentTo(1))
105105
Expect(fakeStorager.deleteRecursiveArgsForCall[0].arg1).To(Equal("prefix"))
106106
Expect(err).ToNot(HaveOccurred())
107107

108108
})
109109

110110
It("Wrong number of parameters", func() {
111-
err := strategy.ExecuteCommand("delete-recursive", []string{"prefix", "extra-prefix"})
111+
err := commandExecuter.Execute("delete-recursive", []string{"prefix", "extra-prefix"})
112112
Expect(err.Error()).To(ContainSubstring("delete-recursive takes at most 1 argument (prefix) got"))
113113
})
114114

@@ -119,7 +119,7 @@ var _ = Describe("Execute Command", func() {
119119
fakeStorager.ExistsStub = func(file string) (bool, error) {
120120
return true, nil
121121
}
122-
err := strategy.ExecuteCommand("exists", []string{"object"})
122+
err := commandExecuter.Execute("exists", []string{"object"})
123123

124124
Expect(fakeStorager.ExistsCallCount()).To(BeEquivalentTo(1))
125125
Expect(err).ToNot(HaveOccurred())
@@ -131,42 +131,42 @@ var _ = Describe("Execute Command", func() {
131131
return false, nil
132132
}
133133

134-
err := strategy.ExecuteCommand("exists", []string{"object"})
134+
err := commandExecuter.Execute("exists", []string{"object"})
135135
Expect(fakeStorager.ExistsCallCount()).To(BeEquivalentTo(1))
136136
Expect(err).To(BeAssignableToTypeOf(&NotExistsError{}))
137137

138138
})
139139

140140
It("Wrong number of parameters", func() {
141-
err := strategy.ExecuteCommand("exists", []string{"object", "extra-object"})
141+
err := commandExecuter.Execute("exists", []string{"object", "extra-object"})
142142
Expect(err.Error()).To(ContainSubstring("exists method expected 1 argument got"))
143143
})
144144

145145
})
146146

147147
Context("Sign", func() {
148148
It("Successfull", func() {
149-
err := strategy.ExecuteCommand("sign", []string{"object", "put", "10s"})
149+
err := commandExecuter.Execute("sign", []string{"object", "put", "10s"})
150150

151151
Expect(fakeStorager.SignCallCount()).To(BeEquivalentTo(1))
152152
Expect(err).ToNot(HaveOccurred())
153153

154154
})
155155

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

160160
})
161161

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

166166
})
167167

168168
It("Wrong number of parameters", func() {
169-
err := strategy.ExecuteCommand("sign", []string{"object", "put"})
169+
err := commandExecuter.Execute("sign", []string{"object", "put"})
170170
Expect(err.Error()).To(ContainSubstring("sign method expects 3 arguments got"))
171171

172172
})
@@ -175,7 +175,7 @@ var _ = Describe("Execute Command", func() {
175175

176176
Context("List", func() {
177177
It("Successfull", func() {
178-
err := strategy.ExecuteCommand("list", []string{})
178+
err := commandExecuter.Execute("list", []string{})
179179

180180
Expect(fakeStorager.ListCallCount()).To(BeEquivalentTo(1))
181181
Expect(fakeStorager.listArgsForCall[0].arg1).To(Equal(""))
@@ -184,53 +184,53 @@ var _ = Describe("Execute Command", func() {
184184
})
185185

186186
It("With Prefix", func() {
187-
err := strategy.ExecuteCommand("exists", []string{"prefix"})
187+
err := commandExecuter.Execute("exists", []string{"prefix"})
188188
Expect(fakeStorager.ExistsCallCount()).To(BeEquivalentTo(1))
189189
Expect(fakeStorager.existsArgsForCall[0].arg1).To(Equal("prefix"))
190190
Expect(err).To(BeAssignableToTypeOf(&NotExistsError{}))
191191

192192
})
193193

194194
It("Wrong number of parameters", func() {
195-
err := strategy.ExecuteCommand("list", []string{"prefix-1", "prefix-2"})
195+
err := commandExecuter.Execute("list", []string{"prefix-1", "prefix-2"})
196196
Expect(err.Error()).To(ContainSubstring("list method takes at most 1 argument (prefix) got"))
197197
})
198198

199199
})
200200

201201
Context("Properties", func() {
202202
It("Successfull", func() {
203-
err := strategy.ExecuteCommand("properties", []string{"object"})
203+
err := commandExecuter.Execute("properties", []string{"object"})
204204
Expect(fakeStorager.PropertiesCallCount()).To(BeEquivalentTo(1))
205205
Expect(err).ToNot(HaveOccurred())
206206

207207
})
208208

209209
It("Wrong number of parameters", func() {
210-
err := strategy.ExecuteCommand("properties", []string{})
210+
err := commandExecuter.Execute("properties", []string{})
211211
Expect(err.Error()).To(ContainSubstring("properties method expected 1 argument got"))
212212
})
213213

214214
})
215215

216216
Context("Ensure storage exists", func() {
217217
It("Successfull", func() {
218-
err := strategy.ExecuteCommand("ensure-storage-exists", []string{})
218+
err := commandExecuter.Execute("ensure-storage-exists", []string{})
219219
Expect(fakeStorager.EnsureStorageExistsCallCount()).To(BeEquivalentTo(1))
220220
Expect(err).ToNot(HaveOccurred())
221221

222222
})
223223

224224
It("Wrong number of parameters", func() {
225-
err := strategy.ExecuteCommand("ensure-storage-exists", []string{"extra-parameter"})
225+
err := commandExecuter.Execute("ensure-storage-exists", []string{"extra-parameter"})
226226
Expect(err.Error()).To(ContainSubstring("ensureStorageExists method expected 0 argument got"))
227227
})
228228

229229
})
230230

231231
Context("Unsupported command", func() {
232232
It("Successfull", func() {
233-
err := strategy.ExecuteCommand("unsupported-command", []string{})
233+
err := commandExecuter.Execute("unsupported-command", []string{})
234234
Expect(err.Error()).To(ContainSubstring("unknown command: '%s'", "unsupported-command"))
235235

236236
})

0 commit comments

Comments
 (0)