cos 0.1.0 → 0.1.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 +4 -4
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +13 -2
- data/Gemfile +4 -1
- data/LICENSE +191 -0
- data/README.md +2014 -17
- data/Rakefile +23 -6
- data/bin/cos +325 -0
- data/bin/setup +1 -3
- data/cos.gemspec +24 -13
- data/lib/cos.rb +41 -4
- data/lib/cos/api.rb +289 -0
- data/lib/cos/bucket.rb +731 -0
- data/lib/cos/checkpoint.rb +62 -0
- data/lib/cos/client.rb +58 -0
- data/lib/cos/config.rb +102 -0
- data/lib/cos/dir.rb +301 -0
- data/lib/cos/download.rb +252 -0
- data/lib/cos/exception.rb +62 -0
- data/lib/cos/file.rb +152 -0
- data/lib/cos/http.rb +95 -0
- data/lib/cos/logging.rb +47 -0
- data/lib/cos/resource.rb +201 -0
- data/lib/cos/signature.rb +119 -0
- data/lib/cos/slice.rb +292 -0
- data/lib/cos/struct.rb +49 -0
- data/lib/cos/tree.rb +165 -0
- data/lib/cos/util.rb +82 -0
- data/lib/cos/version.rb +2 -2
- data/spec/cos/bucket_spec.rb +562 -0
- data/spec/cos/client_spec.rb +77 -0
- data/spec/cos/dir_spec.rb +195 -0
- data/spec/cos/download_spec.rb +105 -0
- data/spec/cos/http_spec.rb +70 -0
- data/spec/cos/signature_spec.rb +83 -0
- data/spec/cos/slice_spec.rb +302 -0
- data/spec/cos/struct_spec.rb +38 -0
- data/spec/cos/tree_spec.rb +322 -0
- data/spec/cos/util_spec.rb +106 -0
- data/test/download_test.rb +44 -0
- data/test/list_test.rb +43 -0
- data/test/upload_test.rb +48 -0
- metadata +132 -21
- data/.idea/.name +0 -1
- data/.idea/cos.iml +0 -49
- data/.idea/encodings.xml +0 -6
- data/.idea/misc.xml +0 -14
- data/.idea/modules.xml +0 -8
- data/.idea/workspace.xml +0 -465
- data/bin/console +0 -14
@@ -0,0 +1,83 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'minitest/mock'
|
5
|
+
|
6
|
+
module COS
|
7
|
+
|
8
|
+
describe Signature do
|
9
|
+
|
10
|
+
before :all do
|
11
|
+
@config = Config.new({
|
12
|
+
app_id: '100000',
|
13
|
+
secret_id: 'secret_id',
|
14
|
+
secret_key: 'secret_key'
|
15
|
+
})
|
16
|
+
|
17
|
+
Signature.send(:public, *Signature.private_instance_methods)
|
18
|
+
end
|
19
|
+
|
20
|
+
# 测试签名字符串是否正确
|
21
|
+
it 'should get correct string_to_sign' do
|
22
|
+
Time.stub :now, Time.at(0) do
|
23
|
+
s = Signature.new(@config)
|
24
|
+
|
25
|
+
s.instance_variable_set(:@file_id, '/file/id')
|
26
|
+
|
27
|
+
s.stub(:rand, 8888) do
|
28
|
+
expect(
|
29
|
+
s.string_to_sign(:once, 'bucket')
|
30
|
+
).to eq('a=100000&b=bucket&k=secret_id&e=0&t=0&r=8888&f=/file/id')
|
31
|
+
|
32
|
+
expect do
|
33
|
+
s.string_to_sign(:aaa, 'bucket')
|
34
|
+
end.to raise_error(Exception)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# 测试单次签名是否正确
|
40
|
+
it 'should get correct once signature' do
|
41
|
+
|
42
|
+
value = 'uHttFnTdOl0Gav10HilAyd48y0JhPTEwMDAwMCZiPWJ1Y2tldF9uYW1lJms9c2VjcmV0X2lkJmU9MCZ0PTAmcj05OTk5JmY9LzEwMDAwMC9idWNrZXRfbmFtZS9wYXRoL2ZpbGUx'
|
43
|
+
|
44
|
+
Time.stub :now, Time.at(0) do
|
45
|
+
s = Signature.new(@config)
|
46
|
+
|
47
|
+
s.stub(:rand, 9999) do
|
48
|
+
expect(
|
49
|
+
s.once('bucket_name', '/path/file1')
|
50
|
+
).to eq(value)
|
51
|
+
|
52
|
+
expect(
|
53
|
+
s.once('bucket_name', 'path/file1')
|
54
|
+
).to eq(value)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
# 测试多次签名是否正确
|
61
|
+
it 'should get correct multiple signature' do
|
62
|
+
|
63
|
+
value = '5Z8lOVnqnB+edqjced24dmJu2gZhPTEwMDAwMCZiPWJ1Y2tldF9uYW1lJms9c2VjcmV0X2lkJmU9NjAwJnQ9MCZyPTk5OTkmZj0='
|
64
|
+
|
65
|
+
Time.stub :now, Time.at(0) do
|
66
|
+
s = Signature.new(@config)
|
67
|
+
|
68
|
+
s.stub(:rand, 9999) do
|
69
|
+
expect(
|
70
|
+
s.multiple('bucket_name', 600)
|
71
|
+
).to eq(value)
|
72
|
+
|
73
|
+
expect do
|
74
|
+
s.multiple('bucket_name', 0)
|
75
|
+
end.to raise_error(AttrError)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,302 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module COS
|
6
|
+
|
7
|
+
describe Slice do
|
8
|
+
|
9
|
+
before :all do
|
10
|
+
config = {
|
11
|
+
app_id: '100000',
|
12
|
+
secret_id: 'secret_id',
|
13
|
+
secret_key: 'secret_key',
|
14
|
+
protocol: 'http',
|
15
|
+
default_bucket: 'bucket_name'
|
16
|
+
}
|
17
|
+
@client = Client.new(config)
|
18
|
+
@config = @client.config
|
19
|
+
|
20
|
+
@file = './file_to_upload.log'
|
21
|
+
@file_path = '/path/path2/'
|
22
|
+
@file_name = 'test_file'
|
23
|
+
|
24
|
+
File.open(@file, 'w') do |f|
|
25
|
+
(1..100).each do |i|
|
26
|
+
f.puts i.to_s.rjust(100, '0')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
before :each do
|
32
|
+
File.delete("#{@file}.cpt") if File.exist?("#{@file}.cpt")
|
33
|
+
end
|
34
|
+
|
35
|
+
after :each do
|
36
|
+
File.delete("#{@file}.cpt") if File.exist?("#{@file}.cpt")
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should upload file' do
|
40
|
+
|
41
|
+
stub_request(:post, 'http://web.file.myqcloud.com/files/v1/100000/bucket_name/path/path2/test_file')
|
42
|
+
.to_return(:status => 200, :body => {
|
43
|
+
code: 0, message: 'ok', data: {session: 'session', slice_size: 100, offset: 0}
|
44
|
+
}.to_json).then
|
45
|
+
.to_return(:status => 200, :body => {
|
46
|
+
code: 0, message: 'ok', data: {session: 'session', access_url: 'access_url'}
|
47
|
+
}.to_json)
|
48
|
+
|
49
|
+
prg = []
|
50
|
+
|
51
|
+
progress = proc do |p|
|
52
|
+
prg << p
|
53
|
+
end
|
54
|
+
|
55
|
+
@slice = Slice.new(
|
56
|
+
config: @config,
|
57
|
+
http: @client.api.http,
|
58
|
+
path: @file_path,
|
59
|
+
file_name: @file_name,
|
60
|
+
file_src: @file,
|
61
|
+
options: {},
|
62
|
+
progress: progress
|
63
|
+
).upload
|
64
|
+
|
65
|
+
|
66
|
+
expect(File.exist?("#{@file}.cpt")).to be false
|
67
|
+
|
68
|
+
expect(prg.size.class).to eq(Fixnum)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should upload file raise error' do
|
72
|
+
|
73
|
+
File.delete("#{@file}.cpt") if File.exist?("#{@file}.cpt")
|
74
|
+
|
75
|
+
stub_request(:post, 'http://web.file.myqcloud.com/files/v1/100000/bucket_name/path/path2/test_file')
|
76
|
+
.to_return(:status => 200, :body => {
|
77
|
+
code: 0, message: 'ok', data: {session: 'session', slice_size: 100, offset: 0}
|
78
|
+
}.to_json).then
|
79
|
+
.to_return(:status => 400, :body => {
|
80
|
+
code: -111, message: 'error', data: {session: 'session', slice_size: 100, offset: 0}
|
81
|
+
}.to_json)
|
82
|
+
|
83
|
+
prg = []
|
84
|
+
|
85
|
+
progress = proc do |p|
|
86
|
+
prg << p
|
87
|
+
end
|
88
|
+
|
89
|
+
expect do
|
90
|
+
@slice = Slice.new(
|
91
|
+
config: @config,
|
92
|
+
http: @client.api.http,
|
93
|
+
path: @file_path,
|
94
|
+
file_name: @file_name,
|
95
|
+
file_src: @file,
|
96
|
+
options: {disable_cpt: true},
|
97
|
+
progress: progress
|
98
|
+
).upload
|
99
|
+
end.to raise_error(ServerError)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should upload file return in first thread' do
|
103
|
+
|
104
|
+
File.delete("#{@file}.cpt") if File.exist?("#{@file}.cpt")
|
105
|
+
|
106
|
+
stub_request(:post, 'http://web.file.myqcloud.com/files/v1/100000/bucket_name/path/path2/test_file').
|
107
|
+
to_return(:status => 200, :body => {
|
108
|
+
code: 0, message: 'ok', data: {access_url: 'access_url'}
|
109
|
+
}.to_json)
|
110
|
+
|
111
|
+
prg = []
|
112
|
+
|
113
|
+
progress = proc {}
|
114
|
+
|
115
|
+
@slice2 = Slice.new(
|
116
|
+
config: @config,
|
117
|
+
http: @client.api.http,
|
118
|
+
path: @file_path,
|
119
|
+
file_name: @file_name,
|
120
|
+
file_src: @file,
|
121
|
+
options: {disable_cpt: true},
|
122
|
+
progress: progress
|
123
|
+
).upload
|
124
|
+
|
125
|
+
expect(@slice2[:access_url]).to eq('access_url')
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'should upload file return in first thread' do
|
129
|
+
|
130
|
+
stub_request(:post, 'http://web.file.myqcloud.com/files/v1/100000/bucket_name/path/path2/test_file').
|
131
|
+
to_return(:status => 200, :body => {
|
132
|
+
code: 0, message: 'ok', data: {access_url: 'access_url'}
|
133
|
+
}.to_json)
|
134
|
+
|
135
|
+
prg = []
|
136
|
+
|
137
|
+
progress = proc {}
|
138
|
+
|
139
|
+
@slice2 = Slice.new(
|
140
|
+
config: @config,
|
141
|
+
http: @client.api.http,
|
142
|
+
path: @file_path,
|
143
|
+
file_name: @file_name,
|
144
|
+
file_src: @file,
|
145
|
+
options: {},
|
146
|
+
progress: progress
|
147
|
+
).upload
|
148
|
+
|
149
|
+
# expect(WebMock).to have_requested(
|
150
|
+
# :post, 'http://web.file.myqcloud.com/files/v1/100000/bucket_name/path/path2/test_file').times(1)
|
151
|
+
|
152
|
+
# expect(File.exist?("#{@file}.cpt")).to be false
|
153
|
+
|
154
|
+
expect(prg.size).to eq(0)
|
155
|
+
|
156
|
+
expect(@slice2[:access_url]).to eq('access_url')
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'should raise error slice_size error' do
|
160
|
+
expect do
|
161
|
+
Slice.new(
|
162
|
+
config: @config,
|
163
|
+
http: @client.api.http,
|
164
|
+
path: @file_path,
|
165
|
+
file_name: @file_name,
|
166
|
+
file_src: @file,
|
167
|
+
options: {slice_size: 0}
|
168
|
+
).upload
|
169
|
+
end.to raise_error(ClientError, 'slice_size must > 0')
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should upload file load form cpt file with missing sha1' do
|
173
|
+
|
174
|
+
# 创建cpt
|
175
|
+
cpt_file = './test.cpt.log'
|
176
|
+
File.open(cpt_file, 'w') do |f|
|
177
|
+
f << '{"session": "session"}'
|
178
|
+
end
|
179
|
+
|
180
|
+
stub_request(:post, 'http://web.file.myqcloud.com/files/v1/100000/bucket_name/path/path2/test_file').
|
181
|
+
to_return(:status => 200, :body => {
|
182
|
+
code: 0, message: 'ok', data: {session: 'session', slice_size: 10000, offset: 0}
|
183
|
+
}.to_json)
|
184
|
+
|
185
|
+
prg = []
|
186
|
+
|
187
|
+
progress = proc {}
|
188
|
+
|
189
|
+
expect do
|
190
|
+
@slice = Slice.new(
|
191
|
+
config: @config,
|
192
|
+
http: @client.api.http,
|
193
|
+
path: @file_path,
|
194
|
+
file_name: @file_name,
|
195
|
+
file_src: @file,
|
196
|
+
options: {cpt_file: cpt_file},
|
197
|
+
progress: progress
|
198
|
+
).upload
|
199
|
+
end.to raise_error(CheckpointBrokenError, 'Missing SHA1 in checkpoint.')
|
200
|
+
|
201
|
+
File.delete(cpt_file) if File.exist?(cpt_file)
|
202
|
+
end
|
203
|
+
|
204
|
+
it 'should upload file load form cpt file with change' do
|
205
|
+
|
206
|
+
# 创建cpt
|
207
|
+
cpt_file = './test.cpt.log'
|
208
|
+
File.open(cpt_file, 'w') do |f|
|
209
|
+
f << '{"session": "session", "sha1":"1111", "file_meta":{"sha1":"1111"}}'
|
210
|
+
end
|
211
|
+
|
212
|
+
stub_request(:post, 'http://web.file.myqcloud.com/files/v1/100000/bucket_name/path/path2/test_file').
|
213
|
+
to_return(:status => 200, :body => {
|
214
|
+
code: 0, message: 'ok', data: {session: 'session', slice_size: 10000, offset: 0}
|
215
|
+
}.to_json)
|
216
|
+
|
217
|
+
prg = []
|
218
|
+
|
219
|
+
progress = proc {}
|
220
|
+
|
221
|
+
expect do
|
222
|
+
@slice = Slice.new(
|
223
|
+
config: @config,
|
224
|
+
http: @client.api.http,
|
225
|
+
path: @file_path,
|
226
|
+
file_name: @file_name,
|
227
|
+
file_src: @file,
|
228
|
+
options: {cpt_file: cpt_file},
|
229
|
+
progress: progress
|
230
|
+
).upload
|
231
|
+
end.to raise_error(CheckpointBrokenError, 'Unmatched checkpoint SHA1')
|
232
|
+
File.delete(cpt_file) if File.exist?(cpt_file)
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'should upload file load form cpt file with wrong sha1' do
|
236
|
+
|
237
|
+
# 创建cpt
|
238
|
+
cpt_file = './test.cpt.log'
|
239
|
+
File.open(cpt_file, 'w') do |f|
|
240
|
+
f << '{"session": "session", "sha1":"a51796cf06a44d611992c6fc796c62b10da95ccf", "file_meta":{"sha1":"1111"}, "parts":[], "slice_size":10000, "file_size":'+File.size(@file).to_s+', "offset":0}'
|
241
|
+
end
|
242
|
+
|
243
|
+
stub_request(:post, 'http://web.file.myqcloud.com/files/v1/100000/bucket_name/path/path2/test_file').
|
244
|
+
to_return(:status => 200, :body => {
|
245
|
+
code: 0, message: 'ok', data: {session: 'session', slice_size: 10000, offset: 0}
|
246
|
+
}.to_json)
|
247
|
+
|
248
|
+
prg = []
|
249
|
+
|
250
|
+
progress = proc {}
|
251
|
+
|
252
|
+
expect do
|
253
|
+
@slice = Slice.new(
|
254
|
+
config: @config,
|
255
|
+
http: @client.api.http,
|
256
|
+
path: @file_path,
|
257
|
+
file_name: @file_name,
|
258
|
+
file_src: @file,
|
259
|
+
options: {cpt_file: cpt_file},
|
260
|
+
progress: progress
|
261
|
+
).upload
|
262
|
+
end.to raise_error(FileInconsistentError, 'The file to upload is changed')
|
263
|
+
File.delete(cpt_file) if File.exist?(cpt_file)
|
264
|
+
end
|
265
|
+
|
266
|
+
it 'should upload file finished' do
|
267
|
+
|
268
|
+
# 创建cpt
|
269
|
+
cpt_file = './test.cpt.log'
|
270
|
+
File.open(cpt_file, 'w') do |f|
|
271
|
+
f << '{"session": "session", "sha1":"ea32e288faa633f692cb2d7025a8ddaf54bf6516", "file_meta":{"sha1":"afbd38119325969a447bddee2dae8fd822de138f"}, "parts":[{"number":1,"done":true}], "slice_size":10000, "file_size":'+File.size(@file).to_s+', "offset":0}'
|
272
|
+
end
|
273
|
+
|
274
|
+
stub_request(:post, 'http://web.file.myqcloud.com/files/v1/100000/bucket_name/path/path2/test_file').
|
275
|
+
to_return(:status => 400, :body => {
|
276
|
+
code: -288, message: 'ok', data: {session: 'session', access_url: 'access_url'}
|
277
|
+
}.to_json)
|
278
|
+
|
279
|
+
prg = []
|
280
|
+
|
281
|
+
progress = proc do |p|
|
282
|
+
prg << p
|
283
|
+
end
|
284
|
+
|
285
|
+
expect(
|
286
|
+
Slice.new(
|
287
|
+
config: @config,
|
288
|
+
http: @client.api.http,
|
289
|
+
path: @file_path,
|
290
|
+
file_name: @file_name,
|
291
|
+
file_src: @file,
|
292
|
+
options: {cpt_file: cpt_file},
|
293
|
+
progress: progress
|
294
|
+
).upload
|
295
|
+
).to eq(nil)
|
296
|
+
|
297
|
+
File.delete(cpt_file) if File.exist?(cpt_file)
|
298
|
+
end
|
299
|
+
|
300
|
+
end
|
301
|
+
|
302
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module COS
|
6
|
+
|
7
|
+
describe Struct do
|
8
|
+
|
9
|
+
it 'should raise AttrError when miss required atrrs' do
|
10
|
+
expect do
|
11
|
+
Config.new({
|
12
|
+
app_id: '100000',
|
13
|
+
secret_id: 'secret_id',
|
14
|
+
})
|
15
|
+
end.to raise_error(AttrError)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should raise AttrError when give extra attrs' do
|
19
|
+
expect do
|
20
|
+
Config.new({
|
21
|
+
aaaa: 11111,
|
22
|
+
app_id: '100000',
|
23
|
+
secret_id: 'secret_id',
|
24
|
+
secret_key: 'secret_key',
|
25
|
+
protocol: 'http',
|
26
|
+
default_bucket: 'bucket_name'
|
27
|
+
})
|
28
|
+
end.to raise_error(AttrError)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should use default logger' do
|
32
|
+
Logging.instance_variable_set(:@logger, nil)
|
33
|
+
expect(Logging.logger.level).to eq(Logger::INFO)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,322 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module COS
|
6
|
+
|
7
|
+
describe Tree do
|
8
|
+
|
9
|
+
before :all do
|
10
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/?op=stat").
|
11
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {}}.to_json)
|
12
|
+
|
13
|
+
@config = {
|
14
|
+
app_id: '100000',
|
15
|
+
secret_id: 'secret_id',
|
16
|
+
secret_key: 'secret_key',
|
17
|
+
protocol: 'http',
|
18
|
+
default_bucket: 'bucket_name'
|
19
|
+
}
|
20
|
+
COS.client(@config).bucket
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should create tree object' do
|
24
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/path1/?op=stat").
|
25
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {name: 'path1', ctime: Time.now.to_i.to_s, mtime: Time.now.to_i.to_s, biz_attr: ''}}.to_json)
|
26
|
+
|
27
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/path1/?context=&num=20&op=list&order=0&pattern=eListDirOnly").
|
28
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {
|
29
|
+
has_more: false,
|
30
|
+
context: '',
|
31
|
+
infos: [
|
32
|
+
{name: 'path1-1', ctime: Time.now.to_i.to_s, mtime: Time.now.to_i.to_s, biz_attr: ''},
|
33
|
+
{name: 'path1-2', ctime: Time.now.to_i.to_s, mtime: Time.now.to_i.to_s, biz_attr: ''}
|
34
|
+
]
|
35
|
+
}}.to_json)
|
36
|
+
|
37
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/path1/path1-1/?context=&num=20&op=list&order=0&pattern=eListDirOnly").
|
38
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {
|
39
|
+
has_more: false,
|
40
|
+
context: '',
|
41
|
+
infos: []
|
42
|
+
}}.to_json)
|
43
|
+
|
44
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/path1/path1-2/?context=&num=20&op=list&order=0&pattern=eListDirOnly").
|
45
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {
|
46
|
+
has_more: false,
|
47
|
+
context: '',
|
48
|
+
infos: []
|
49
|
+
}}.to_json)
|
50
|
+
|
51
|
+
tree = COS.client.bucket.tree('path1')
|
52
|
+
|
53
|
+
expect(tree[:children][1][:resource].name).to eq('path1-2')
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should create tree hash' do
|
57
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/path1/?op=stat").
|
58
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {name: 'path1', ctime: Time.now.to_i.to_s, mtime: Time.now.to_i.to_s, biz_attr: ''}}.to_json)
|
59
|
+
|
60
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/path1/?context=&num=20&op=list&order=0&pattern=eListDirOnly").
|
61
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {
|
62
|
+
has_more: false,
|
63
|
+
context: '',
|
64
|
+
infos: [
|
65
|
+
{name: 'path1-1', ctime: Time.now.to_i.to_s, mtime: Time.now.to_i.to_s, biz_attr: ''},
|
66
|
+
{name: 'path1-2', ctime: Time.now.to_i.to_s, mtime: Time.now.to_i.to_s, biz_attr: ''}
|
67
|
+
]
|
68
|
+
}}.to_json)
|
69
|
+
|
70
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/path1/path1-1/?context=&num=20&op=list&order=0&pattern=eListDirOnly").
|
71
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {
|
72
|
+
has_more: false,
|
73
|
+
context: '',
|
74
|
+
infos: []
|
75
|
+
}}.to_json)
|
76
|
+
|
77
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/path1/path1-2/?context=&num=20&op=list&order=0&pattern=eListDirOnly").
|
78
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {
|
79
|
+
has_more: false,
|
80
|
+
context: '',
|
81
|
+
infos: []
|
82
|
+
}}.to_json)
|
83
|
+
|
84
|
+
tree = COS.client.bucket.hash_tree('path1')
|
85
|
+
|
86
|
+
expect(tree[:children][1][:resource][:name]).to eq('path1-2')
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should print tree in command line' do
|
90
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/?op=stat").
|
91
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {name: '', ctime: Time.now.to_i.to_s, mtime: Time.now.to_i.to_s, biz_attr: ''}}.to_json)
|
92
|
+
|
93
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/?context=&num=1&op=list&order=0&pattern=eListBoth").
|
94
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {
|
95
|
+
has_more: false,
|
96
|
+
context: '',
|
97
|
+
dircount: 2,
|
98
|
+
filecount: 0,
|
99
|
+
infos: [
|
100
|
+
{name: 'path1-1', ctime: Time.now.to_i.to_s, mtime: Time.now.to_i.to_s, biz_attr: ''},
|
101
|
+
{name: 'path1-2', ctime: Time.now.to_i.to_s, mtime: Time.now.to_i.to_s, biz_attr: ''},
|
102
|
+
]
|
103
|
+
}}.to_json)
|
104
|
+
|
105
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/?context=&num=20&op=list&order=0&pattern=eListBoth").
|
106
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {
|
107
|
+
has_more: false,
|
108
|
+
context: '',
|
109
|
+
dircount: 2,
|
110
|
+
filecount: 1,
|
111
|
+
infos: [
|
112
|
+
{name: 'path1-1', ctime: Time.now.to_i.to_s, mtime: Time.now.to_i.to_s, biz_attr: ''},
|
113
|
+
{name: 'path1-2', ctime: Time.now.to_i.to_s, mtime: Time.now.to_i.to_s, biz_attr: ''},
|
114
|
+
]
|
115
|
+
}}.to_json)
|
116
|
+
|
117
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/path1-1/?context=&num=1&op=list&order=0&pattern=eListBoth").
|
118
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {
|
119
|
+
has_more: false,
|
120
|
+
context: '',
|
121
|
+
dircount: 0,
|
122
|
+
filecount: 0,
|
123
|
+
infos: []
|
124
|
+
}}.to_json)
|
125
|
+
|
126
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/path1-1/?context=&num=20&op=list&order=0&pattern=eListBoth").
|
127
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {
|
128
|
+
has_more: false,
|
129
|
+
context: '',
|
130
|
+
dircount: 0,
|
131
|
+
filecount: 0,
|
132
|
+
infos: []
|
133
|
+
}}.to_json)
|
134
|
+
|
135
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/path1-2/?context=&num=20&op=list&order=0&pattern=eListBoth").
|
136
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {
|
137
|
+
has_more: false,
|
138
|
+
dircount: 0,
|
139
|
+
filecount: 0,
|
140
|
+
context: '',
|
141
|
+
infos: [
|
142
|
+
{name: 'path1-2-1', ctime: Time.now.to_i.to_s, mtime: Time.now.to_i.to_s, biz_attr: ''},
|
143
|
+
{name: 'path1-2-2', ctime: Time.now.to_i.to_s, mtime: Time.now.to_i.to_s, biz_attr: ''},
|
144
|
+
{name: 'f1', ctime: @time, mtime: @time, biz_attr: '', filesize: 100, filelen:100, access_url: 'url'},
|
145
|
+
]
|
146
|
+
}}.to_json)
|
147
|
+
|
148
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/path1-2/?context=&num=1&op=list&order=0&pattern=eListBoth").
|
149
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {
|
150
|
+
has_more: false,
|
151
|
+
context: '',
|
152
|
+
dircount: 2,
|
153
|
+
filecount: 1,
|
154
|
+
infos: [
|
155
|
+
{name: 'path1-2-1', ctime: Time.now.to_i.to_s, mtime: Time.now.to_i.to_s, biz_attr: ''},
|
156
|
+
{name: 'path1-2-2', ctime: Time.now.to_i.to_s, mtime: Time.now.to_i.to_s, biz_attr: ''},
|
157
|
+
{name: 'f1', ctime: @time, mtime: @time, biz_attr: '', filesize: 100, filelen:100, access_url: 'url'},
|
158
|
+
]
|
159
|
+
}}.to_json)
|
160
|
+
|
161
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/path1-2/path1-2-1/?context=&num=1&op=list&order=0&pattern=eListBoth").
|
162
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {
|
163
|
+
has_more: false,
|
164
|
+
context: '',
|
165
|
+
dircount: 0,
|
166
|
+
filecount: 0,
|
167
|
+
infos: []
|
168
|
+
}}.to_json)
|
169
|
+
|
170
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/path1-2/path1-2-1/?context=&num=20&op=list&order=0&pattern=eListBoth").
|
171
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {
|
172
|
+
has_more: false,
|
173
|
+
context: '',
|
174
|
+
dircount: 0,
|
175
|
+
filecount: 0,
|
176
|
+
infos: [
|
177
|
+
{name: 'f1', ctime: @time, mtime: @time, biz_attr: '', filesize: 100, filelen:100, access_url: 'url'},
|
178
|
+
]
|
179
|
+
}}.to_json)
|
180
|
+
|
181
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/path1-2/path1-2-2/?context=&num=1&op=list&order=0&pattern=eListBoth").
|
182
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {
|
183
|
+
has_more: false,
|
184
|
+
dircount: 0,
|
185
|
+
filecount: 0,
|
186
|
+
context: '',
|
187
|
+
infos: []
|
188
|
+
}}.to_json)
|
189
|
+
|
190
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/path1-2/path1-2-2/?context=&num=20&op=list&order=0&pattern=eListBoth").
|
191
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {
|
192
|
+
has_more: false,
|
193
|
+
dircount: 0,
|
194
|
+
filecount: 0,
|
195
|
+
context: '',
|
196
|
+
infos: []
|
197
|
+
}}.to_json)
|
198
|
+
|
199
|
+
path_obj = COS.client.bucket.stat
|
200
|
+
COS::Tree.new({path: path_obj, files: true, files_count: true}).print_tree
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'should get tree in COSFile' do
|
204
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/?op=stat").
|
205
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {name: '', ctime: Time.now.to_i.to_s, mtime: Time.now.to_i.to_s, biz_attr: ''}}.to_json)
|
206
|
+
|
207
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/?context=&num=1&op=list&order=0&pattern=eListBoth").
|
208
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {
|
209
|
+
has_more: false,
|
210
|
+
context: '',
|
211
|
+
dircount: 2,
|
212
|
+
filecount: 0,
|
213
|
+
infos: [
|
214
|
+
{name: 'path1-1', ctime: Time.now.to_i.to_s, mtime: Time.now.to_i.to_s, biz_attr: ''},
|
215
|
+
{name: 'path1-2', ctime: Time.now.to_i.to_s, mtime: Time.now.to_i.to_s, biz_attr: ''},
|
216
|
+
]
|
217
|
+
}}.to_json)
|
218
|
+
|
219
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/?context=&num=20&op=list&order=0&pattern=eListBoth").
|
220
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {
|
221
|
+
has_more: false,
|
222
|
+
context: '',
|
223
|
+
dircount: 2,
|
224
|
+
filecount: 1,
|
225
|
+
infos: [
|
226
|
+
{name: 'path1-1', ctime: Time.now.to_i.to_s, mtime: Time.now.to_i.to_s, biz_attr: ''},
|
227
|
+
{name: 'path1-2', ctime: Time.now.to_i.to_s, mtime: Time.now.to_i.to_s, biz_attr: ''},
|
228
|
+
]
|
229
|
+
}}.to_json)
|
230
|
+
|
231
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/path1-1/?context=&num=1&op=list&order=0&pattern=eListBoth").
|
232
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {
|
233
|
+
has_more: false,
|
234
|
+
context: '',
|
235
|
+
dircount: 0,
|
236
|
+
filecount: 0,
|
237
|
+
infos: []
|
238
|
+
}}.to_json)
|
239
|
+
|
240
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/path1-1/?context=&num=20&op=list&order=0&pattern=eListBoth").
|
241
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {
|
242
|
+
has_more: false,
|
243
|
+
context: '',
|
244
|
+
dircount: 0,
|
245
|
+
filecount: 0,
|
246
|
+
infos: []
|
247
|
+
}}.to_json)
|
248
|
+
|
249
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/path1-2/?context=&num=20&op=list&order=0&pattern=eListBoth").
|
250
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {
|
251
|
+
has_more: false,
|
252
|
+
dircount: 0,
|
253
|
+
filecount: 0,
|
254
|
+
context: '',
|
255
|
+
infos: [
|
256
|
+
{name: 'path1-2-1', ctime: Time.now.to_i.to_s, mtime: Time.now.to_i.to_s, biz_attr: ''},
|
257
|
+
{name: 'path1-2-2', ctime: Time.now.to_i.to_s, mtime: Time.now.to_i.to_s, biz_attr: ''},
|
258
|
+
{name: 'f1', ctime: @time, mtime: @time, biz_attr: '', filesize: 100, filelen:100, access_url: 'url'},
|
259
|
+
]
|
260
|
+
}}.to_json)
|
261
|
+
|
262
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/path1-2/?context=&num=1&op=list&order=0&pattern=eListBoth").
|
263
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {
|
264
|
+
has_more: false,
|
265
|
+
context: '',
|
266
|
+
dircount: 2,
|
267
|
+
filecount: 1,
|
268
|
+
infos: [
|
269
|
+
{name: 'path1-2-1', ctime: Time.now.to_i.to_s, mtime: Time.now.to_i.to_s, biz_attr: ''},
|
270
|
+
{name: 'path1-2-2', ctime: Time.now.to_i.to_s, mtime: Time.now.to_i.to_s, biz_attr: ''},
|
271
|
+
{name: 'f1', ctime: @time, mtime: @time, biz_attr: '', filesize: 100, filelen:100, access_url: 'url'},
|
272
|
+
]
|
273
|
+
}}.to_json)
|
274
|
+
|
275
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/path1-2/path1-2-1/?context=&num=1&op=list&order=0&pattern=eListBoth").
|
276
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {
|
277
|
+
has_more: false,
|
278
|
+
context: '',
|
279
|
+
dircount: 0,
|
280
|
+
filecount: 0,
|
281
|
+
infos: []
|
282
|
+
}}.to_json)
|
283
|
+
|
284
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/path1-2/path1-2-1/?context=&num=20&op=list&order=0&pattern=eListBoth").
|
285
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {
|
286
|
+
has_more: false,
|
287
|
+
context: '',
|
288
|
+
dircount: 0,
|
289
|
+
filecount: 0,
|
290
|
+
infos: [
|
291
|
+
{name: 'f1', ctime: @time, mtime: @time, biz_attr: '', filesize: 100, filelen:100, access_url: 'url'},
|
292
|
+
]
|
293
|
+
}}.to_json)
|
294
|
+
|
295
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/path1-2/path1-2-2/?context=&num=1&op=list&order=0&pattern=eListBoth").
|
296
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {
|
297
|
+
has_more: false,
|
298
|
+
dircount: 0,
|
299
|
+
filecount: 0,
|
300
|
+
context: '',
|
301
|
+
infos: []
|
302
|
+
}}.to_json)
|
303
|
+
|
304
|
+
stub_request(:get, "http://web.file.myqcloud.com/files/v1/100000/bucket_name/path1-2/path1-2-2/?context=&num=20&op=list&order=0&pattern=eListBoth").
|
305
|
+
to_return(:status => 200, :body => { code: 0, message: 'ok', data: {
|
306
|
+
has_more: false,
|
307
|
+
dircount: 0,
|
308
|
+
filecount: 0,
|
309
|
+
context: '',
|
310
|
+
infos: []
|
311
|
+
}}.to_json)
|
312
|
+
|
313
|
+
path_obj = COS.client.bucket.stat
|
314
|
+
tree = path_obj.tree(files: true, files_count: true)
|
315
|
+
|
316
|
+
# bucket root
|
317
|
+
expect(tree[:resource].name).to eq('')
|
318
|
+
end
|
319
|
+
|
320
|
+
end
|
321
|
+
|
322
|
+
end
|