aeolus-image 0.0.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +161 -0
- data/Rakefile +32 -19
- data/lib/aeolus_image.rb +35 -0
- data/lib/aeolus_image/active_resource_oauth_client.rb +62 -0
- data/lib/aeolus_image/import.rb +44 -0
- data/lib/aeolus_image/model/factory/base.rb +93 -0
- data/lib/aeolus_image/model/factory/build.rb +23 -0
- data/lib/aeolus_image/model/factory/builder.rb +46 -0
- data/lib/aeolus_image/model/factory/image.rb +23 -0
- data/lib/aeolus_image/model/factory/provider_image.rb +35 -0
- data/lib/aeolus_image/model/factory/target_image.rb +45 -0
- data/lib/aeolus_image/model/warehouse/icicle.rb +60 -0
- data/lib/aeolus_image/model/warehouse/image.rb +135 -0
- data/lib/aeolus_image/model/warehouse/image_build.rb +60 -0
- data/lib/aeolus_image/model/warehouse/provider_image.rb +36 -0
- data/lib/aeolus_image/model/warehouse/target_image.rb +53 -0
- data/lib/aeolus_image/model/warehouse/template.rb +35 -0
- data/lib/aeolus_image/model/warehouse/warehouse_client.rb +201 -0
- data/lib/aeolus_image/model/warehouse/warehouse_model.rb +236 -0
- data/spec/aeolus_image/model/factory/provider_image_spec.rb +12 -0
- data/spec/models/factory/base_spec.rb +94 -0
- data/spec/models/factory/builder_spec.rb +31 -0
- data/spec/models/factory/provider_image_spec.rb +21 -0
- data/spec/models/factory/target_image_spec.rb +21 -0
- data/spec/models/warehouse/image_build_spec.rb +189 -0
- data/spec/models/warehouse/image_spec.rb +241 -0
- data/spec/models/warehouse/provider_image_spec.rb +115 -0
- data/spec/models/warehouse/target_image_spec.rb +180 -0
- data/spec/models/warehouse/template_spec.rb +76 -0
- data/spec/models/warehouse/warehouse_client_spec.rb +445 -0
- data/spec/models/warehouse/warehouse_model_spec.rb +94 -0
- data/spec/spec_helper.rb +34 -47
- data/spec/vcr/cassettes/builder.yml +24 -0
- data/spec/vcr/cassettes/oauth.yml +80 -0
- data/spec/vcr/cassettes/oauth_fail_invalid.yml +30 -0
- data/spec/vcr/cassettes/oauth_fail_no.yml +22 -0
- data/spec/vcr/cassettes/oauth_success_valid.yml +30 -0
- data/spec/vcr_setup.rb +26 -0
- metadata +70 -46
- data/bin/aeolus-image +0 -6
- data/examples/aeolus-cli +0 -9
- data/examples/custom_repo.tdl +0 -18
- data/examples/image_description.xml +0 -3
- data/examples/tdl.rng +0 -207
- data/lib/base_command.rb +0 -134
- data/lib/build_command.rb +0 -68
- data/lib/config_parser.rb +0 -212
- data/lib/delete_command.rb +0 -9
- data/lib/import_command.rb +0 -44
- data/lib/list_command.rb +0 -141
- data/lib/push_command.rb +0 -72
- data/man/aeolus-image-build.1 +0 -36
- data/man/aeolus-image-import.1 +0 -57
- data/man/aeolus-image-list.1 +0 -80
- data/man/aeolus-image-push.1 +0 -40
- data/man/aeolus-image.1 +0 -16
- data/spec/base_command_spec.rb +0 -76
- data/spec/build_command_spec.rb +0 -63
- data/spec/config_parser_spec.rb +0 -82
- data/spec/import_command_spec.rb +0 -43
- data/spec/list_command_spec.rb +0 -21
- data/spec/push_command_spec.rb +0 -56
- data/spec/spec.opts +0 -3
@@ -0,0 +1,115 @@
|
|
1
|
+
# Copyright 2011 Red Hat, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'spec_helper'
|
16
|
+
|
17
|
+
module Aeolus
|
18
|
+
module Image
|
19
|
+
module Warehouse
|
20
|
+
describe ProviderImage do
|
21
|
+
before(:each) do
|
22
|
+
@provider_image_attributes = {
|
23
|
+
:provider => 'provider',
|
24
|
+
:target_image => 'target_image',
|
25
|
+
:uuid => 'uuid',
|
26
|
+
:other_attribute => 'other_attribute',
|
27
|
+
:another_attribute => 'another_attribute'
|
28
|
+
}
|
29
|
+
@object = mock(Object, :attr_list => @provider_image_attributes.keys, :attrs => @provider_image_attributes)
|
30
|
+
@provider_image_attributes.each do |key, value|
|
31
|
+
@object.stub(key.to_sym, value)
|
32
|
+
end
|
33
|
+
@provider_image = ProviderImage.new(@object)
|
34
|
+
end
|
35
|
+
|
36
|
+
context "@bucket_name" do
|
37
|
+
|
38
|
+
it "should be set correctly" do
|
39
|
+
# accessor set in WarehouseModel
|
40
|
+
@provider_image.class.bucket_name.should be_eql('provider_images')
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
context "#initialize" do
|
46
|
+
|
47
|
+
before(:each) do
|
48
|
+
@attr_writers = [ :provider, :target_image ]
|
49
|
+
@attr_accessors = @provider_image_attributes.keys - @attr_writers
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should correctly set attribute writers" do
|
53
|
+
@attr_writers.each do |writer|
|
54
|
+
@provider_image.respond_to?(:"#{writer.to_s}=").should be_true
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should correctly set attribute accessors" do
|
59
|
+
@attr_accessors.each do |accessor|
|
60
|
+
@provider_image.respond_to?(:"#{accessor.to_s}").should be_true
|
61
|
+
@provider_image.respond_to?(:"#{accessor.to_s}=").should be_true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should set attributes to correct values" do
|
66
|
+
@attr_accessors.each do |key|
|
67
|
+
@provider_image.send(:"#{key.to_s}").should be_equal(@provider_image_attributes[key])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
context "#target_image" do
|
74
|
+
context "with @target_image present" do
|
75
|
+
before(:each) do
|
76
|
+
@target_image_mock = mock(TargetImage)
|
77
|
+
TargetImage.stub(:find).and_return(@target_image_mock)
|
78
|
+
end
|
79
|
+
it "should call TargetImage.find with correct parameter" do
|
80
|
+
TargetImage.should_receive(:find).with(@provider_image.instance_variable_get( :@target_image ))
|
81
|
+
@provider_image.target_image
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should return found TargetImage" do
|
85
|
+
@provider_image.target_image.should be_eql(@target_image_mock)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "with @target_image absent" do
|
90
|
+
before(:each) do
|
91
|
+
@provider_image.instance_variable_set(:@target_image, nil)
|
92
|
+
end
|
93
|
+
it "should not call TargetImage.find at all" do
|
94
|
+
TargetImage.should_not_receive(:find)
|
95
|
+
@provider_image.target_image
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "#provider_name" do
|
101
|
+
it "should return @provider" do
|
102
|
+
@provider_image.provider_name.should be_eql(@provider_image.instance_variable_get(:@provider))
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "#delete!" do
|
107
|
+
it "should call ProviderImage.delete with @uuid" do
|
108
|
+
ProviderImage.should_receive(:delete).with(@provider_image.instance_variable_get(:@uuid))
|
109
|
+
@provider_image.delete!
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
# Copyright 2011 Red Hat, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'spec_helper'
|
16
|
+
|
17
|
+
module Aeolus
|
18
|
+
module Image
|
19
|
+
module Warehouse
|
20
|
+
describe TargetImage do
|
21
|
+
before(:each) do
|
22
|
+
@target_image_attributes = {
|
23
|
+
:build => 'build',
|
24
|
+
:uuid => 'uuid',
|
25
|
+
:template => 'template',
|
26
|
+
:other_attribute => 'other_attribute',
|
27
|
+
:another_attribute => 'another_attribute'
|
28
|
+
}
|
29
|
+
@object = mock(Object, :attr_list => @target_image_attributes.keys, :attrs => @target_image_attributes)
|
30
|
+
@target_image_attributes.each do |key, value|
|
31
|
+
@object.stub(key.to_sym, value)
|
32
|
+
end
|
33
|
+
@target_image = TargetImage.new(@object)
|
34
|
+
|
35
|
+
|
36
|
+
@provider_image_mock_with_no_target_image = mock(ProviderImage, :target_image => nil)
|
37
|
+
@provider_image_mock_with_correct_target_image = mock(ProviderImage, :target_image => @target_image)
|
38
|
+
@other_provider_image_mock_with_correct_target_image = mock(ProviderImage, :target_image => @target_image)
|
39
|
+
|
40
|
+
@other_target_image_attributes = @target_image_attributes.merge(:uuid => 'other_uuid')
|
41
|
+
@other_object = mock(Object, :attr_list => @other_target_image_attributes.keys, :attrs => @other_target_image_attributes)
|
42
|
+
@other_target_image_attributes.each do |key, value|
|
43
|
+
@other_object.stub(key.to_sym, value)
|
44
|
+
end
|
45
|
+
@other_target_image = TargetImage.new(@other_object)
|
46
|
+
@provider_image_mock_with_other_target_image = mock(ProviderImage, :target_image => @other_target_image)
|
47
|
+
|
48
|
+
@all_provider_images = [ @provider_image_mock_with_correct_target_image, @other_provider_image_mock_with_correct_target_image, @provider_image_mock_with_other_target_image, @provider_image_mock_with_no_target_image ]
|
49
|
+
|
50
|
+
@correct_provider_images = [ @provider_image_mock_with_correct_target_image, @other_provider_image_mock_with_correct_target_image ]
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
context "@bucket_name" do
|
55
|
+
|
56
|
+
it "should be set correctly" do
|
57
|
+
# accessor set in WarehouseModel
|
58
|
+
@target_image.class.bucket_name.should be_eql('target_images')
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
context "#initialize" do
|
64
|
+
|
65
|
+
before(:each) do
|
66
|
+
@attr_writers = [ :build ]
|
67
|
+
@attr_accessors = @target_image_attributes.keys - @attr_writers
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should correctly set attribute writers" do
|
71
|
+
@attr_writers.each do |writer|
|
72
|
+
@target_image.respond_to?(:"#{writer.to_s}=").should be_true
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should correctly set attribute accessors" do
|
77
|
+
@attr_accessors.each do |accessor|
|
78
|
+
@target_image.respond_to?(:"#{accessor.to_s}").should be_true
|
79
|
+
@target_image.respond_to?(:"#{accessor.to_s}=").should be_true
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should set attributes to correct values" do
|
84
|
+
@attr_accessors.each do |key|
|
85
|
+
@target_image.send(:"#{key.to_s}").should be_equal(@target_image_attributes[key])
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
context "#build" do
|
92
|
+
context "with @build present" do
|
93
|
+
before(:each) do
|
94
|
+
@image_build_mock = mock(ImageBuild)
|
95
|
+
ImageBuild.stub(:find).and_return(@image_build_mock)
|
96
|
+
end
|
97
|
+
it "should call TargetImage.find with correct parameter" do
|
98
|
+
ImageBuild.should_receive(:find).with(@target_image.instance_variable_get( :@build ))
|
99
|
+
@target_image.build
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should return found TargetImage" do
|
103
|
+
@target_image.build.should be_eql(@image_build_mock)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context "with @build absent" do
|
108
|
+
before(:each) do
|
109
|
+
@target_image.instance_variable_set(:@build, nil)
|
110
|
+
end
|
111
|
+
it "should not call TargetImage.find at all" do
|
112
|
+
ImageBuild.should_not_receive(:find)
|
113
|
+
@target_image.build
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context "#provider_images" do
|
119
|
+
before(:each) do
|
120
|
+
ProviderImage.stub(:where).and_return(@all_provider_images)
|
121
|
+
end
|
122
|
+
|
123
|
+
context "should return collection" do
|
124
|
+
it "with correct provider image" do
|
125
|
+
@target_image.provider_images.should include(@provider_image_mock_with_correct_target_image)
|
126
|
+
end
|
127
|
+
it "with other correct provider image" do
|
128
|
+
@target_image.provider_images.should include(@other_provider_image_mock_with_correct_target_image)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context "#template" do
|
134
|
+
context "with @template present" do
|
135
|
+
before(:each) do
|
136
|
+
@template_mock = mock(Template)
|
137
|
+
Template.stub(:find).and_return(@template_mock)
|
138
|
+
end
|
139
|
+
it "should call Template.find with correct parameter" do
|
140
|
+
Template.should_receive(:find).with(@target_image.instance_variable_get( :@template ))
|
141
|
+
@target_image.target_template
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should return found Template" do
|
145
|
+
@target_image.target_template.should be_eql(@template_mock)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context "with @template absent" do
|
150
|
+
before(:each) do
|
151
|
+
@target_image.instance_variable_set(:@template, nil)
|
152
|
+
end
|
153
|
+
it "should not call Template.find at all" do
|
154
|
+
Template.should_not_receive(:find)
|
155
|
+
@target_image.target_template
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context "#delete!" do
|
161
|
+
|
162
|
+
before(:each) do
|
163
|
+
@correct_provider_images.each{|pi| pi.stub(:delete!)}
|
164
|
+
@target_image.stub(:provider_images).and_return(@correct_provider_images)
|
165
|
+
TargetImage.stub(:delete)
|
166
|
+
end
|
167
|
+
it "should delete all associated provider images" do
|
168
|
+
@correct_provider_images.each{|pi| pi.should_receive(:delete!)}
|
169
|
+
@target_image.delete!
|
170
|
+
end
|
171
|
+
it "should call TargetImage.delete with @uuid" do
|
172
|
+
TargetImage.should_receive(:delete).with(@target_image.instance_variable_get(:@uuid))
|
173
|
+
@target_image.delete!
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# Copyright 2011 Red Hat, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'spec_helper'
|
16
|
+
|
17
|
+
module Aeolus
|
18
|
+
module Image
|
19
|
+
module Warehouse
|
20
|
+
describe Template do
|
21
|
+
let(:body) { 'body' }
|
22
|
+
before(:each) do
|
23
|
+
@template_attributes = {
|
24
|
+
:attribute => 'attribute',
|
25
|
+
:other_attribute => 'other_attribute',
|
26
|
+
:another_attribute => 'another_attribute'
|
27
|
+
}
|
28
|
+
@object = mock(Object, :attr_list => @template_attributes.keys, :attrs => @template_attributes, :body => 'body')
|
29
|
+
@template_attributes.each do |key, value|
|
30
|
+
@object.stub(key.to_sym, value)
|
31
|
+
end
|
32
|
+
@template = Template.new(@object)
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
context "@bucket_name" do
|
37
|
+
|
38
|
+
it "should be set correctly" do
|
39
|
+
# accessor set in WarehouseModel
|
40
|
+
@template.class.bucket_name.should be_eql('templates')
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
context "#initialize" do
|
46
|
+
|
47
|
+
before(:each) do
|
48
|
+
@attr_writers = []
|
49
|
+
@attr_accessors = @template_attributes.keys - @attr_writers
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should correctly set attribute writers" do
|
53
|
+
@attr_writers.each do |writer|
|
54
|
+
@template.respond_to?(:"#{writer.to_s}=").should be_true
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should correctly set attribute accessors" do
|
59
|
+
@attr_accessors.each do |accessor|
|
60
|
+
@template.respond_to?(:"#{accessor.to_s}").should be_true
|
61
|
+
@template.respond_to?(:"#{accessor.to_s}=").should be_true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should set attributes to correct values" do
|
66
|
+
@attr_accessors.each do |key|
|
67
|
+
puts @template.send(:"#{key.to_s}")
|
68
|
+
@template.send(:"#{key.to_s}").should be_equal(@template_attributes[key])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,445 @@
|
|
1
|
+
# Copyright 2011 Red Hat, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'spec_helper'
|
16
|
+
|
17
|
+
module Aeolus
|
18
|
+
module Image
|
19
|
+
module Warehouse
|
20
|
+
describe BucketObject do
|
21
|
+
let(:connection) { 'connection' }
|
22
|
+
let(:key) { 'key' }
|
23
|
+
let(:bucket) { mock(Bucket, :name => 'bucket_name') }
|
24
|
+
|
25
|
+
subject { BucketObject.new( connection, key, bucket ) }
|
26
|
+
|
27
|
+
context "#initialize" do
|
28
|
+
|
29
|
+
it "should set instance varibales correctly" do
|
30
|
+
subject.instance_variable_get(:@connection).should be_eql(connection)
|
31
|
+
subject.instance_variable_get(:@key).should be_eql(key)
|
32
|
+
subject.instance_variable_get(:@bucket).should be_eql(bucket)
|
33
|
+
subject.instance_variable_get(:@path).should be_eql('/bucket_name/key')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context ".create" do
|
38
|
+
|
39
|
+
pending
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
context "#body" do
|
44
|
+
|
45
|
+
let(:connection_hash) { { :plain => true } }
|
46
|
+
|
47
|
+
it "should call @connection.do_request with correct parameters" do
|
48
|
+
subject.instance_variable_get(:@connection).should_receive(:do_request).with(subject.instance_variable_get(:@path), connection_hash )
|
49
|
+
subject.body
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "#set_body" do
|
54
|
+
|
55
|
+
let(:body) { 'body' }
|
56
|
+
let(:connection_hash) { { :content => body, :method => :put } }
|
57
|
+
|
58
|
+
it "should call @connection.do_request with correct parameters" do
|
59
|
+
subject.instance_variable_get(:@connection).should_receive(:do_request).with(subject.instance_variable_get(:@path), connection_hash )
|
60
|
+
subject.set_body(body)
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
context "#attr_list" do
|
66
|
+
|
67
|
+
let(:connection_hash) { { :content => 'op=parts', :method => :post } }
|
68
|
+
let(:do_request_result) { Nokogiri::XML(do_request_result_string) }
|
69
|
+
let(:do_request_result_string) { "<object></object>" }
|
70
|
+
before(:each) do
|
71
|
+
subject.instance_variable_get(:@connection).stub(:do_request).and_return(do_request_result)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should call @connection.do_request with correct parameters" do
|
75
|
+
subject.instance_variable_get(:@connection).should_receive(:do_request).with( subject.instance_variable_get(:@path), connection_hash )
|
76
|
+
subject.attr_list
|
77
|
+
end
|
78
|
+
|
79
|
+
context "when @connection.do_request returns good data" do
|
80
|
+
let(:do_request_result_string) { "<object><object_attr name='name_1'>value_1</object_attr><object_attr name='name_2'>value_2</object_attr></object>" }
|
81
|
+
|
82
|
+
it "should return correct values" do
|
83
|
+
subject.attr_list.should be_eql(["name_1", "name_2"])
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "when @connection.do_request returns bad data" do
|
88
|
+
let(:do_request_result_string) { "<object>/<object>" }
|
89
|
+
|
90
|
+
it "should return correct values" do
|
91
|
+
subject.attr_list.should_not be_eql(["name_1", "name_2"])
|
92
|
+
subject.attr_list.should be_eql([])
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "#attrs" do
|
98
|
+
|
99
|
+
let(:attrs) { { 'attr1' => 'val1', 'attr2' => 'val2', 'attr_empty' => '', 'attr_nil' => nil, 'attr-dash' => 'dash' } }
|
100
|
+
let(:attr_list_without_dash) { attrs.keys - ['attr-dash'] }
|
101
|
+
let(:attr_list_with_dash) { attrs.keys - attr_list_without_dash }
|
102
|
+
let(:attr_list) { attr_list_with_dash + attr_list_without_dash }
|
103
|
+
let(:connection_hash) { { :plain => true } }
|
104
|
+
before(:each) do
|
105
|
+
attrs.each do |key, value|
|
106
|
+
subject.instance_variable_get(:@connection).stub(:do_request).with( "#{subject.instance_variable_get(:@path)}/#{key}", connection_hash ).and_return(value)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should call @connection.do_request for each attribute without dash" do
|
111
|
+
attr_list_without_dash.each do |attr|
|
112
|
+
subject.instance_variable_get(:@connection).should_receive(:do_request).with( "#{subject.instance_variable_get(:@path)}/#{attr}", connection_hash )
|
113
|
+
end
|
114
|
+
attr_list_with_dash.each do |attr|
|
115
|
+
subject.instance_variable_get(:@connection).should_not_receive(:do_request).with( "#{subject.instance_variable_get(:@path)}/#{attr}", connection_hash )
|
116
|
+
end
|
117
|
+
subject.attrs( attr_list )
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should return correct values" do
|
121
|
+
subject.attrs(attr_list).should be_eql(attrs.except(*attr_list_with_dash))
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
context "#attr" do
|
127
|
+
|
128
|
+
let(:good_attribute_name) { "good_name" }
|
129
|
+
let(:good_attribute_value) { "good_value" }
|
130
|
+
let(:bad_attribute_name) { "bad_name" }
|
131
|
+
before(:each) do
|
132
|
+
subject.stub(:attrs).and_return( { good_attribute_name => good_attribute_value } )
|
133
|
+
end
|
134
|
+
|
135
|
+
context "when passed good name of attribute" do
|
136
|
+
it "should return correct value" do
|
137
|
+
subject.attr(good_attribute_name).should be_eql(good_attribute_value)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context "when passed bad name of attribute" do
|
142
|
+
it "should return nil" do
|
143
|
+
subject.attr(bad_attribute_name).should be_nil
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context "when passed nil as name of attribute" do
|
148
|
+
it "should return nil" do
|
149
|
+
subject.attr(nil).should be_nil
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
context "#set_attrs" do
|
156
|
+
|
157
|
+
let(:attrs_hash) { { :attr1 => 'value1', :attr2 => 'value2' } }
|
158
|
+
before(:each) do
|
159
|
+
subject.stub(:set_attr)
|
160
|
+
end
|
161
|
+
it "should call set_attr with correct parameters for each attribute" do
|
162
|
+
attrs_hash.each do |key, value|
|
163
|
+
subject.should_receive(:set_attr).with(key, value)
|
164
|
+
end
|
165
|
+
subject.set_attrs(attrs_hash)
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
context "#set_attr" do
|
171
|
+
|
172
|
+
let(:name) { 'name' }
|
173
|
+
let(:content) { 'content' }
|
174
|
+
let(:connection_hash) { { :method => :put, :content => content } }
|
175
|
+
it "should call @connection.do_request with correct parameters" do
|
176
|
+
subject.instance_variable_get(:@connection).should_receive(:do_request).with("#{subject.instance_variable_get(:@path)}/#{name}", connection_hash )
|
177
|
+
subject.set_attr(name, content)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
context "#delete!" do
|
182
|
+
|
183
|
+
let(:connection_hash) { { :method => :delete } }
|
184
|
+
before(:each) do
|
185
|
+
subject.instance_variable_get(:@connection).stub(:do_request)
|
186
|
+
end
|
187
|
+
it "should call @connection.do_request with correct parameters" do
|
188
|
+
subject.instance_variable_get(:@connection).should_receive(:do_request).with(subject.instance_variable_get(:@path), connection_hash )
|
189
|
+
subject.delete!
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe Bucket do
|
196
|
+
|
197
|
+
subject { bucket }
|
198
|
+
let(:name) { 'bucket_name' }
|
199
|
+
let(:do_request_result_string) { "<object>/<object>" }
|
200
|
+
let(:do_request_result) { Nokogiri::XML(do_request_result_string) }
|
201
|
+
let(:connection) { mock(Object, :do_request => do_request_result) }
|
202
|
+
let(:bucket) { Bucket.new(name, connection) }
|
203
|
+
context "#initialize" do
|
204
|
+
|
205
|
+
it "should set instance variables correctly" do
|
206
|
+
subject.instance_variable_get(:@name).should be_eql(name)
|
207
|
+
subject.instance_variable_get(:@connection).should be_eql(connection)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
context "#to_s" do
|
212
|
+
|
213
|
+
it "should return correct string" do
|
214
|
+
subject.to_s.should be_eql("Bucket: #{name}")
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
218
|
+
|
219
|
+
context "#object_names" do
|
220
|
+
let(:connection_path) { "/#{name}" }
|
221
|
+
let(:do_request_result_string) { "<objects><object><key>name1</key></object><object><key>name2</key></object></objects>" }
|
222
|
+
|
223
|
+
it "should call @connection.do_request with correct parameters" do
|
224
|
+
connection.should_receive(:do_request).with(connection_path)
|
225
|
+
subject.object_names
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should return array of object names" do
|
229
|
+
puts subject.object_names
|
230
|
+
subject.object_names.should be_eql(['name1', 'name2'])
|
231
|
+
end
|
232
|
+
|
233
|
+
end
|
234
|
+
|
235
|
+
context "#objects" do
|
236
|
+
let(:object_names) { %w{ name1 name2 } }
|
237
|
+
let(:mock_object) { mock(BucketObject) }
|
238
|
+
before(:each) do
|
239
|
+
subject.stub(:object_names).and_return(object_names)
|
240
|
+
subject.stub(:object).and_return( mock_object )
|
241
|
+
end
|
242
|
+
|
243
|
+
it "should return BucketObject for each object name" do
|
244
|
+
subject.objects.should be_eql([mock_object, mock_object])
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
context "#object" do
|
249
|
+
|
250
|
+
let(:object_name) { 'object_name' }
|
251
|
+
let(:mock_object) { mock(BucketObject) }
|
252
|
+
before(:each) do
|
253
|
+
BucketObject.stub(:new).and_return(mock_object)
|
254
|
+
end
|
255
|
+
it "should call BucketObject.new with correct parameters" do
|
256
|
+
BucketObject.should_receive(:new).with(connection, object_name, subject)
|
257
|
+
subject.object(object_name)
|
258
|
+
end
|
259
|
+
|
260
|
+
it "should return new BucketObject" do
|
261
|
+
subject.object(object_name).should be_eql(mock_object)
|
262
|
+
end
|
263
|
+
|
264
|
+
end
|
265
|
+
|
266
|
+
context "#create_object" do
|
267
|
+
|
268
|
+
let(:object_name) { 'object_name' }
|
269
|
+
let(:object_body) { 'object_body' }
|
270
|
+
let(:object_attrs) { { :attr1 => 'value1', :attr2 => 'value2' } }
|
271
|
+
let(:mock_object) { mock(BucketObject) }
|
272
|
+
before(:each) do
|
273
|
+
BucketObject.stub(:create).and_return(mock_object)
|
274
|
+
end
|
275
|
+
it "should call BucketObject.create with correct parameters" do
|
276
|
+
BucketObject.should_receive(:create).with(connection, object_name, subject, object_body, object_attrs)
|
277
|
+
subject.create_object(object_name, object_body, object_attrs)
|
278
|
+
end
|
279
|
+
|
280
|
+
it "should return new BucketObject" do
|
281
|
+
subject.create_object(object_name, object_body, object_attrs).should be_eql(mock_object)
|
282
|
+
end
|
283
|
+
|
284
|
+
end
|
285
|
+
|
286
|
+
context "#include?" do
|
287
|
+
|
288
|
+
let(:object_names) { %w{ name1 name2 } }
|
289
|
+
before(:each) do
|
290
|
+
subject.stub(:object_names).and_return(object_names)
|
291
|
+
end
|
292
|
+
|
293
|
+
context "when passed key of existing object" do
|
294
|
+
it { subject.include?('name1').should be_true }
|
295
|
+
end
|
296
|
+
context "when passed key of nonexisting object" do
|
297
|
+
it { subject.include?('name3').should be_false }
|
298
|
+
end
|
299
|
+
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
describe Connection do
|
304
|
+
subject { connection }
|
305
|
+
|
306
|
+
let(:uri) { 'uri' }
|
307
|
+
let(:connection) { Connection.new(uri) }
|
308
|
+
context "#initialize" do
|
309
|
+
|
310
|
+
it "should set up instance variables correctly" do
|
311
|
+
subject.instance_variable_get(:@uri).should be_eql(uri)
|
312
|
+
end
|
313
|
+
|
314
|
+
end
|
315
|
+
|
316
|
+
context "#do_request" do
|
317
|
+
let(:path) { 'path' }
|
318
|
+
let(:opts) { { :method => 'method', :content => 'content', :plain => false, :headers => {} } }
|
319
|
+
let(:result) { 'result' }
|
320
|
+
let(:xml_result) { Nokogiri::XML(result) }
|
321
|
+
|
322
|
+
before(:each) do
|
323
|
+
RestClient::Request.stub(:execute).and_return(result)
|
324
|
+
end
|
325
|
+
|
326
|
+
context "with meaningful parameters" do
|
327
|
+
|
328
|
+
it "should call RestClient::Request.execute with correct parameters" do
|
329
|
+
RestClient::Request.should_receive(:execute).with(:method => opts[:method], :url => uri + path, :payload => opts[:content], :headers => opts[:headers])
|
330
|
+
subject.do_request(path, opts)
|
331
|
+
end
|
332
|
+
end
|
333
|
+
context "with no parameters" do
|
334
|
+
|
335
|
+
it "should call RestClient::Request.execute with meaningful defaults" do
|
336
|
+
RestClient::Request.should_receive(:execute).with(:method => :get, :url => uri + '/', :payload => '', :headers => {})
|
337
|
+
subject.do_request()
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
context "with opts[:plain] = true" do
|
342
|
+
let(:opts) { { :method => 'method', :content => 'content', :plain => true, :headers => {} } }
|
343
|
+
it "should return plain result" do
|
344
|
+
subject.do_request(path, opts).should be_eql(result)
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
context "with opts[:plain] = false" do
|
349
|
+
let(:opts) { { :method => 'method', :content => 'content', :plain => false, :headers => {} } }
|
350
|
+
it "should return plain result" do
|
351
|
+
subject.do_request(path, opts).to_s.should be_eql(xml_result.to_s)
|
352
|
+
subject.do_request(path, opts).class.should be_eql(xml_result.class)
|
353
|
+
end
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
describe Client do
|
358
|
+
|
359
|
+
subject { client }
|
360
|
+
let(:client) { Client.new(uri) }
|
361
|
+
let(:uri) { 'uri' }
|
362
|
+
let(:connection) { mock(Object, :do_request => do_request_result) }
|
363
|
+
let(:do_request_result) { Nokogiri::XML(do_request_result_string) }
|
364
|
+
let(:do_request_result_string) { "<object>/<object>" }
|
365
|
+
before(:each) do
|
366
|
+
Connection.stub(:new).and_return(connection)
|
367
|
+
end
|
368
|
+
|
369
|
+
context "#initialize" do
|
370
|
+
|
371
|
+
it "should set instance variables correctly" do
|
372
|
+
subject.instance_variable_get(:@connection).should be_eql(connection)
|
373
|
+
end
|
374
|
+
|
375
|
+
end
|
376
|
+
|
377
|
+
context "#create_bucket" do
|
378
|
+
let(:bucket) { mock(Bucket) }
|
379
|
+
let(:bucket_name) { 'bucket_name' }
|
380
|
+
let(:path) { "/#{bucket_name}" }
|
381
|
+
let(:connection_hash) { { :method => :put } }
|
382
|
+
before(:each) do
|
383
|
+
Bucket.stub(:new).and_return(bucket)
|
384
|
+
end
|
385
|
+
|
386
|
+
it "should call @connection.do_request with correct parameters" do
|
387
|
+
connection.should_receive(:do_request).with(path, connection_hash)
|
388
|
+
subject.create_bucket(bucket_name)
|
389
|
+
end
|
390
|
+
|
391
|
+
it "should return Bucket object" do
|
392
|
+
subject.create_bucket(bucket_name).should be_eql(bucket)
|
393
|
+
end
|
394
|
+
|
395
|
+
end
|
396
|
+
|
397
|
+
context "#bucket" do
|
398
|
+
let(:bucket) { mock(Bucket) }
|
399
|
+
let(:bucket_name) { 'bucket_name' }
|
400
|
+
before(:each) do
|
401
|
+
Bucket.stub(:new).and_return(bucket)
|
402
|
+
end
|
403
|
+
|
404
|
+
it "should return Bucket object" do
|
405
|
+
subject.create_bucket(bucket_name).should be_eql(bucket)
|
406
|
+
end
|
407
|
+
|
408
|
+
end
|
409
|
+
|
410
|
+
context "#buckets" do
|
411
|
+
let(:bucket_names) { %w{ bucket1 bucket2 bucket3 } }
|
412
|
+
let(:do_request_result_string) { "<api>#{bucket_names.map{|bn| "<link rel='bucket' href='#{bn}'/>"}}</api>" }
|
413
|
+
it "should return array of bucket names" do
|
414
|
+
subject.buckets.should be_eql(bucket_names)
|
415
|
+
end
|
416
|
+
|
417
|
+
end
|
418
|
+
|
419
|
+
context "#get_iwhd_version" do
|
420
|
+
let(:iwhd_version) { 'iwhd_version' }
|
421
|
+
let(:do_request_result_string) { "<api service='image_warehouse' version='#{iwhd_version}'></api>" }
|
422
|
+
it "should return iwhd version value" do
|
423
|
+
subject.get_iwhd_version.should be_eql(iwhd_version)
|
424
|
+
end
|
425
|
+
|
426
|
+
end
|
427
|
+
|
428
|
+
context "#query" do
|
429
|
+
let(:bucket_name) { 'bucket_name' }
|
430
|
+
let(:path) { "/#{bucket_name}/_query" }
|
431
|
+
let(:query_string) { "query_string" }
|
432
|
+
let(:connection_hash) { { :method => :post, :content => query_string } }
|
433
|
+
|
434
|
+
it "should call @connection.do_request with correct parameters" do
|
435
|
+
|
436
|
+
connection.should_receive(:do_request).with(path, connection_hash)
|
437
|
+
subject.query(bucket_name, query_string)
|
438
|
+
end
|
439
|
+
|
440
|
+
end
|
441
|
+
end
|
442
|
+
end
|
443
|
+
end
|
444
|
+
end
|
445
|
+
end
|