sndacs 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,180 @@
1
+ require 'spec_helper'
2
+
3
+ module Sndacs
4
+
5
+ describe Bucket do
6
+ before :all do
7
+ @service = Sndacs::Service.new
8
+ end
9
+
10
+ before :each do
11
+ sleep 1 # for delay
12
+
13
+ @bucket_spec_name = 'bucket-spec-test-' << Time.now.to_i.to_s
14
+ @bucket_spec_region = 'huabei-1'
15
+ @bucket_spec = Bucket.send(:new, @service, @bucket_spec_name, @bucket_spec_region)
16
+ end
17
+
18
+ context "#retrieve" do
19
+ it "should works" do
20
+ @bucket_spec.save
21
+
22
+ bucket = @bucket_spec.retrieve
23
+ bucket.should == @bucket_spec
24
+
25
+ @bucket_spec.destroy
26
+ end
27
+
28
+ it "should raise Sndacs::Error::NoSuchBucket if bucket does not exist" do
29
+ lambda {
30
+ @bucket_spec.retrieve
31
+ }.should raise_error(Sndacs::Error::NoSuchBucket)
32
+ end
33
+ end
34
+
35
+ context "#location" do
36
+ before :each do
37
+ @bucket_spec.save
38
+ end
39
+
40
+ after :each do
41
+ @bucket_spec.destroy
42
+ end
43
+
44
+ it "should works" do
45
+ bucket_location = @bucket_spec.location
46
+
47
+ bucket_location.should == @bucket_spec_region
48
+ end
49
+
50
+ it "should reload location with force=true" do
51
+ @bucket_spec.should_receive(:location_constraint).and_return(@bucket_spec_region)
52
+
53
+ @bucket_spec.location(true)
54
+ end
55
+ end
56
+
57
+ context "#save" do
58
+ it "should works" do
59
+ @bucket_spec.should_receive(:create_bucket_configuration)
60
+
61
+ @bucket_spec.save
62
+ end
63
+
64
+ it "should raise Sndacs::Error::BucketAlreadyExists if bucket alreay exist" do
65
+ @bucket_spec.save
66
+
67
+ lambda {
68
+ @bucket_spec.save
69
+ }.should raise_error(Sndacs::Error::BucketAlreadyExists)
70
+
71
+ @bucket_spec.destroy
72
+ end
73
+ end
74
+
75
+ context "#destroy" do
76
+ before :each do
77
+ @bucket_spec.save
78
+ end
79
+
80
+ it "should works" do
81
+ #@bucket_spec.should_receive(:delete_bucket)
82
+
83
+ @bucket_spec.destroy.should == true
84
+ end
85
+
86
+ it "should destroy bucket whether it has objects in it with force=true" do
87
+ bucket_object = @bucket_spec.object("object-spec-test-#{Time.now.to_i.to_s}")
88
+ bucket_object.content = 'Hello,world!'
89
+ bucket_object.save
90
+
91
+ @bucket_spec.destroy(true).should == true
92
+ end
93
+
94
+ it "should raise Sndacs::Error::NoSuchBucket if bucket doest not exist" do
95
+ @bucket_spec.destroy
96
+
97
+ lambda {
98
+ @bucket_spec.destroy
99
+ }.should raise_error(Sndacs::Error::NoSuchBucket)
100
+ end
101
+
102
+ it "should raise Sndacs::Error::BucketNotEmpty if bucket has objects in it" do
103
+ bucket_object = @bucket_spec.object("object-spec-test-#{Time.now.to_i.to_s}")
104
+ bucket_object.content = 'Hello,world!'
105
+ bucket_object.save
106
+
107
+ lambda {
108
+ @bucket_spec.destroy
109
+ }.should raise_error(Sndacs::Error::BucketNotEmpty)
110
+
111
+ bucket_object.destroy
112
+
113
+ @bucket_spec.destroy
114
+ end
115
+ end
116
+
117
+ context "#exists?" do
118
+ it "should return true if bucket exists" do
119
+ @bucket_spec.save
120
+
121
+ @bucket_spec.exists?.should == true
122
+
123
+ @bucket_spec.destroy
124
+ end
125
+
126
+ it "should return false if bucket does not exist" do
127
+ @bucket_spec.exists?.should == false
128
+ end
129
+ end
130
+
131
+ context "#vhost?" do
132
+ xit "should works" do
133
+ end
134
+ end
135
+
136
+ context "#host" do
137
+ it "should obey @location when @location is supplied" do
138
+ @bucket_spec.host.should =~ /#{@bucket_spec_region}/
139
+ end
140
+
141
+ it "should use Sndacs::REGION_DEFAULT when @location is empty" do
142
+ bucket_tmp = Bucket.send(:new, @service, @bucket_spec_name, nil)
143
+ bucket_tmp.host.should =~ /#{Sndacs::REGION_DEFAULT}/
144
+ end
145
+ end
146
+
147
+ context "#path_prefix" do
148
+ it "should works" do
149
+ @bucket_spec.path_prefix.should =~ /#{@bucket_spec_name}/
150
+ end
151
+ end
152
+
153
+ context "#objects" do
154
+ before :each do
155
+ @bucket_spec.save
156
+ end
157
+
158
+ after :each do
159
+ @bucket_spec.destroy true
160
+ end
161
+
162
+ it "should works" do
163
+ bucket_object = @bucket_spec.object("object-spec-test-#{Time.now.to_i.to_s}")
164
+ bucket_object.content = 'Hello,world!'
165
+ bucket_object.save
166
+
167
+ bucket_objects = @bucket_spec.objects
168
+ bucket_objects.should be_instance_of(Array)
169
+ bucket_objects.should include(bucket_object)
170
+ end
171
+ end
172
+
173
+ context "#object" do
174
+ it "should works" do
175
+ @bucket_spec.object("object-spec-test-#{Time.now.to_i.to_s}").should be_instance_of(Sndacs::Object)
176
+ end
177
+ end
178
+ end
179
+
180
+ end
@@ -0,0 +1,167 @@
1
+ require 'net/http'
2
+ require 'spec_helper'
3
+
4
+ module Sndacs
5
+
6
+ describe Object do
7
+ before :all do
8
+ @service = Sndacs::Service.new
9
+
10
+ @bucket_spec_name = "bucket-spec-test-#{Time.now.to_i.to_s}"
11
+ @bucket_spec_region = 'huabei-1'
12
+ @bucket_spec = Bucket.send(:new, @service, @bucket_spec_name, @bucket_spec_region)
13
+ @bucket_spec.save
14
+ end
15
+
16
+ after :all do
17
+ @bucket_spec.destroy
18
+ end
19
+
20
+ before :each do
21
+ #sleep 1
22
+
23
+ @object_spec_name = "object-spec-test-#{Time.now.to_i.to_s}.txt"
24
+ @object_spec_content = 'Hello,world!'
25
+ @object_spec = @bucket_spec.object @object_spec_name
26
+ @object_spec.content = @object_spec_content
27
+ end
28
+
29
+ context "#retrieve" do
30
+ it "should works" do
31
+ @object_spec.save
32
+
33
+ object = @object_spec.retrieve
34
+ object.should == @object_spec
35
+
36
+ @object_spec.destroy
37
+ end
38
+
39
+ it "should raise Sndacs::Error::NoSuchKey if object does not exist" do
40
+ lambda {
41
+ @object_spec.retrieve
42
+ }.should raise_error(Sndacs::Error::NoSuchKey)
43
+ end
44
+ end
45
+
46
+ context "#content" do
47
+ before :each do
48
+ @object_spec.save
49
+ end
50
+
51
+ after :each do
52
+ @object_spec.destroy
53
+ end
54
+
55
+ it "should works" do
56
+ object_content = @object_spec.content
57
+
58
+ object_content.should == @object_spec_content
59
+ end
60
+
61
+ it "should reload content with force=true" do
62
+ @object_spec.should_receive(:get_object).and_return(@object_spec_content)
63
+
64
+ @object_spec.content(true)
65
+ end
66
+ end
67
+
68
+ context "#save" do
69
+ it "should works" do
70
+ @object_spec.should_receive(:put_object).and_return(true)
71
+
72
+ @object_spec.save
73
+ end
74
+
75
+ it "should update object's content when change its content and save" do
76
+ new_content = 'Hello,sndacs!'
77
+
78
+ @object_spec.content = new_content
79
+ @object_spec.save
80
+
81
+ object_content = @object_spec.content(true)
82
+ object_content.should == new_content
83
+
84
+ @object_spec.destroy
85
+ end
86
+ end
87
+
88
+ context "#destroy" do
89
+ before :each do
90
+ @object_spec.save
91
+ end
92
+
93
+ it "should works" do
94
+ @object_spec.destroy.should == true
95
+ end
96
+
97
+ it "should raise Sndacs::Error::NoSuchKey if object does not exist" do
98
+ @object_spec.destroy.should == true
99
+
100
+ lambda {
101
+ @object_spec.destroy
102
+ }.should raise_error(Sndacs::Error::NoSuchKey)
103
+ end
104
+ end
105
+
106
+ context "#url" do
107
+ before :each do
108
+ @object_spec.save
109
+ end
110
+
111
+ after :each do
112
+ @object_spec.destroy
113
+ end
114
+
115
+ it "should works" do
116
+ @object_spec.url.should =~ /#{@bucket_spec_name}\/#{@object_spec_name}/
117
+ end
118
+ end
119
+
120
+ context "#cname_url" do
121
+ before :each do
122
+ @object_spec.save
123
+ end
124
+
125
+ after :each do
126
+ @object_spec.destroy
127
+ end
128
+
129
+ xit "should works" do
130
+ #@object_spec.url.should =~ /#{@bucket_spec_name}\/#{@object_spec_name}/
131
+ end
132
+ end
133
+
134
+ context "#temporary_url" do
135
+ before :each do
136
+ @object_spec.save
137
+ end
138
+
139
+ after :each do
140
+ @object_spec.destroy
141
+ end
142
+
143
+ it "should works" do
144
+ object_url = @object_spec.temporary_url
145
+ object_url.should =~ /#{@bucket_spec_name}\/#{@object_spec_name}/
146
+
147
+ object_content = Net::HTTP.get(URI(object_url))
148
+ object_content.should == @object_spec_content
149
+ end
150
+ end
151
+
152
+ context "#exists?" do
153
+ it "should return true if object exists" do
154
+ @object_spec.save
155
+
156
+ @object_spec.exists?.should == true
157
+
158
+ @object_spec.destroy
159
+ end
160
+
161
+ it "should return false if object does not exist" do
162
+ @object_spec.exists?.should == false
163
+ end
164
+ end
165
+ end
166
+
167
+ end
@@ -1,25 +1,36 @@
1
1
  require 'spec_helper'
2
2
 
3
- require 'sndacs/service'
4
-
5
3
  module Sndacs
6
- describe Service do
7
- context "#buckets" do
8
- context "when buckets is empty" do
9
- it "should works" do
10
- @service_empty_buckets_list = Sndacs::Service.new(
11
- :access_key_id => "12345678901234567890",
12
- :secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF"
13
- )
14
- @response_empty_buckets_list = Net::HTTPOK.new("1.1", "200", "OK")
15
- @service_empty_buckets_list.should_receive(:service_request).and_return(@response_empty_buckets_list)
16
- @response_empty_buckets_list.should_receive(:body).and_return(@buckets_empty_list_body)
17
- @buckets_empty_list_body = <<-EOEmptyBuckets
18
- <?xml version="1.0" encoding="UTF-8"?>\n<ListAllMyBucketsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <Owner> <ID>123u1odhkhfoadf</ID> <DisplayName>JohnDoe</DisplayName> </Owner> <Buckets> </Buckets> </ListAllMyBucketsResult>
19
- EOEmptyBuckets
20
- @service_empty_buckets_list.buckets.should == []
4
+
5
+ describe Service do
6
+ context "#buckets" do
7
+ context "when buckets is empty" do
8
+ before :each do
9
+ @service_empty = Sndacs::Service.new
10
+ @response_empty = Net::HTTPOK.new('1.1', '200', 'OK')
11
+ @buckets_empty_body = <<-EOEmptyBuckets
12
+ <?xml version="1.0" encoding="UTF-8"?>\n<ListAllMyBucketsResult xmlns="http://storage.grandcloud.cn/doc/2006-03-01/"><Owner><ID>123u1odhkhfoadf</ID> <DisplayName>JohnDoe</DisplayName></Owner><Buckets></Buckets></ListAllMyBucketsResult>
13
+ EOEmptyBuckets
14
+ end
15
+
16
+ it "should works" do
17
+ @service_empty.should_receive(:service_request).and_return(@response_empty)
18
+ @response_empty.should_receive(:body).and_return(@buckets_empty_body)
19
+
20
+ @service_empty.buckets.should == []
21
+ end
22
+ end
23
+
24
+ context "when buckets is not empty" do
25
+ before :each do
26
+ @service = Sndacs::Service.new
27
+ end
28
+
29
+ it "should works" do
30
+ @service.buckets.should be_instance_of(Array)
31
+ end
32
+ end
21
33
  end
22
- end
23
34
  end
24
- end
35
+
25
36
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,24 @@
1
1
  require 'rspec'
2
+ require 'sndacs'
2
3
 
3
4
  RSpec.configure do |config|
5
+ config.include RSpec::Matchers
6
+
4
7
  config.mock_with :rspec
5
8
  end
9
+
10
+ module Sndacs
11
+
12
+ # Default configurations, see Sndacs::Config for more info
13
+ Config.access_key_id = '7EDX20CJ54PA31INPXTD469MR'
14
+ Config.secret_access_key = 'NzljZWE0MzgtNGQ0Yi00ZGZiLWI0YzMtOTQzODE2MTkzN2Nk'
15
+ Config.host = 'storage.grandcloud.cn'
16
+ Config.content_host = 'storage.sdcloud.cn'
17
+ Config.proxy = nil
18
+ Config.timeout = 60
19
+ Config.use_ssl = false
20
+ Config.chunk_size = 104856
21
+ Config.debug = false
22
+
23
+ end
24
+
metadata CHANGED
@@ -1,78 +1,93 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sndacs
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.1
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - LI Daobing
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-03-26 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2012-07-12 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: proxies
16
- requirement: &19459980 !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
17
24
  none: false
18
- requirements:
25
+ requirements:
19
26
  - - ~>
20
- - !ruby/object:Gem::Version
27
+ - !ruby/object:Gem::Version
28
+ hash: 23
29
+ segments:
30
+ - 0
31
+ - 2
32
+ - 0
21
33
  version: 0.2.0
22
34
  type: :runtime
23
- prerelease: false
24
- version_requirements: *19459980
25
- - !ruby/object:Gem::Dependency
26
- name: test-unit
27
- requirement: &19459020 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '2.0'
33
- type: :development
34
- prerelease: false
35
- version_requirements: *19459020
36
- - !ruby/object:Gem::Dependency
37
- name: mocha
38
- requirement: &19443300 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
43
- version: '0'
44
- type: :development
45
- prerelease: false
46
- version_requirements: *19443300
47
- - !ruby/object:Gem::Dependency
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
48
37
  name: bundler
49
- requirement: &19441820 !ruby/object:Gem::Requirement
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
50
40
  none: false
51
- requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 23
45
+ segments:
46
+ - 1
47
+ - 0
48
+ - 0
54
49
  version: 1.0.0
55
50
  type: :development
56
- prerelease: false
57
- version_requirements: *19441820
58
- - !ruby/object:Gem::Dependency
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
59
53
  name: rspec
60
- requirement: &19441060 !ruby/object:Gem::Requirement
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
61
56
  none: false
62
- requirements:
57
+ requirements:
63
58
  - - ~>
64
- - !ruby/object:Gem::Version
65
- version: '2.0'
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 2
63
+ - 0
64
+ version: "2.0"
66
65
  type: :development
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: mocha
67
69
  prerelease: false
68
- version_requirements: *19441060
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ type: :development
80
+ version_requirements: *id004
69
81
  description: sndacs library provides access to SNDA Cloud Storage.
70
- email:
82
+ email:
71
83
  - lidaobing@snda.com
72
84
  executables: []
85
+
73
86
  extensions: []
87
+
74
88
  extra_rdoc_files: []
75
- files:
89
+
90
+ files:
76
91
  - .gitignore
77
92
  - .rspec
78
93
  - Gemfile
@@ -83,6 +98,7 @@ files:
83
98
  - lib/sndacs.rb
84
99
  - lib/sndacs/bucket.rb
85
100
  - lib/sndacs/buckets_extension.rb
101
+ - lib/sndacs/config.rb
86
102
  - lib/sndacs/connection.rb
87
103
  - lib/sndacs/exceptions.rb
88
104
  - lib/sndacs/object.rb
@@ -93,36 +109,44 @@ files:
93
109
  - lib/sndacs/signature.rb
94
110
  - lib/sndacs/version.rb
95
111
  - sndacs.gemspec
112
+ - spec/sndacs/bucket_spec.rb
113
+ - spec/sndacs/object_spec.rb
96
114
  - spec/sndacs/service_spec.rb
97
115
  - spec/spec_helper.rb
98
- - test/bucket_test.rb
99
- - test/connection_test.rb
100
- - test/object_test.rb
101
- - test/service_test.rb
102
- - test/signature_test.rb
103
- - test/test_helper.rb
104
116
  homepage: https://github.com/grandcloud/sndacs-ruby
105
117
  licenses: []
118
+
106
119
  post_install_message:
107
120
  rdoc_options: []
108
- require_paths:
121
+
122
+ require_paths:
109
123
  - lib
110
- required_ruby_version: !ruby/object:Gem::Requirement
124
+ required_ruby_version: !ruby/object:Gem::Requirement
111
125
  none: false
112
- requirements:
113
- - - ! '>='
114
- - !ruby/object:Gem::Version
115
- version: '0'
116
- required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ hash: 3
130
+ segments:
131
+ - 0
132
+ version: "0"
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
134
  none: false
118
- requirements:
119
- - - ! '>='
120
- - !ruby/object:Gem::Version
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ hash: 23
139
+ segments:
140
+ - 1
141
+ - 3
142
+ - 6
121
143
  version: 1.3.6
122
144
  requirements: []
145
+
123
146
  rubyforge_project:
124
147
  rubygems_version: 1.8.15
125
148
  signing_key:
126
149
  specification_version: 3
127
- summary: Library for accessing SNDA Cloud Storage objects and buckets
150
+ summary: Library for accessing SNDA Cloud Storage buckets and objects
128
151
  test_files: []
152
+