cloud_door 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/Guardfile +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +204 -0
- data/Rakefile +11 -0
- data/bin/dropbox +133 -0
- data/bin/onedrive +133 -0
- data/cloud_door.gemspec +38 -0
- data/cloud_door_config.yml +12 -0
- data/data/.gitkeep +0 -0
- data/data/testlist +0 -0
- data/lib/cloud_door.rb +114 -0
- data/lib/cloud_door/account.rb +27 -0
- data/lib/cloud_door/cloud_storage.rb +294 -0
- data/lib/cloud_door/cloud_yaml.rb +45 -0
- data/lib/cloud_door/config.rb +61 -0
- data/lib/cloud_door/console.rb +334 -0
- data/lib/cloud_door/dropbox.rb +166 -0
- data/lib/cloud_door/exceptions.rb +153 -0
- data/lib/cloud_door/file_list.rb +164 -0
- data/lib/cloud_door/onedrive.rb +180 -0
- data/lib/cloud_door/onedrive_api.rb +169 -0
- data/lib/cloud_door/token.rb +67 -0
- data/lib/cloud_door/version.rb +3 -0
- data/log/.gitkeep +0 -0
- data/spec/cloud_door/account_spec.rb +96 -0
- data/spec/cloud_door/cloud_storage_spec.rb +10 -0
- data/spec/cloud_door/cloud_yaml_spec.rb +32 -0
- data/spec/cloud_door/config_spec.rb +95 -0
- data/spec/cloud_door/console_spec.rb +633 -0
- data/spec/cloud_door/dropbox_spec.rb +625 -0
- data/spec/cloud_door/file_list_spec.rb +451 -0
- data/spec/cloud_door/onedrive_api_spec.rb +256 -0
- data/spec/cloud_door/onedrive_spec.rb +652 -0
- data/spec/cloud_door/token_spec.rb +81 -0
- data/spec/fabricators/account_fabricator.rb +5 -0
- data/spec/fabricators/cloud_yaml_fabricator.rb +5 -0
- data/spec/fabricators/config_fabrication.rb +5 -0
- data/spec/fabricators/token_fabricator.rb +10 -0
- data/spec/spec_helper.rb +55 -0
- metadata +380 -0
@@ -0,0 +1,633 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
def create_console
|
4
|
+
console = CloudDoor::Console.new(CloudDoor::OneDrive)
|
5
|
+
console.drive.storage.token.token_file = './data/test_token'
|
6
|
+
console.drive.storage.token.access_token = 'token'
|
7
|
+
console.drive.storage.token.refresh_token = 'refresh'
|
8
|
+
console.drive.storage.config.client_id = '1234'
|
9
|
+
console.drive.storage.config.client_secret = 'abcd'
|
10
|
+
console.drive.storage.config.redirect_url = 'testurl'
|
11
|
+
console.drive.storage.account.login_account = 'test'
|
12
|
+
console.drive.storage.account.login_password = 'pass1234'
|
13
|
+
console.drive.storage.file_list.list_file = './data/testlist'
|
14
|
+
console
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'Console' do
|
18
|
+
before(:each) do
|
19
|
+
# $terminal is instance of Highline class
|
20
|
+
$terminal.output = StringIO.new
|
21
|
+
end
|
22
|
+
=begin
|
23
|
+
describe 'config' do
|
24
|
+
subject { console.config(show) }
|
25
|
+
let(:console) { create_console }
|
26
|
+
context 'input config' do
|
27
|
+
let(:show) { false }
|
28
|
+
it do
|
29
|
+
subject
|
30
|
+
config = console.drive.storage.config
|
31
|
+
expect(config.client_id).to eq 'client'
|
32
|
+
expect(config.client_secret).to eq 'secret'
|
33
|
+
expect(config.redirect_url).to eq 'localhost'
|
34
|
+
expects = 'update configuration success'
|
35
|
+
expect($terminal.output.string).to include(expects)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
context 'show config' do
|
39
|
+
let(:show) { true }
|
40
|
+
it do
|
41
|
+
expect { subject }.to raise_error(SystemExit)
|
42
|
+
expects = <<EOF
|
43
|
+
OneDrive configuration are
|
44
|
+
client_id : 1234
|
45
|
+
client_secret: abcd
|
46
|
+
redirect_url : testurl
|
47
|
+
EOF
|
48
|
+
expect($terminal.output.string).to include(expects)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe 'account' do
|
54
|
+
subject { console.account(show) }
|
55
|
+
let(:console) { create_console }
|
56
|
+
context 'input account' do
|
57
|
+
let(:show) { false }
|
58
|
+
it do
|
59
|
+
subject
|
60
|
+
account = console.drive.storage.account
|
61
|
+
expect(account.login_account).to eq 'account'
|
62
|
+
expect(account.login_password).to eq 'password'
|
63
|
+
expects = 'update account success'
|
64
|
+
expect($terminal.output.string).to include(expects)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
context 'show account' do
|
68
|
+
let(:show) { true }
|
69
|
+
it do
|
70
|
+
expect { subject }.to raise_error(SystemExit)
|
71
|
+
expects = <<EOF
|
72
|
+
OneDrive account are
|
73
|
+
login_account : test
|
74
|
+
login_password: pass1234
|
75
|
+
EOF
|
76
|
+
expect($terminal.output.string).to include(expects)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
=end
|
81
|
+
describe 'login' do
|
82
|
+
subject { console.login(default) }
|
83
|
+
let(:console) { create_console }
|
84
|
+
context 'success' do
|
85
|
+
context 'use default account' do
|
86
|
+
let(:default) { true }
|
87
|
+
let(:posit) do
|
88
|
+
{
|
89
|
+
'file1' => {'id' => 'file.1234', 'type' => 'file'},
|
90
|
+
'folder1' => {'id' => 'folder.5678', 'type' => 'folder'}
|
91
|
+
}
|
92
|
+
end
|
93
|
+
it do
|
94
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:isset_account?)
|
95
|
+
.and_return(true)
|
96
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:login)
|
97
|
+
.and_return(true)
|
98
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:show_user)
|
99
|
+
.and_return({'name' => 'drive'})
|
100
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:show_current_directory)
|
101
|
+
.and_return('/top')
|
102
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:show_files)
|
103
|
+
.with(nil)
|
104
|
+
.and_return(posit)
|
105
|
+
subject
|
106
|
+
expects = <<EOF
|
107
|
+
found defaulut account 'test'. use this account.
|
108
|
+
start a connection to the OneDrive. please wait a few seconds.
|
109
|
+
login success.
|
110
|
+
login as drive.
|
111
|
+
|
112
|
+
you have these files on '/top'.
|
113
|
+
[file ] file1
|
114
|
+
[folder] folder1
|
115
|
+
EOF
|
116
|
+
expect($terminal.output.string).to include(expects)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
context 'use input account' do
|
120
|
+
let(:default) { false }
|
121
|
+
let(:posit) do
|
122
|
+
{
|
123
|
+
'file1' => {'id' => 'file.1234', 'type' => 'file'},
|
124
|
+
'folder1' => {'id' => 'folder.5678', 'type' => 'folder'}
|
125
|
+
}
|
126
|
+
end
|
127
|
+
it do
|
128
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:login)
|
129
|
+
.and_return(true)
|
130
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:show_user)
|
131
|
+
.and_return({'name' => 'drive'})
|
132
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:show_current_directory)
|
133
|
+
.and_return('/top')
|
134
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:show_files)
|
135
|
+
.with(nil)
|
136
|
+
.and_return(posit)
|
137
|
+
subject
|
138
|
+
expects = <<EOF
|
139
|
+
please enter the OneDrive account.
|
140
|
+
start a connection to the OneDrive. please wait a few seconds.
|
141
|
+
login success.
|
142
|
+
login as drive.
|
143
|
+
|
144
|
+
you have these files on '/top'.
|
145
|
+
[file ] file1
|
146
|
+
[folder] folder1
|
147
|
+
EOF
|
148
|
+
expect($terminal.output.string).to include(expects)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'fail' do
|
154
|
+
context 'configuration not init' do
|
155
|
+
let(:default) { false }
|
156
|
+
it do
|
157
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:configuration_init?)
|
158
|
+
.and_return(false)
|
159
|
+
expect { subject }.to raise_error(SystemExit)
|
160
|
+
expects = "config is not found. please execute './onedrive config' before."
|
161
|
+
expect($terminal.output.string).to include(expects)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
context 'account not found' do
|
165
|
+
let(:default) { true }
|
166
|
+
it do
|
167
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:isset_account?)
|
168
|
+
.and_return(false)
|
169
|
+
expect { subject }.to raise_error(SystemExit)
|
170
|
+
expects = "default account is not found. please execute './onedrive account' before."
|
171
|
+
expect($terminal.output.string).to include(expects)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
context 'login fail' do
|
175
|
+
let(:default) { false }
|
176
|
+
it do
|
177
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:login)
|
178
|
+
.and_return(false)
|
179
|
+
subject
|
180
|
+
expects = <<EOF
|
181
|
+
please enter the OneDrive account.
|
182
|
+
start a connection to the OneDrive. please wait a few seconds.
|
183
|
+
login fail.
|
184
|
+
EOF
|
185
|
+
expect($terminal.output.string).to include(expects)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
describe 'ls' do
|
192
|
+
subject { console.ls(file_name) }
|
193
|
+
let(:console) { create_console }
|
194
|
+
context 'have files' do
|
195
|
+
let(:file_name) { nil }
|
196
|
+
let(:posit) do
|
197
|
+
{
|
198
|
+
'file1' => {'id' => 'file.1234', 'type' => 'file'},
|
199
|
+
'folder1' => {'id' => 'folder.5678', 'type' => 'folder'}
|
200
|
+
}
|
201
|
+
end
|
202
|
+
it do
|
203
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:show_files)
|
204
|
+
.with(nil)
|
205
|
+
.and_return(posit)
|
206
|
+
subject
|
207
|
+
expects = <<EOF
|
208
|
+
you have these files on '/top'.
|
209
|
+
[file ] file1
|
210
|
+
[folder] folder1
|
211
|
+
EOF
|
212
|
+
expect($terminal.output.string).to include(expects)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
context 'not have file' do
|
216
|
+
let(:file_name) { nil }
|
217
|
+
let(:posit) { {} }
|
218
|
+
it do
|
219
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:show_files)
|
220
|
+
.with(nil)
|
221
|
+
.and_return(posit)
|
222
|
+
subject
|
223
|
+
expects = "you have no file on '/top'."
|
224
|
+
expect($terminal.output.string).to include(expects)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
context 'file name input' do
|
228
|
+
let(:file_name) { 'folder1' }
|
229
|
+
let(:posit) do
|
230
|
+
{
|
231
|
+
'file2' => {'id' => 'file.2345', 'type' => 'file'},
|
232
|
+
'folder2' => {'id' => 'folder.6789', 'type' => 'folder'}
|
233
|
+
}
|
234
|
+
end
|
235
|
+
it do
|
236
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:show_files)
|
237
|
+
.with(file_name)
|
238
|
+
.and_return(posit)
|
239
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:file_exist?)
|
240
|
+
.with(file_name)
|
241
|
+
.and_return(true)
|
242
|
+
subject
|
243
|
+
expects = <<EOF
|
244
|
+
you have these files on '/top/folder1'.
|
245
|
+
[file ] file2
|
246
|
+
[folder] folder2
|
247
|
+
EOF
|
248
|
+
expect($terminal.output.string).to include(expects)
|
249
|
+
end
|
250
|
+
end
|
251
|
+
context 'file not exists' do
|
252
|
+
let(:file_name) { 'folder9' }
|
253
|
+
it do
|
254
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:file_exist?)
|
255
|
+
.with(file_name)
|
256
|
+
.and_return(false)
|
257
|
+
expect { subject }.to raise_error(SystemExit)
|
258
|
+
expects = "'/top/folder9' not exists in OneDrive"
|
259
|
+
expect($terminal.output.string).to include(expects)
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
describe 'cd' do
|
265
|
+
subject { console.cd(file_name) }
|
266
|
+
let(:console) { create_console }
|
267
|
+
context 'file_name not input' do
|
268
|
+
let(:file_name) { nil }
|
269
|
+
it do
|
270
|
+
expect { subject }.to raise_error(SystemExit)
|
271
|
+
expects = 'this command needs file name.'
|
272
|
+
expect($terminal.output.string).to include(expects)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
context 'have files' do
|
276
|
+
let(:file_name) { 'folder1' }
|
277
|
+
let(:posit) do
|
278
|
+
{
|
279
|
+
'file2' => {'id' => 'file.2345', 'type' => 'file'},
|
280
|
+
'folder2' => {'id' => 'folder.6789', 'type' => 'folder'}
|
281
|
+
}
|
282
|
+
end
|
283
|
+
it do
|
284
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:file_exist?)
|
285
|
+
.with(file_name)
|
286
|
+
.and_return(true)
|
287
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:change_directory)
|
288
|
+
.with(file_name)
|
289
|
+
.and_return(posit)
|
290
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:show_current_directory)
|
291
|
+
.and_return('/top')
|
292
|
+
subject
|
293
|
+
expects = <<EOF
|
294
|
+
move to '/top/folder1'.
|
295
|
+
you have these files on '/top/folder1'.
|
296
|
+
[file ] file2
|
297
|
+
[folder] folder2
|
298
|
+
EOF
|
299
|
+
expect($terminal.output.string).to include(expects)
|
300
|
+
end
|
301
|
+
end
|
302
|
+
context 'not have file' do
|
303
|
+
let(:file_name) { 'folder1' }
|
304
|
+
let(:posit) { {} }
|
305
|
+
it do
|
306
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:file_exist?)
|
307
|
+
.with(file_name)
|
308
|
+
.and_return(true)
|
309
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:change_directory)
|
310
|
+
.with(file_name)
|
311
|
+
.and_return(posit)
|
312
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:show_current_directory)
|
313
|
+
.and_return('/top')
|
314
|
+
subject
|
315
|
+
expects = <<EOF
|
316
|
+
move to '/top/folder1'.
|
317
|
+
you have no file on '/top/folder1'.
|
318
|
+
EOF
|
319
|
+
expect($terminal.output.string).to include(expects)
|
320
|
+
end
|
321
|
+
end
|
322
|
+
context 'file not exists' do
|
323
|
+
let(:file_name) { 'folder9' }
|
324
|
+
it do
|
325
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:file_exist?)
|
326
|
+
.with(file_name)
|
327
|
+
.and_return(false)
|
328
|
+
expect { subject }.to raise_error(SystemExit)
|
329
|
+
expects = "'/top/folder9' not exists in OneDrive"
|
330
|
+
expect($terminal.output.string).to include(expects)
|
331
|
+
end
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
describe 'info' do
|
336
|
+
subject { console.info(file_name) }
|
337
|
+
let(:console) { create_console }
|
338
|
+
context 'file_name not input' do
|
339
|
+
let(:file_name) { nil }
|
340
|
+
it do
|
341
|
+
expect { subject }.to raise_error(SystemExit)
|
342
|
+
expects = 'this command needs file name.'
|
343
|
+
expect($terminal.output.string).to include(expects)
|
344
|
+
end
|
345
|
+
end
|
346
|
+
context 'file exists' do
|
347
|
+
let(:file_name) { 'file1' }
|
348
|
+
let(:posit) do
|
349
|
+
{
|
350
|
+
'id' => 'file.1234',
|
351
|
+
'name' => 'file1'
|
352
|
+
}
|
353
|
+
end
|
354
|
+
it do
|
355
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:file_exist?)
|
356
|
+
.with(file_name)
|
357
|
+
.and_return(true)
|
358
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:show_property)
|
359
|
+
.and_return(posit)
|
360
|
+
subject
|
361
|
+
expects = <<EOF
|
362
|
+
information of '/top/file1'.
|
363
|
+
id : file.1234
|
364
|
+
name : file1
|
365
|
+
EOF
|
366
|
+
expect($terminal.output.string).to include(expects)
|
367
|
+
end
|
368
|
+
end
|
369
|
+
context 'file not exists' do
|
370
|
+
let(:file_name) { 'file9' }
|
371
|
+
it do
|
372
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:file_exist?)
|
373
|
+
.with(file_name)
|
374
|
+
.and_return(false)
|
375
|
+
expect { subject }.to raise_error(SystemExit)
|
376
|
+
expects = "'/top/file9' not exists in OneDrive"
|
377
|
+
expect($terminal.output.string).to include(expects)
|
378
|
+
end
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
382
|
+
describe 'pwd' do
|
383
|
+
subject { console.pwd }
|
384
|
+
let(:console) { create_console }
|
385
|
+
let(:posit) { '/top' }
|
386
|
+
it do
|
387
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:show_current_directory)
|
388
|
+
.and_return(posit)
|
389
|
+
subject
|
390
|
+
expects = '/top'
|
391
|
+
expect($terminal.output.string).to include(expects)
|
392
|
+
end
|
393
|
+
end
|
394
|
+
|
395
|
+
describe 'download' do
|
396
|
+
subject { console.download(file_name) }
|
397
|
+
let(:console) { create_console }
|
398
|
+
context 'file_name not input' do
|
399
|
+
let(:file_name) { nil }
|
400
|
+
it do
|
401
|
+
expect { subject }.to raise_error(SystemExit)
|
402
|
+
expects = 'this command needs file name.'
|
403
|
+
expect($terminal.output.string).to include(expects)
|
404
|
+
end
|
405
|
+
end
|
406
|
+
context 'file exists' do
|
407
|
+
context 'not duplicate' do
|
408
|
+
let(:file_name) { 'file1' }
|
409
|
+
it do
|
410
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:file_exist?)
|
411
|
+
.with(file_name)
|
412
|
+
.and_return(true)
|
413
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:download_file)
|
414
|
+
.with(file_name)
|
415
|
+
.and_return(true)
|
416
|
+
subject
|
417
|
+
expects = "'file1' download success."
|
418
|
+
expect($terminal.output.string).to include(expects)
|
419
|
+
end
|
420
|
+
end
|
421
|
+
context 'duplicate' do
|
422
|
+
let(:file_name) { 'file1' }
|
423
|
+
before(:each) do
|
424
|
+
open(file_name, 'wb') { |file| file << 'test' }
|
425
|
+
end
|
426
|
+
it do
|
427
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:file_exist?)
|
428
|
+
.with(file_name)
|
429
|
+
.and_return(true)
|
430
|
+
expect { subject }.to raise_error(SystemExit)
|
431
|
+
expects = "'file1' already exists in local."
|
432
|
+
expect($terminal.output.string).to include(expects)
|
433
|
+
end
|
434
|
+
after(:each) do
|
435
|
+
File.delete(file_name) if File.exist?(file_name)
|
436
|
+
end
|
437
|
+
end
|
438
|
+
end
|
439
|
+
context 'file not exists' do
|
440
|
+
let(:file_name) { 'file9' }
|
441
|
+
it do
|
442
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:file_exist?)
|
443
|
+
.with(file_name)
|
444
|
+
.and_return(false)
|
445
|
+
expect { subject }.to raise_error(SystemExit)
|
446
|
+
expects = "'/top/file9' not exists in OneDrive."
|
447
|
+
expect($terminal.output.string).to include(expects)
|
448
|
+
end
|
449
|
+
end
|
450
|
+
end
|
451
|
+
|
452
|
+
describe 'upload' do
|
453
|
+
subject { console.upload(file_name) }
|
454
|
+
let(:console) { create_console }
|
455
|
+
context 'file_name not input' do
|
456
|
+
let(:file_name) { nil }
|
457
|
+
it do
|
458
|
+
expect { subject }.to raise_error(SystemExit)
|
459
|
+
expects = 'this command needs file name.'
|
460
|
+
expect($terminal.output.string).to include(expects)
|
461
|
+
end
|
462
|
+
end
|
463
|
+
context 'file exists' do
|
464
|
+
context 'not duplicate' do
|
465
|
+
let(:file_name) { 'file1' }
|
466
|
+
before(:each) do
|
467
|
+
open(file_name, 'wb') { |file| file << 'test' }
|
468
|
+
end
|
469
|
+
it do
|
470
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:file_exist?)
|
471
|
+
.with(file_name)
|
472
|
+
.and_return(false)
|
473
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:upload_file)
|
474
|
+
.with(file_name)
|
475
|
+
.and_return(true)
|
476
|
+
subject
|
477
|
+
expects = <<EOF
|
478
|
+
'/top/file1' upload success.
|
479
|
+
EOF
|
480
|
+
expect($terminal.output.string).to include(expects)
|
481
|
+
end
|
482
|
+
after(:each) do
|
483
|
+
File.delete(file_name) if File.exist?(file_name)
|
484
|
+
end
|
485
|
+
end
|
486
|
+
context 'duplicate' do
|
487
|
+
let(:file_name) { 'file1' }
|
488
|
+
before(:each) do
|
489
|
+
open(file_name, 'wb') { |file| file << 'test' }
|
490
|
+
end
|
491
|
+
it do
|
492
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:file_exist?)
|
493
|
+
.with(file_name)
|
494
|
+
.and_return(true)
|
495
|
+
expect { subject }.to raise_error(SystemExit)
|
496
|
+
expects = "'/top/file1' already exists in OneDrive."
|
497
|
+
expect($terminal.output.string).to include(expects)
|
498
|
+
end
|
499
|
+
after(:each) do
|
500
|
+
File.delete(file_name) if File.exist?(file_name)
|
501
|
+
end
|
502
|
+
end
|
503
|
+
context'target is directory' do
|
504
|
+
let(:file_name) { 'folder1' }
|
505
|
+
before(:each) do
|
506
|
+
Dir.mkdir(file_name)
|
507
|
+
end
|
508
|
+
it do
|
509
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:file_exist?)
|
510
|
+
.with("#{file_name}.zip")
|
511
|
+
.and_return(false)
|
512
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:upload_file)
|
513
|
+
.with(file_name)
|
514
|
+
.and_return(true)
|
515
|
+
subject
|
516
|
+
expects = <<EOF
|
517
|
+
'folder1' is a directory.
|
518
|
+
upload as 'folder1.zip'.
|
519
|
+
|
520
|
+
'/top/folder1.zip' upload success.
|
521
|
+
EOF
|
522
|
+
expect($terminal.output.string).to include(expects)
|
523
|
+
end
|
524
|
+
after(:each) do
|
525
|
+
Dir.rmdir(file_name) if Dir.exist?(file_name)
|
526
|
+
end
|
527
|
+
end
|
528
|
+
end
|
529
|
+
context 'file not exists' do
|
530
|
+
let(:file_name) { 'file9' }
|
531
|
+
it do
|
532
|
+
expect { subject }.to raise_error(SystemExit)
|
533
|
+
expects = "'file9' not exists in local."
|
534
|
+
expect($terminal.output.string).to include(expects)
|
535
|
+
end
|
536
|
+
end
|
537
|
+
end
|
538
|
+
|
539
|
+
describe 'rm' do
|
540
|
+
subject { console.rm(file_name) }
|
541
|
+
let(:console) { create_console }
|
542
|
+
context 'file_name not input' do
|
543
|
+
let(:file_name) { nil }
|
544
|
+
it do
|
545
|
+
expect { subject }.to raise_error(SystemExit)
|
546
|
+
expects = 'this command needs file name.'
|
547
|
+
expect($terminal.output.string).to include(expects)
|
548
|
+
end
|
549
|
+
end
|
550
|
+
context 'file exists' do
|
551
|
+
context 'target is file' do
|
552
|
+
let(:file_name) { 'file1' }
|
553
|
+
it do
|
554
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:file_exist?)
|
555
|
+
.with(file_name)
|
556
|
+
.and_return(true)
|
557
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:has_file?)
|
558
|
+
.with(file_name)
|
559
|
+
.and_return(false)
|
560
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:delete_file)
|
561
|
+
.with(file_name)
|
562
|
+
.and_return(true)
|
563
|
+
subject
|
564
|
+
expects = "'/top/file1' delete success."
|
565
|
+
expect($terminal.output.string).to include(expects)
|
566
|
+
end
|
567
|
+
end
|
568
|
+
context 'target is directory' do
|
569
|
+
let(:file_name) { 'folder1' }
|
570
|
+
it do
|
571
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:file_exist?)
|
572
|
+
.with(file_name)
|
573
|
+
.and_return(true)
|
574
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:has_file?)
|
575
|
+
.with(file_name)
|
576
|
+
.and_return(true)
|
577
|
+
expect { subject }.to raise_error(SystemExit)
|
578
|
+
expects = "'/top/folder1' has files."
|
579
|
+
expect($terminal.output.string).to include(expects)
|
580
|
+
end
|
581
|
+
end
|
582
|
+
end
|
583
|
+
context 'file not exists' do
|
584
|
+
let(:file_name) { 'file9' }
|
585
|
+
it do
|
586
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:file_exist?)
|
587
|
+
.with(file_name)
|
588
|
+
.and_return(false)
|
589
|
+
expect { subject }.to raise_error(SystemExit)
|
590
|
+
expects = "'/top/file9' not exists in OneDrive"
|
591
|
+
expect($terminal.output.string).to include(expects)
|
592
|
+
end
|
593
|
+
end
|
594
|
+
end
|
595
|
+
|
596
|
+
describe 'mkdir' do
|
597
|
+
subject { console.mkdir(mkdir_name) }
|
598
|
+
let(:console) { create_console }
|
599
|
+
context 'mkdir_name not input' do
|
600
|
+
let(:mkdir_name) { nil }
|
601
|
+
it do
|
602
|
+
expect { subject }.to raise_error(SystemExit)
|
603
|
+
expects = 'this command needs file name.'
|
604
|
+
expect($terminal.output.string).to include(expects)
|
605
|
+
end
|
606
|
+
end
|
607
|
+
context 'folder not exists' do
|
608
|
+
let(:mkdir_name) { 'folder1' }
|
609
|
+
it do
|
610
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:file_exist?)
|
611
|
+
.with(mkdir_name)
|
612
|
+
.and_return(false)
|
613
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:make_directory)
|
614
|
+
.with(mkdir_name)
|
615
|
+
.and_return(true)
|
616
|
+
subject
|
617
|
+
expects = "make '/top/folder1' directory success."
|
618
|
+
expect($terminal.output.string).to include(expects)
|
619
|
+
end
|
620
|
+
end
|
621
|
+
context 'folder exists' do
|
622
|
+
let(:mkdir_name) { 'folder1' }
|
623
|
+
it do
|
624
|
+
expect_any_instance_of(CloudDoor::OneDrive).to receive(:file_exist?)
|
625
|
+
.with(mkdir_name)
|
626
|
+
.and_return(true)
|
627
|
+
expect { subject }.to raise_error(SystemExit)
|
628
|
+
expects = "'/top/folder1' already exists in OneDrive."
|
629
|
+
expect($terminal.output.string).to include(expects)
|
630
|
+
end
|
631
|
+
end
|
632
|
+
end
|
633
|
+
end
|