ruby-libstorj 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.gitmodules +3 -0
  4. data/.rspec +1 -0
  5. data/Gemfile +23 -0
  6. data/Gemfile.lock +111 -0
  7. data/Guardfile +21 -0
  8. data/LICENSE +502 -0
  9. data/README.md +262 -0
  10. data/Rakefile +76 -0
  11. data/ext/libstorj/.gitignore +47 -0
  12. data/ext/libstorj/.travis.yml +27 -0
  13. data/ext/libstorj/Doxyfile +2427 -0
  14. data/ext/libstorj/LICENSE +502 -0
  15. data/ext/libstorj/Makefile.am +6 -0
  16. data/ext/libstorj/README.md +198 -0
  17. data/ext/libstorj/autogen.sh +3 -0
  18. data/ext/libstorj/configure.ac +64 -0
  19. data/ext/libstorj/depends/Makefile +153 -0
  20. data/ext/libstorj/depends/config.guess +1462 -0
  21. data/ext/libstorj/depends/config.sub +1823 -0
  22. data/ext/libstorj/depends/extract-osx-sdk.sh +33 -0
  23. data/ext/libstorj/depends/packages/cctools.mk +7 -0
  24. data/ext/libstorj/depends/packages/clang.mk +7 -0
  25. data/ext/libstorj/depends/packages/gmp.mk +23 -0
  26. data/ext/libstorj/depends/packages/gnutls.mk +25 -0
  27. data/ext/libstorj/depends/packages/json-c.mk +7 -0
  28. data/ext/libstorj/depends/packages/libcurl.mk +39 -0
  29. data/ext/libstorj/depends/packages/libmicrohttpd.mk +7 -0
  30. data/ext/libstorj/depends/packages/libuv.mk +7 -0
  31. data/ext/libstorj/depends/packages/nettle.mk +30 -0
  32. data/ext/libstorj/libstorj.pc.in +11 -0
  33. data/ext/libstorj/src/Makefile.am +23 -0
  34. data/ext/libstorj/src/bip39.c +233 -0
  35. data/ext/libstorj/src/bip39.h +64 -0
  36. data/ext/libstorj/src/bip39_english.h +2074 -0
  37. data/ext/libstorj/src/cli.c +1494 -0
  38. data/ext/libstorj/src/crypto.c +525 -0
  39. data/ext/libstorj/src/crypto.h +178 -0
  40. data/ext/libstorj/src/downloader.c +1923 -0
  41. data/ext/libstorj/src/downloader.h +163 -0
  42. data/ext/libstorj/src/http.c +688 -0
  43. data/ext/libstorj/src/http.h +175 -0
  44. data/ext/libstorj/src/rs.c +962 -0
  45. data/ext/libstorj/src/rs.h +99 -0
  46. data/ext/libstorj/src/storj.c +1523 -0
  47. data/ext/libstorj/src/storj.h +1014 -0
  48. data/ext/libstorj/src/uploader.c +2736 -0
  49. data/ext/libstorj/src/uploader.h +181 -0
  50. data/ext/libstorj/src/utils.c +336 -0
  51. data/ext/libstorj/src/utils.h +65 -0
  52. data/ext/libstorj/test/Makefile.am +27 -0
  53. data/ext/libstorj/test/mockbridge.c +260 -0
  54. data/ext/libstorj/test/mockbridge.json +687 -0
  55. data/ext/libstorj/test/mockbridgeinfo.json +1836 -0
  56. data/ext/libstorj/test/mockfarmer.c +358 -0
  57. data/ext/libstorj/test/storjtests.h +41 -0
  58. data/ext/libstorj/test/tests.c +1617 -0
  59. data/ext/libstorj/test/tests_rs.c +869 -0
  60. data/ext/ruby-libstorj/extconf.rb +8 -0
  61. data/ext/ruby-libstorj/ruby-libstorj.cc +17 -0
  62. data/lib/ruby-libstorj.rb +1 -0
  63. data/lib/ruby-libstorj/arg_forwarding_task.rb +58 -0
  64. data/lib/ruby-libstorj/env.rb +178 -0
  65. data/lib/ruby-libstorj/ext/bucket.rb +71 -0
  66. data/lib/ruby-libstorj/ext/create_bucket_request.rb +53 -0
  67. data/lib/ruby-libstorj/ext/curl_code.rb +139 -0
  68. data/lib/ruby-libstorj/ext/ext.rb +71 -0
  69. data/lib/ruby-libstorj/ext/file.rb +84 -0
  70. data/lib/ruby-libstorj/ext/get_bucket_request.rb +45 -0
  71. data/lib/ruby-libstorj/ext/json_request.rb +51 -0
  72. data/lib/ruby-libstorj/ext/list_files_request.rb +63 -0
  73. data/lib/ruby-libstorj/ext/types.rb +226 -0
  74. data/lib/ruby-libstorj/ext/upload_options.rb +38 -0
  75. data/lib/ruby-libstorj/libstorj.rb +22 -0
  76. data/lib/ruby-libstorj/mixins/storj.rb +27 -0
  77. data/lib/ruby-libstorj/struct.rb +42 -0
  78. data/ruby-libstorj.gemspec +57 -0
  79. data/spec/helpers/options.yml.example +22 -0
  80. data/spec/helpers/shared_rake_examples.rb +132 -0
  81. data/spec/helpers/storj_options.rb +96 -0
  82. data/spec/helpers/upload.data +3 -0
  83. data/spec/helpers/upload.data.sha256 +1 -0
  84. data/spec/libstorj_spec.rb +0 -0
  85. data/spec/ruby-libstorj/arg_forwarding_task_spec.rb +311 -0
  86. data/spec/ruby-libstorj/env_spec.rb +353 -0
  87. data/spec/ruby-libstorj/ext_spec.rb +75 -0
  88. data/spec/ruby-libstorj/json_request_spec.rb +13 -0
  89. data/spec/ruby-libstorj/libstorj_spec.rb +81 -0
  90. data/spec/ruby-libstorj/struct_spec.rb +64 -0
  91. data/spec/spec_helper.rb +113 -0
  92. metadata +136 -0
@@ -0,0 +1,3 @@
1
+ ### THIS FILE IS USED AS TEST UPLOAD DATA ###
2
+
3
+ 437BCEF6073012E7BB6C23D88F9BE07FF070AADBCEF5681CD2F7CB87C19F0EFF3C4A015169E090820DB22FF30CF9EF316A1685822E2F59BEFF7C04322919107FFC2CC4AF5FF94CA7D453BF0CA3156CF1407AA92994ED4F57B068C8652578C889615A9F703C87F5508AAD40C856363BF3BC31F4E875D7F7BD9DB3CFFD06808168E70AEFAFBBAAC5F6D41907513FEBF1ED0FB33A5FD53B50655F2428330FE15C19DE8CF1CC456D5D60B92E71F19BCE2880DA79373B5B75F3B06BA542A269B3DEEABD1D9094AD493576DA4B555ADCE3E63FC888097744D89B1362B1D906D0497DBA368A1BBCD88450620F6BBA2DDC2EB16F6D5538B5C39D1B542184CD515AB4557645983C98AD33797B07D523B6904916A9E3657EAEC3C94B18FADDD700CC5CCAB541CED98EAA765AD57D9C330D00E095AB9405C5181BED57777A5AC1D8FAD65CA770B8C94B1798A475274248381CAFD4761C98D4A7BE85B4761B225BA951FDFCEA45D6FE6C208BC7AE7668196520F1A8933E606A2FEC8F0DADBC17DC3FAC20D426068A0DDE6C38749A7989D544638786B84B64FC50C4C13A7DB2791815CC16D5410561DFFC433F1D1B2403C6284DDD50B2F584BB501239C3D992D4C418F5A670B79A79E8C11045D9C45D373AB31D751EC03B217624D8475BAF1142EBDA1DC633B981E5A602CA575DDDD51BEA56F3AC8B3A17CE54FC46BAE93F885CBCB3C5813718BDEC53DAC6E6300341272B61F8F96945B9F2096F3EDFF89F0E0B23A13880AFC4BAD83A08DC660C04C6013C152F04E8C62C3FF29AB2D9E666207E3822FDE1646FD090E90AEDA012ADC79521C98EF78819E52068B807AE5F108B3DAED9417B5AD57BEED4FBF0D2A421E435EDFBF4C3DAF0F2598317B25CCD933F93832616ED9F97436629760926C99A392E8AB31B4913F6812CC511E08F46834A1B2094159A45198954C7A3A19DD2679795FB799F8FCE6D81DFDE63E354189A6A2CB35551399D7A0E7E23D536D88A14EAEB7772749E891AB8495388F8A537C7A1DEE1628892BB05D6CE6EE3DA6F97F755D8CC6C96A7A62F09CE9D41328F71BB50ACD1363F7CDB33BAC2593511AE02933FC83011117CC87030DE1284677BE2DC3345A0DEB10AA3C3C49C85314414255ACA573E192E38BC0B8EC5ADC99676E732B43A179A8C9314BD5E78C14BED915E367F7B5276C7C05547F3DF98BBBE69C5BDF6BAFBEBC2AB8BCD3B559029AE171576B9469B28BF400D0573E3E65E289BE8AFA53F48B16378DB52EC47FE13DF4C648DED9AD23A62BC51D5000E838961222285E5043E6A78EEB76715ECB0928E1E40E997114478DC5ECE8E78CC585449972E6A413E9FF19523CD57D82553F29C36F698C55B5A0B4C5DD9AD8DABA7CDC0452D99EECF2EA7BAFC7CF61A50E8CC9787E94B8F8B2187233F4534AFB0143811F2C3F7964CD1BE7301D990
@@ -0,0 +1 @@
1
+ ddf547ddef6cacefe9c05879118fe423e67decae872723babde64550378c732f
File without changes
@@ -0,0 +1,311 @@
1
+ require 'rake'
2
+ require_relative '../helpers/shared_rake_examples'
3
+ require_relative '../../lib/ruby-libstorj/arg_forwarding_task'
4
+
5
+ RSpec.describe LibStorj::ArgForwardingTask do
6
+ let(:instantiate) do
7
+ described_class.new task_name,
8
+ alias_names: alias_names,
9
+ args_deps_hash: {args => deps},
10
+ &task_block
11
+ end
12
+
13
+ describe 'example_task' do
14
+ let(:task_name) {:example_task}
15
+
16
+ context 'without block' do
17
+ let(:task_block) {nil}
18
+
19
+ context 'without aliases' do
20
+ let(:alias_names) {[]}
21
+
22
+ context 'with args' do
23
+ let(:args) {%i[first_arg second_arg third_arg]}
24
+
25
+ context 'without deps' do
26
+ let(:deps) {[]}
27
+
28
+ before :all do
29
+ Rake.application = Rake::Application.new
30
+ end
31
+
32
+ include_examples 'raises `ArgumentError`'
33
+ end
34
+
35
+ context 'with deps' do
36
+ let(:deps) {%i[first_dep second_dep third_dep]}
37
+
38
+ before :all do
39
+ Rake.application = Rake::Application.new
40
+ end
41
+
42
+
43
+ include_examples 'raises `ArgumentError`'
44
+ end
45
+ end
46
+
47
+ context 'without args' do
48
+ let(:args) {[]}
49
+ let(:expected_args) {{}}
50
+
51
+ context 'without deps' do
52
+ let(:deps) {[]}
53
+
54
+ before :all do
55
+ Rake.application = Rake::Application.new
56
+ end
57
+
58
+ include_examples 'raises `ArgumentError`'
59
+ end
60
+
61
+ context 'with deps' do
62
+ let(:deps) {%i[first_dep second_dep third_dep]}
63
+
64
+ before :all do
65
+ Rake.application = Rake::Application.new
66
+ end
67
+
68
+ include_examples 'raises `ArgumentError`'
69
+ end
70
+ end
71
+ end
72
+
73
+ context 'with aliases' do
74
+ let(:alias_names) {%i[first_alias second_alias third_alias]}
75
+
76
+ context 'without args' do
77
+ let(:args) {[]}
78
+ let(:expected_args) {{}}
79
+
80
+ context 'without deps' do
81
+ let(:deps) {[]}
82
+
83
+ before :all do
84
+ Rake.application = Rake::Application.new
85
+ end
86
+
87
+ include_examples 'defines the target task'
88
+ include_examples 'gets invoked via any alias'
89
+ end
90
+
91
+ context 'with deps' do
92
+ let(:deps) {%i[first_dep second_dep third_dep]}
93
+
94
+ before :all do
95
+ Rake.application = Rake::Application.new
96
+ end
97
+
98
+ before do
99
+ deps.each do |dep_name|
100
+ Rake::Task.define_task dep_name
101
+ end
102
+ end
103
+
104
+ include_examples 'defines the target task'
105
+ include_examples 'gets invoked via any alias'
106
+ include_examples 'invokes all dependencies when invoked'
107
+ include_examples 'invokes all dependencies when invoked via any alias'
108
+ end
109
+ end
110
+
111
+ context 'with args' do
112
+ let(:args) {%i[first_arg second_arg third_arg]}
113
+ let(:expected_args) do
114
+ ### #=> {:first_arg => :first_value, ...}
115
+ Hash[args.zip(%i[first_value second_value third_value])]
116
+ end
117
+
118
+ context 'without deps' do
119
+ let(:deps) {[]}
120
+
121
+ before :all do
122
+ Rake.application = Rake::Application.new
123
+ end
124
+
125
+ include_examples 'defines the target task'
126
+ # include_examples 'gets invoked with args via any alias'
127
+ end
128
+
129
+ context 'with deps' do
130
+ let(:deps) {%i[first_dep second_dep third_dep]}
131
+
132
+ before :all do
133
+ Rake.application = Rake::Application.new
134
+ end
135
+
136
+ before do
137
+ deps.each do |dep_name|
138
+ Rake::Task.define_task dep_name
139
+ end
140
+ end
141
+
142
+ include_examples 'defines the target task'
143
+ include_examples 'gets invoked with args via any alias'
144
+ include_examples 'invokes all dependencies when invoked'
145
+ include_examples 'invokes all dependencies when invoked via any alias'
146
+ end
147
+ end
148
+ end
149
+ end
150
+
151
+ context 'with block' do
152
+ let(:task_block) do
153
+ Proc.new do
154
+ #-- noop
155
+ end
156
+ end
157
+
158
+ context 'without aliases' do
159
+ let(:alias_names) {[]}
160
+
161
+ context 'without args' do
162
+ let(:args) {[]}
163
+ let(:expected_args) {{}}
164
+
165
+ context 'without deps' do
166
+ let(:deps) {[]}
167
+
168
+ before :all do
169
+ Rake.application = Rake::Application.new
170
+ end
171
+
172
+ include_examples 'defines the target task'
173
+ include_examples 'yields to the block'
174
+ end
175
+
176
+ context 'with deps' do
177
+ let(:deps) {%i[first_dep second_dep third_dep]}
178
+
179
+ before :all do
180
+ Rake.application = Rake::Application.new
181
+ end
182
+
183
+ before do
184
+ deps.each do |dep_name|
185
+ Rake::Task.define_task dep_name
186
+ end
187
+ end
188
+
189
+ include_examples 'defines the target task'
190
+ include_examples 'yields to the block'
191
+ include_examples 'invokes all dependencies when invoked'
192
+ end
193
+ end
194
+
195
+ context 'with args' do
196
+ let(:args) {%i[first_arg second_arg third_arg]}
197
+ let(:expected_args) do
198
+ ### #=> {:first_arg => :first_value, ...}
199
+ Hash[args.zip(%i[first_value second_value third_value])]
200
+ end
201
+
202
+ context 'without deps' do
203
+ let(:deps) {[]}
204
+
205
+ before :all do
206
+ Rake.application = Rake::Application.new
207
+ end
208
+
209
+ include_examples 'defines the target task'
210
+ include_examples 'yields to the block'
211
+ end
212
+
213
+ context 'with deps' do
214
+ let(:deps) {%i[first_dep second_dep third_dep]}
215
+
216
+ before :all do
217
+ Rake.application = Rake::Application.new
218
+ end
219
+
220
+ before do
221
+ deps.each do |dep_name|
222
+ Rake::Task.define_task dep_name
223
+ end
224
+ end
225
+
226
+ include_examples 'defines the target task'
227
+ include_examples 'yields to the block'
228
+ include_examples 'invokes all dependencies when invoked'
229
+ end
230
+ end
231
+ end
232
+
233
+ context 'with aliases' do
234
+ let(:alias_names) {%i[first_alias second_alias third_alias]}
235
+
236
+ context 'without args' do
237
+ let(:args) {[]}
238
+ let(:expected_args) {{}}
239
+
240
+ context 'without deps' do
241
+ let(:deps) {[]}
242
+
243
+ before :all do
244
+ Rake.application = Rake::Application.new
245
+ end
246
+
247
+ include_examples 'defines the target task'
248
+ include_examples 'gets invoked via any alias'
249
+ end
250
+
251
+ context 'with deps' do
252
+ let(:deps) {%i[first_dep second_dep third_dep]}
253
+
254
+ before :all do
255
+ Rake.application = Rake::Application.new
256
+ end
257
+
258
+ before do
259
+ deps.each do |dep_name|
260
+ Rake::Task.define_task dep_name
261
+ end
262
+ end
263
+
264
+ include_examples 'defines the target task'
265
+ include_examples 'gets invoked via any alias'
266
+ include_examples 'invokes all dependencies when invoked'
267
+ include_examples 'invokes all dependencies when invoked via any alias'
268
+ end
269
+ end
270
+
271
+ context 'with args' do
272
+ let(:args) {%i[first_arg second_arg third_arg]}
273
+ let(:expected_args) do
274
+ ### #=> {:first_arg => :first_value, ...}
275
+ Hash[args.zip(%i[first_value second_value third_value])]
276
+ end
277
+
278
+ context 'without deps' do
279
+ let(:deps) {[]}
280
+
281
+ before :all do
282
+ Rake.application = Rake::Application.new
283
+ end
284
+
285
+ include_examples 'defines the target task'
286
+ include_examples 'gets invoked with args via any alias'
287
+ end
288
+
289
+ context 'with deps' do
290
+ let(:deps) {%i[first_dep second_dep third_dep]}
291
+
292
+ before :all do
293
+ Rake.application = Rake::Application.new
294
+ end
295
+
296
+ before do
297
+ deps.each do |dep_name|
298
+ Rake::Task.define_task dep_name
299
+ end
300
+ end
301
+
302
+ include_examples 'defines the target task'
303
+ include_examples 'gets invoked with args via any alias'
304
+ include_examples 'invokes all dependencies when invoked'
305
+ include_examples 'invokes all dependencies when invoked via any alias'
306
+ end
307
+ end
308
+ end
309
+ end
310
+ end
311
+ end
@@ -0,0 +1,353 @@
1
+ require 'openssl'
2
+ require_relative '../helpers/storj_options'
3
+ include LibStorjTest
4
+
5
+ RSpec.describe LibStorj::Env do
6
+ let(:bucket_class) {::LibStorj::Ext::Storj::Bucket}
7
+ let(:file_class) {::LibStorj::Ext::Storj::File}
8
+ let(:instance) do
9
+ described_class.new(*default_options)
10
+ end
11
+
12
+ after :each do
13
+ # (see https://github.com/Storj/ruby-libstorj/issues/2)
14
+ # Process.RLIMIT_MEMLOCK #=> 8
15
+ instance.destroy
16
+ end
17
+
18
+ describe 'new' do
19
+ it 'returns an instance of the described class' do
20
+ expect(instance).to be_an_instance_of(described_class)
21
+ end
22
+ end
23
+
24
+ describe '@storj_env' do
25
+ it 'does not point to NULL' do
26
+ expect(instance.storj_env.to_ptr).not_to equal(FFI::Pointer::NULL)
27
+ end
28
+
29
+ it 'is an instance of the struct wrapper corresponding to its C analogue' do
30
+ expect(instance.storj_env).to be_an_instance_of(described_class::C_ANALOGUE)
31
+ end
32
+ end
33
+
34
+ describe '#get_info' do
35
+ context 'without error' do
36
+ it 'yields with an nil error and hash response' do
37
+ yielded = false
38
+ instance.get_info do |error, info|
39
+ expect(error).to be(nil)
40
+ expect(info).to be_an_instance_of(Hash)
41
+ yielded = true
42
+ end
43
+
44
+ wait_for(yielded).to be_truthy
45
+ end
46
+ end
47
+
48
+ context 'with error' do
49
+ it 'yields with an error and nil response' do
50
+ instance.storj_env[:bridge_options][:host].write_string 'a.nonexistant.example'
51
+
52
+ expect do |block|
53
+ instance.get_info(&block)
54
+ end.to yield_with_args(/couldn't resolve host name/i, nil)
55
+ end
56
+ end
57
+ end
58
+
59
+ describe '#get_buckets' do
60
+ context 'without error' do
61
+ let(:bucket_names) {%w[bucket1 bucket2 bucket3]}
62
+
63
+ before do
64
+ bucket_names.each &instance.method(:create_bucket)
65
+ end
66
+
67
+ after do
68
+ bucket_names.each &instance.method(:delete_bucket)
69
+ end
70
+
71
+ it 'yields a nil error and an array of buckets' do
72
+ expect do |block| #{|block| instance.get_bucekts(&block)}.to yield_with_args
73
+ instance.get_buckets do |error, buckets|
74
+ expect(error).to be(nil)
75
+ expect(buckets.length).to be(bucket_names.length)
76
+ expect(buckets).to satisfy do |buckets|
77
+ bucket_names = buckets.map(&:name)
78
+ names_match = bucket_names.all? &bucket_names.method(:include?)
79
+ are_all_buckets = buckets.all? do |bucket|
80
+ bucket.is_a? bucket_class
81
+ end
82
+
83
+ names_match && are_all_buckets
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ context 'with error' do
91
+ it 'yields with a non-nil error value and nil response' do
92
+ # (see https://tools.ietf.org/html/rfc2606)
93
+ instance.storj_env[:bridge_options][:host].write_string 'a.nonexistant.example'
94
+
95
+ expect do |block|
96
+ instance.get_buckets(&block)
97
+ end.to yield_with_args(/couldn't resolve host name/i, nil)
98
+ end
99
+ end
100
+ end
101
+
102
+ describe '#create_bucket' do
103
+ let(:test_bucket_name) {'test'}
104
+
105
+ # TODO: refactor error contexts into shared example group 'api request'
106
+ context 'without error' do
107
+ let(:bucket_class) {::LibStorj::Ext::Storj::Bucket}
108
+
109
+ def clean_buckets(&block)
110
+ catch(:no_bucket) do
111
+ return get_test_bucket_id do |id|
112
+ instance.delete_bucket(id, &block)
113
+ end
114
+ end
115
+
116
+ yield if block_given?
117
+ end
118
+
119
+ after do
120
+ clean_buckets
121
+ end
122
+
123
+ it 'yields with nil error and the new bucket' do
124
+ clean_buckets do
125
+ instance.create_bucket(test_bucket_name) do |error, bucket|
126
+ expect(error).to be(nil)
127
+ expect(bucket).to be_an_instance_of(bucket_class)
128
+ end
129
+ sleep 3
130
+ end
131
+ end
132
+ end
133
+
134
+ context 'with error' do
135
+ describe 'external error' do
136
+ it 'yields with a non-nil error value and nil response' do
137
+ # (see https://tools.ietf.org/html/rfc2606)
138
+ instance.storj_env[:bridge_options][:host].write_string 'a.nonexistant.example'
139
+
140
+ expect do |block|
141
+ instance.create_bucket(test_bucket_name, &block)
142
+ end.to yield_with_args(/couldn't resolve host name/i, nil)
143
+ end
144
+ end
145
+
146
+ describe 'bucket name in use' do
147
+ before do
148
+ instance.create_bucket(test_bucket_name)
149
+ end
150
+
151
+ it 'yields with a bucket name in use error' do
152
+ # (see https://tools.ietf.org/html/rfc2606)
153
+ expect do |block|
154
+ instance.create_bucket(test_bucket_name, &block)
155
+ end.to yield_with_args(/name already used by another bucket/i, nil)
156
+ end
157
+ end
158
+ end
159
+ end
160
+
161
+ describe '#delete_bucket' do
162
+ let(:test_bucket_name) {'test'}
163
+
164
+ before :each do
165
+ instance.create_bucket(test_bucket_name)
166
+ end
167
+
168
+ # TODO: refactor error contexts into shared example group 'api request'
169
+ context 'without error' do
170
+ let(:bucket_class) {::LibStorj::Ext::Storj::Bucket}
171
+
172
+ it 'yields with nil error' do
173
+ get_test_bucket_id do |id|
174
+ instance.delete_bucket(id) do |error|
175
+ expect(error).to be(nil)
176
+ end
177
+ end
178
+ end
179
+ end
180
+
181
+ context 'with error' do
182
+ describe 'external error' do
183
+ it 'yields with a non-nil error value and nil response' do
184
+ # (see https://tools.ietf.org/html/rfc2606)
185
+ instance.storj_env[:bridge_options][:host].write_string 'a.nonexistant.example'
186
+
187
+ expect do |block|
188
+ instance.delete_bucket(test_bucket_name, &block)
189
+ end.to yield_with_args(/couldn't resolve host name/i)
190
+ end
191
+ end
192
+
193
+ xdescribe 'malformed id error' do
194
+ let(:malformed_bucket_id) {'this is not what a bucket id looks like'}
195
+
196
+ it 'yields with a malformed id error' do
197
+ instance.delete_bucket(malformed_bucket_id) do |error|
198
+ expect(error).to match(/bucket id is malformed/i)
199
+ end
200
+ end
201
+ end
202
+ end
203
+ end
204
+
205
+ describe '#store_file' do
206
+ let(:test_bucket_name) {'test'}
207
+ let(:test_file_name) {'test.data'}
208
+ let(:test_file_path) {File.join %W(#{__dir__} .. helpers upload.data)}
209
+ let(:options) {{
210
+ file_name: test_file_name
211
+ }}
212
+ let(:progress_proc) {Proc.new do
213
+ # ensure this block is called
214
+ end}
215
+
216
+ before do
217
+ done = nil
218
+ instance.create_bucket test_bucket_name do
219
+ done = true
220
+ end
221
+
222
+ wait_for(done).to be_truthy
223
+ end
224
+
225
+ context 'without error' do
226
+ it 'uploads a file of the same size to the the specified bucket' do
227
+ get_test_bucket_id do |test_bucket_id|
228
+ state = instance.store_file bucket_id: test_bucket_id,
229
+ file_path: test_file_path,
230
+ options: options,
231
+ progress_proc: progress_proc do |file_id|
232
+ if file_id.nil?
233
+ fail %q(Please ensure the test file doesn't already exist; TODO: automate this)
234
+ end
235
+
236
+ expect(file_id).to match(/\w+/i)
237
+ # ensure this block is called
238
+ end
239
+ end
240
+ end
241
+ end
242
+ end
243
+
244
+ describe '#resolve_file' do
245
+ let(:test_bucket_name) {'test'}
246
+ let(:test_file_name) {'test.data'}
247
+ let(:test_file_path) {File.join %W(#{__dir__} .. helpers download.data)}
248
+ let(:expected_hash) {File.read test_file_path}
249
+ let(:test_file_hash) {
250
+ data = File.read test_file_path
251
+ OpenSSL::Digest::SHA256.hexdigest data
252
+ }
253
+ let(:progress_proc) {Proc.new do
254
+ # ensure this block gets called
255
+ end}
256
+
257
+ after :each do
258
+ if File.exists? test_file_path
259
+ File.unlink test_file_path
260
+ end
261
+ end
262
+
263
+ context 'without error' do
264
+ it 'downloads a file with the same sha256sum as the uploaded test data' do
265
+ get_test_file_id do |test_bucket_id, test_file_id|
266
+ instance.resolve_file bucket_id: test_bucket_id,
267
+ file_id: test_file_id,
268
+ file_path: test_file_path,
269
+ progress_proc: progress_proc do |*args|
270
+ # ensure this block is called
271
+ expect(expected_hash).to equal(test_file_hash)
272
+ end
273
+ end
274
+ end
275
+ end
276
+ end
277
+
278
+ describe '#list_files' do
279
+ #NB: `#list_files` test requires files be added to the `test` bucket;
280
+ #TODO: automate this'
281
+ let(:test_bucket_name) {'test'}
282
+
283
+ context 'without error' do
284
+ it 'yields with a nil error and an array of files' do
285
+ get_test_bucket_id do |test_bucket_id|
286
+ instance.list_files(test_bucket_id) do |error, files|
287
+ expect(error).to be(nil)
288
+ expect(files).to be_an_instance_of(Array)
289
+ expect(files).to satisfy do |files|
290
+ files.all? {|file| file.is_a? file_class}
291
+ end
292
+ end
293
+ end
294
+ end
295
+ end
296
+
297
+ context 'with error' do
298
+ describe 'external error' do
299
+ it 'yields with a non-nil error value and nil response' do
300
+ # (see https://tools.ietf.org/html/rfc2606)
301
+ instance.storj_env[:bridge_options][:host].write_string 'a.nonexistant.example'
302
+
303
+ expect do |block|
304
+ instance.list_files(test_bucket_name, &block)
305
+ end.to yield_with_args(/couldn't resolve host name/i, nil)
306
+ end
307
+ end
308
+
309
+ xdescribe 'malformed id error' do
310
+ let(:malformed_bucket_id) {'this is not what a bucket id looks like'}
311
+
312
+ it 'yields with a malformed id error' do
313
+ instance.list_files(malformed_bucket_id) do |error|
314
+ expect(error).to match(/bucket id is malformed/i)
315
+ end
316
+ end
317
+ end
318
+ end
319
+ end
320
+
321
+ describe '#delete_file' do
322
+ let(:test_bucket_name) {'test'}
323
+ let(:test_file_name) {'test.data'}
324
+ let(:test_file_path) {File.join %W(#{__dir__} .. helpers upload.data)}
325
+
326
+ context 'without error' do
327
+ it 'yields with nil error and the new bucket' do
328
+ get_test_file_id do |test_file_id, test_bucket_id|
329
+ instance.delete_file test_bucket_id, test_file_id do |error|
330
+ expect(error).to be_nil
331
+ instance.list_files test_bucket_id do |error, files|
332
+ file_was_deleted = files.nil? || files.any {|file| file.name == test_file_name}
333
+ expect(file_was_deleted).to be_truthy
334
+ end
335
+ end
336
+ end
337
+ end
338
+ end
339
+
340
+ context 'with error' do
341
+ describe 'external error' do
342
+ it 'yields with a non-nil error value and nil response' do
343
+ # (see https://tools.ietf.org/html/rfc2606)
344
+ instance.storj_env[:bridge_options][:host].write_string 'a.nonexistant.example'
345
+
346
+ expect do |block|
347
+ instance.create_bucket(test_bucket_name, &block)
348
+ end.to yield_with_args(/couldn't resolve host name/i, nil)
349
+ end
350
+ end
351
+ end
352
+ end
353
+ end