ruby-manta 1.2.0 → 2.0.0

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.
@@ -0,0 +1,3 @@
1
+ module RubyManta
2
+ VERSION = '2.0.0'
3
+ end
@@ -1,26 +1,30 @@
1
- require File.expand_path('../lib/version', __FILE__)
1
+ require File.expand_path('../lib/ruby-manta/version', __FILE__)
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'ruby-manta'
5
- s.version = MantaClient::LIB_VERSION
6
- s.date = '2013-10-24'
5
+ s.version = RubyManta::VERSION
6
+ s.date = '2015-03-15'
7
7
  s.summary = "Interface for Joyent's Manta service."
8
- s.description = "A simple low-abstraction layer which communicates with Joyent's Manta service."
8
+ s.description = "A simple low-abstraction layer which communicates with Joyent's Manta service."
9
9
  s.authors = ['Joyent']
10
10
  s.email = 'marsell@joyent.com'
11
11
  s.homepage = 'http://github.com/joyent/ruby-manta/'
12
12
  s.license = 'MIT'
13
13
 
14
- s.add_dependency('net-ssh', '>= 2.6.0')
15
- s.add_dependency('httpclient', '>= 2.3.0.1')
14
+ s.add_dependency 'net-ssh', '>= 2.6.0'
15
+ s.add_dependency 'httpclient', '>= 2.6.0.1'
16
+
17
+ s.add_development_dependency 'rake'
18
+ s.add_development_dependency 'minitest', '~> 5.5.1'
16
19
 
17
20
  s.files = ['LICENSE',
18
21
  'README.md',
19
22
  'ruby-manta.gemspec',
20
23
  'example.rb',
21
- 'lib/version.rb',
22
24
  'lib/ruby-manta.rb',
23
- 'tests/test_ruby-manta.rb']
25
+ 'lib/ruby-manta/version.rb',
26
+ 'lib/ruby-manta/manta_client.rb',
27
+ 'test/unit/manta_client_test.rb']
24
28
 
25
29
  s.test_files = s.files.grep(%r{^test})
26
30
  s.require_paths = %w{lib}
@@ -1,33 +1,38 @@
1
1
  require 'minitest/autorun'
2
- require 'httpclient'
3
- require File.expand_path('../../lib/ruby-manta', __FILE__)
2
+ require_relative '../../lib/ruby-manta'
4
3
 
5
-
6
-
7
- class TestMantaClient < MiniTest::Unit::TestCase
4
+ class TestMantaClient < Minitest::Test
8
5
  @@client = nil
9
6
  @@user = nil
10
7
 
11
8
  def setup
12
9
  if ! @@client
13
- host = ENV['HOST']
14
- key = ENV['KEY' ]
15
- @@user = ENV['USER']
10
+ host = ENV['MANTA_URL']
11
+ key = ENV['MANTA_KEY' ]
12
+ @@user = ENV['MANTA_USER']
16
13
 
17
14
  unless host && key && @@user
18
15
  $stderr.puts 'Require HOST, USER and KEY env variables to run tests.'
19
- $stderr.puts 'E.g. USER=john KEY=~/.ssh/john HOST=https://us-east.manta.joyent.com ruby tests/test_ruby-manta.rb'
16
+ $stderr.puts 'E.g. MANTA_USER=john MANTA_KEY=~/.ssh/john MANTA_URL=https://us-east.manta.joyent.com bundle exec rake test'
20
17
  exit
21
18
  end
22
19
 
23
20
  priv_key_data = File.read(key)
24
- @@client = MantaClient.new(host, @@user, priv_key_data,
25
- :disable_ssl_verification => true)
21
+
22
+ opts = {
23
+ disable_ssl_verification: true
24
+ }
25
+
26
+ if ENV.key?('MANTA_SUBUSER')
27
+ opts[:subuser] = ENV['MANTA_SUBUSER']
28
+ end
29
+
30
+ @@client = RubyManta::MantaClient.new(host, @@user, priv_key_data, opts)
26
31
 
27
32
  @@test_dir_path = '/%s/stor/ruby-manta-test' % @@user
28
33
  end
29
34
 
30
- teardown()
35
+ teardown()
31
36
 
32
37
  @@client.put_directory(@@test_dir_path)
33
38
  end
@@ -46,7 +51,7 @@ class TestMantaClient < MiniTest::Unit::TestCase
46
51
  end
47
52
 
48
53
  @@client.delete_directory(@@test_dir_path)
49
- rescue MantaClient::ResourceNotFound
54
+ rescue RubyManta::MantaClient::ResourceNotFound
50
55
  end
51
56
 
52
57
 
@@ -152,7 +157,7 @@ class TestMantaClient < MiniTest::Unit::TestCase
152
157
  begin
153
158
  @@client.delete_directory(@@test_dir_path)
154
159
  assert false
155
- rescue MantaClient::DirectoryNotEmpty
160
+ rescue RubyManta::MantaClient::DirectoryNotEmpty
156
161
  end
157
162
 
158
163
  @@client.delete_directory(@@test_dir_path + '/dir1')
@@ -166,19 +171,23 @@ class TestMantaClient < MiniTest::Unit::TestCase
166
171
  begin
167
172
  @@client.list_directory(@@test_dir_path + '/does-not-exist')
168
173
  assert false
169
- rescue MantaClient::ResourceNotFound
174
+ rescue RubyManta::MantaClient::ResourceNotFound
170
175
  end
171
176
 
172
177
  begin
173
178
  @@client.put_directory(@@test_dir_path + '/dir1')
174
179
  assert false
175
- rescue MantaClient::DirectoryDoesNotExist
180
+ rescue RubyManta::MantaClient::DirectoryDoesNotExist
176
181
  end
177
182
  end
178
183
 
179
184
 
180
185
 
181
186
  def test_root_directory
187
+ if ENV['MANTA_SUBUSER']
188
+ skip("Subusers can't get access to the root directory")
189
+ end
190
+
182
191
  result, headers = @@client.list_directory('/' + @@user)
183
192
  assert headers.is_a? Hash
184
193
  assert_equal result.size, 4
@@ -212,19 +221,19 @@ class TestMantaClient < MiniTest::Unit::TestCase
212
221
  @@client.put_object(@@test_dir_path + '/obj1', 'bar-data',
213
222
  :durability_level => 999)
214
223
  assert false
215
- rescue MantaClient::InvalidDurabilityLevel
224
+ rescue RubyManta::MantaClient::InvalidDurabilityLevel
216
225
  end
217
226
 
218
227
  begin
219
228
  @@client.get_object(@@test_dir_path + '/does-not-exist')
220
229
  assert false
221
- rescue MantaClient::ResourceNotFound
230
+ rescue RubyManta::MantaClient::ResourceNotFound
222
231
  end
223
232
 
224
233
  begin
225
234
  @@client.delete_object(@@test_dir_path + '/does-not-exist')
226
235
  assert false
227
- rescue MantaClient::ResourceNotFound
236
+ rescue RubyManta::MantaClient::ResourceNotFound
228
237
  end
229
238
 
230
239
  result, headers = @@client.delete_object(@@test_dir_path + '/obj1')
@@ -235,7 +244,9 @@ class TestMantaClient < MiniTest::Unit::TestCase
235
244
 
236
245
 
237
246
  def test_public
238
- host = ENV['HOST'].gsub('https', 'http')
247
+ fail 'MANTA_URL must be specified' unless ENV['MANTA_URL']
248
+
249
+ host = ENV['MANTA_URL'].gsub('https', 'http')
239
250
  test_pub_dir_path = '/%s/public/ruby-manta-test' % @@user
240
251
 
241
252
  @@client.put_directory(test_pub_dir_path)
@@ -303,7 +314,7 @@ class TestMantaClient < MiniTest::Unit::TestCase
303
314
  def test_signed_urls
304
315
 
305
316
  client = HTTPClient.new
306
-
317
+
307
318
  put_url = @@client.gen_signed_url(Time.now + 500000, [:put, :options],
308
319
  @@test_dir_path + '/obj1')
309
320
 
@@ -312,10 +323,10 @@ class TestMantaClient < MiniTest::Unit::TestCase
312
323
  'Access-Control-Request-Method' => 'PUT'
313
324
  })
314
325
 
315
- assert_equal result.status, 200
326
+ assert_equal 200, result.status, "Signed URL Failed: #{result.dump}"
316
327
 
317
328
  result = client.put("https://" + put_url, 'foo-data', { 'Content-Type' => 'text/plain' })
318
- assert_equal result.status, 204
329
+ assert_equal 204, result.status
319
330
 
320
331
  url = @@client.gen_signed_url(Time.now + 500000, :get,
321
332
  @@test_dir_path + '/obj1')
@@ -324,16 +335,16 @@ class TestMantaClient < MiniTest::Unit::TestCase
324
335
  assert_equal result.body, 'foo-data'
325
336
  end
326
337
 
327
-
328
-
329
- def test_snaplinks
338
+ def test_snaplink_not_found
330
339
  begin
331
340
  @@client.put_snaplink(@@test_dir_path + '/obj1',
332
341
  @@test_dir_path + '/obj2')
333
342
  assert false
334
- rescue MantaClient::SourceObjectNotFound
343
+ rescue RubyManta::MantaClient::SourceObjectNotFound
335
344
  end
345
+ end
336
346
 
347
+ def test_snaplinks
337
348
  @@client.put_object(@@test_dir_path + '/obj1', 'foo-data')
338
349
 
339
350
  result, headers = @@client.put_snaplink(@@test_dir_path + '/obj1',
@@ -342,27 +353,35 @@ class TestMantaClient < MiniTest::Unit::TestCase
342
353
  assert headers.is_a? Hash
343
354
 
344
355
  @@client.put_object(@@test_dir_path + '/obj1', 'bar-data')
345
-
356
+
346
357
  result, _ = @@client.get_object(@@test_dir_path + '/obj1')
347
358
  assert_equal result, 'bar-data'
348
-
359
+
349
360
  result, _ = @@client.get_object(@@test_dir_path + '/obj2')
350
361
  assert_equal result, 'foo-data'
351
362
  end
352
363
 
353
364
 
354
365
 
355
- def test_reports
366
+ def test_referencing_invalid_reports_dir
356
367
  begin
357
368
  @@client.list_directory('/%s/reportse' % @@user)
358
369
  assert fail
359
370
  rescue ArgumentError
371
+ assert true
360
372
  end
373
+ end
361
374
 
375
+
376
+
377
+ def test_reports
362
378
  result, headers = @@client.list_directory('/%s/reports' % @@user)
363
379
  assert headers.is_a? Hash
364
380
  assert result.is_a? Array
365
- assert result.length > 0
381
+
382
+ if result.length < 1
383
+ skip 'Usage directory has not been created yet'
384
+ end
366
385
 
367
386
  result, headers = @@client.list_directory('/%s/reports/usage' % @@user)
368
387
  assert headers.is_a? Hash
@@ -386,7 +405,7 @@ class TestMantaClient < MiniTest::Unit::TestCase
386
405
  @@client.put_object(@@test_dir_path + '/obj1', 'bar-data',
387
406
  :if_modified_since => modified)
388
407
  assert fail
389
- rescue MantaClient::PreconditionFailed
408
+ rescue RubyManta::MantaClient::PreconditionFailed
390
409
  end
391
410
 
392
411
  result, headers = @@client.get_object(@@test_dir_path + '/obj1')
@@ -406,7 +425,7 @@ class TestMantaClient < MiniTest::Unit::TestCase
406
425
  @@client.put_object(@@test_dir_path + '/obj1', 'foo-data',
407
426
  :if_none_match => etag)
408
427
  assert false
409
- rescue MantaClient::PreconditionFailed
428
+ rescue RubyManta::MantaClient::PreconditionFailed
410
429
  end
411
430
 
412
431
  result, headers = @@client.get_object(@@test_dir_path + '/obj1')
@@ -423,7 +442,7 @@ class TestMantaClient < MiniTest::Unit::TestCase
423
442
  begin
424
443
  @@client.get_object(@@test_dir_path + '/obj1', :if_match => etag)
425
444
  assert false
426
- rescue MantaClient::PreconditionFailed
445
+ rescue RubyManta::MantaClient::PreconditionFailed
427
446
  end
428
447
 
429
448
  etag = headers['Etag']
@@ -449,7 +468,7 @@ class TestMantaClient < MiniTest::Unit::TestCase
449
468
  @@test_dir_path + '/obj2',
450
469
  :if_none_match => etag)
451
470
  assert false
452
- rescue MantaClient::PreconditionFailed
471
+ rescue RubyManta::MantaClient::PreconditionFailed
453
472
  end
454
473
 
455
474
  result, headers = @@client.put_snaplink(@@test_dir_path + '/obj1',
@@ -463,7 +482,7 @@ class TestMantaClient < MiniTest::Unit::TestCase
463
482
  @@test_dir_path + '/obj3',
464
483
  :if_modified_since => modified)
465
484
  assert false
466
- rescue MantaClient::PreconditionFailed
485
+ rescue RubyManta::MantaClient::PreconditionFailed
467
486
  end
468
487
 
469
488
  @@client.put_snaplink(@@test_dir_path + '/obj1', @@test_dir_path + '/obj3',
@@ -479,7 +498,7 @@ class TestMantaClient < MiniTest::Unit::TestCase
479
498
  begin
480
499
  @@client.delete_object(@@test_dir_path + '/obj1', :if_none_match => etag)
481
500
  assert false
482
- rescue MantaClient::PreconditionFailed
501
+ rescue RubyManta::MantaClient::PreconditionFailed
483
502
  end
484
503
 
485
504
  result, _ = @@client.delete_object(@@test_dir_path + '/obj1', :if_match => etag)
@@ -490,13 +509,13 @@ class TestMantaClient < MiniTest::Unit::TestCase
490
509
  begin
491
510
  @@client.delete_object(@@test_dir_path + '/obj3', :if_unmodified_since => Time.now - 10000)
492
511
  assert false
493
- rescue MantaClient::PreconditionFailed
512
+ rescue RubyManta::MantaClient::PreconditionFailed
494
513
  end
495
514
 
496
515
  begin
497
516
  @@client.delete_object(@@test_dir_path + '/obj3', :if_modified_since => Time.now)
498
517
  assert false
499
- rescue MantaClient::PreconditionFailed
518
+ rescue RubyManta::MantaClient::PreconditionFailed
500
519
  end
501
520
 
502
521
  @@client.delete_object(@@test_dir_path + '/obj3', :if_unmodified_since => Time.now)
@@ -507,7 +526,7 @@ class TestMantaClient < MiniTest::Unit::TestCase
507
526
  begin
508
527
  @@client.get_object(@@test_dir_path + obj_name)
509
528
  assert false
510
- rescue MantaClient::ResourceNotFound
529
+ rescue RubyManta::MantaClient::ResourceNotFound
511
530
  end
512
531
  end
513
532
  end
@@ -523,7 +542,12 @@ class TestMantaClient < MiniTest::Unit::TestCase
523
542
 
524
543
  result.each do |entry|
525
544
  path = '/%s/jobs/%s' % [ @@user, entry['name'] ]
526
- @@client.cancel_job(path)
545
+
546
+ begin
547
+ @@client.cancel_job(path)
548
+ rescue => e
549
+ warn("Unable to cancel jobs: #{e.message}")
550
+ end
527
551
  end
528
552
 
529
553
  begin
@@ -533,7 +557,12 @@ class TestMantaClient < MiniTest::Unit::TestCase
533
557
  end
534
558
 
535
559
  result, headers = @@client.list_jobs(:running)
536
- assert_equal result, []
560
+
561
+ unless result.empty?
562
+ skip "We can't run a job test if we have jobs running because it becomes " +
563
+ 'a difficult coordination problem.'
564
+ end
565
+
537
566
  assert headers.is_a? Hash
538
567
 
539
568
  path, headers = @@client.create_job({ :phases => [{ :exec => 'grep foo' }] })
@@ -599,31 +628,31 @@ class TestMantaClient < MiniTest::Unit::TestCase
599
628
  begin
600
629
  @@client.get_job_input(path + 'a')
601
630
  assert false
602
- rescue MantaClient::ResourceNotFound
631
+ rescue RubyManta::MantaClient::ResourceNotFound
603
632
  end
604
633
 
605
634
  begin
606
635
  @@client.get_job_output(path + 'a')
607
636
  assert false
608
- rescue MantaClient::ResourceNotFound
637
+ rescue RubyManta::MantaClient::ResourceNotFound
609
638
  end
610
639
 
611
640
  begin
612
641
  @@client.get_job_failures(path + 'a')
613
642
  assert false
614
- rescue MantaClient::ResourceNotFound
643
+ rescue RubyManta::MantaClient::ResourceNotFound
615
644
  end
616
645
 
617
646
  begin
618
647
  @@client.get_job_errors(path + 'a')
619
648
  assert false
620
- rescue MantaClient::ResourceNotFound
649
+ rescue RubyManta::MantaClient::ResourceNotFound
621
650
  end
622
651
 
623
652
  begin
624
653
  @@client.end_job_input(path + 'a')
625
654
  assert false
626
- rescue MantaClient::ResourceNotFound
655
+ rescue RubyManta::MantaClient::ResourceNotFound
627
656
  end
628
657
 
629
658
  result, headers = @@client.end_job_input(path)
@@ -669,7 +698,63 @@ class TestMantaClient < MiniTest::Unit::TestCase
669
698
  begin
670
699
  @@client.cancel_job(path)
671
700
  assert fail
672
- rescue MantaClient::InvalidJobState
701
+ rescue RubyManta::MantaClient::InvalidJobState
702
+ end
703
+ end
704
+
705
+ def test_find
706
+ copies = 15
707
+
708
+ begin
709
+ copies.times do |i|
710
+ @@client.put_object(@@test_dir_path + "/find_object_#{i}", 'test_find')
711
+ end
712
+
713
+ results = @@client.find(@@test_dir_path)
714
+
715
+ assert_equal copies, results.length
716
+
717
+ copies.times do |i|
718
+ assert results.include? @@test_dir_path + "/find_object_#{i}"
719
+ end
720
+ ensure
721
+ copies.times do |i|
722
+ result, headers = @@client.delete_object(@@test_dir_path + "/find_object_#{i}")
723
+ assert_equal result, true
724
+ assert headers.is_a? Hash
725
+ end
726
+ end
727
+ end
728
+
729
+ def test_find_regex
730
+ copies = 15
731
+
732
+ begin
733
+ copies.times do |i|
734
+ @@client.put_object(@@test_dir_path + "/find_object_#{i}", 'test_find_regex')
735
+ end
736
+
737
+ @@client.put_object(@@test_dir_path + '/dog_biscuit', 'dont match me')
738
+
739
+ results = @@client.find(@@test_dir_path, regex: 'find_object_.*')
740
+
741
+ assert_equal copies, results.length
742
+
743
+ copies.times do |i|
744
+ assert results.include? @@test_dir_path + "/find_object_#{i}"
745
+ end
746
+
747
+ refute results.include? @@test_dir_path + '/dog_biscuit'
748
+ ensure
749
+ copies.times do |i|
750
+ result, headers = @@client.delete_object(@@test_dir_path + "/find_object_#{i}")
751
+ assert_equal result, true
752
+ assert headers.is_a? Hash
753
+ end
754
+
755
+ result, headers = @@client.delete_object(@@test_dir_path + "/dog_biscuit")
756
+ assert_equal result, true
757
+ assert headers.is_a? Hash
673
758
  end
674
759
  end
675
760
  end