knife-ec2 0.18.0 → 0.18.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.expeditor/config.yml +41 -0
- data/.expeditor/update_version.sh +12 -0
- data/.gitignore +41 -41
- data/CHANGELOG.md +132 -117
- data/CONTRIBUTING.md +245 -216
- data/DOC_CHANGES.md +17 -17
- data/Gemfile +4 -4
- data/LICENSE +201 -201
- data/RELEASE_NOTES.md +17 -17
- data/Rakefile +56 -56
- data/VERSION +1 -0
- data/lib/chef/knife/ec2_server_create.rb +1588 -1577
- data/lib/chef/knife/ec2_server_delete.rb +140 -140
- data/lib/chef/knife/s3_source.rb +49 -49
- data/lib/knife-ec2/version.rb +6 -6
- data/spec/unit/ec2_server_create_spec.rb +2728 -2703
- data/spec/unit/ec2_server_delete_spec.rb +141 -141
- data/spec/unit/s3_source_deps_spec.rb +24 -24
- data/spec/unit/s3_source_spec.rb +75 -75
- metadata +6 -3
@@ -1,141 +1,141 @@
|
|
1
|
-
# License:: Apache License, Version 2.0
|
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
|
-
|
16
|
-
require File.expand_path('../../spec_helper', __FILE__)
|
17
|
-
require 'fog/aws'
|
18
|
-
|
19
|
-
|
20
|
-
describe Chef::Knife::Ec2ServerDelete do
|
21
|
-
before do
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "run" do
|
25
|
-
before(:each) do
|
26
|
-
{
|
27
|
-
:image => 'image',
|
28
|
-
:ssh_key_name => 'ssh_key_name',
|
29
|
-
:aws_access_key_id => 'aws_access_key_id',
|
30
|
-
:aws_secret_access_key => 'aws_secret_access_key'
|
31
|
-
}.each do |key, value|
|
32
|
-
Chef::Config[:knife][key] = value
|
33
|
-
end
|
34
|
-
|
35
|
-
@ec2_server_attribs = { :id => 'i-39382318',
|
36
|
-
:flavor_id => 'm1.small',
|
37
|
-
:image_id => 'ami-47241231',
|
38
|
-
:availability_zone => 'us-west-1',
|
39
|
-
:key_name => 'my_ssh_key',
|
40
|
-
:groups => ['group1', 'group2'],
|
41
|
-
:security_group_ids => ['sg-00aa11bb'],
|
42
|
-
:dns_name => 'ec2-75.101.253.10.compute-1.amazonaws.com',
|
43
|
-
:iam_instance_profile => {},
|
44
|
-
:public_ip_address => '75.101.253.10',
|
45
|
-
:private_dns_name => 'ip-10-251-75-20.ec2.internal',
|
46
|
-
:private_ip_address => '10.251.75.20',
|
47
|
-
:root_device_type => 'not_ebs',
|
48
|
-
:tags => {'Name' => 'foo'}
|
49
|
-
}
|
50
|
-
@knife_ec2_delete = Chef::Knife::Ec2ServerDelete.new
|
51
|
-
@ec2_servers = double()
|
52
|
-
allow(@knife_ec2_delete.ui).to receive(:confirm)
|
53
|
-
allow(@knife_ec2_delete).to receive(:msg_pair)
|
54
|
-
@ec2_server = double(@ec2_server_attribs)
|
55
|
-
@ec2_connection = double(Fog::Compute::AWS)
|
56
|
-
allow(@ec2_connection).to receive(:servers).and_return(@ec2_servers)
|
57
|
-
allow(@knife_ec2_delete.ui).to receive(:warn)
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should invoke validate!" do
|
61
|
-
knife_ec2_delete = Chef::Knife::Ec2ServerDelete.new
|
62
|
-
expect(knife_ec2_delete).to receive(:validate!)
|
63
|
-
knife_ec2_delete.run
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should use invoke fog api to delete instance if instance id is passed" do
|
67
|
-
expect(@ec2_servers).to receive(:get).with('foo').and_return(@ec2_server)
|
68
|
-
expect(Fog::Compute::AWS).to receive(:new).and_return(@ec2_connection)
|
69
|
-
@knife_ec2_delete.name_args = ['foo']
|
70
|
-
expect(@knife_ec2_delete).to receive(:validate!)
|
71
|
-
expect(@ec2_server).to receive(:destroy)
|
72
|
-
@knife_ec2_delete.run
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should use node_name to figure out instance id if not specified explicitly" do
|
76
|
-
expect(@ec2_servers).to receive(:get).with('foo').and_return(@ec2_server)
|
77
|
-
expect(Fog::Compute::AWS).to receive(:new).and_return(@ec2_connection)
|
78
|
-
expect(@knife_ec2_delete).to receive(:validate!)
|
79
|
-
expect(@ec2_server).to receive(:destroy)
|
80
|
-
@knife_ec2_delete.config[:purge] = false
|
81
|
-
@knife_ec2_delete.config[:chef_node_name] = 'baz'
|
82
|
-
double_node = double(Chef::Node)
|
83
|
-
expect(double_node).to receive(:attribute?).with('ec2').and_return(true)
|
84
|
-
expect(double_node).to receive(:[]).with('ec2').and_return('instance_id'=>'foo')
|
85
|
-
double_search = double(Chef::Search::Query)
|
86
|
-
expect(double_search).to receive(:search).with(:node,"name:baz").and_return([[double_node],nil,nil])
|
87
|
-
expect(Chef::Search::Query).to receive(:new).and_return(double_search)
|
88
|
-
@knife_ec2_delete.name_args = []
|
89
|
-
@knife_ec2_delete.run
|
90
|
-
end
|
91
|
-
|
92
|
-
describe "when --purge is passed" do
|
93
|
-
it "should use the node name if its set" do
|
94
|
-
expect(@ec2_servers).to receive(:get).with('foo').and_return(@ec2_server)
|
95
|
-
expect(Fog::Compute::AWS).to receive(:new).and_return(@ec2_connection)
|
96
|
-
@knife_ec2_delete.name_args = ['foo']
|
97
|
-
expect(@knife_ec2_delete).to receive(:validate!)
|
98
|
-
expect(@ec2_server).to receive(:destroy)
|
99
|
-
@knife_ec2_delete.config[:purge] = true
|
100
|
-
@knife_ec2_delete.config[:chef_node_name] = 'baz'
|
101
|
-
expect(Chef::Node).to receive(:load).with('baz').and_return(double(:destroy=>true))
|
102
|
-
expect(Chef::ApiClient).to receive(:load).with('baz').and_return(double(:destroy=>true))
|
103
|
-
@knife_ec2_delete.run
|
104
|
-
end
|
105
|
-
|
106
|
-
it "should search for the node name using the instance id when node name is not specified" do
|
107
|
-
expect(@ec2_servers).to receive(:get).with('i-foo').and_return(@ec2_server)
|
108
|
-
expect(Fog::Compute::AWS).to receive(:new).and_return(@ec2_connection)
|
109
|
-
@knife_ec2_delete.name_args = ['i-foo']
|
110
|
-
expect(@knife_ec2_delete).to receive(:validate!)
|
111
|
-
expect(@ec2_server).to receive(:destroy)
|
112
|
-
@knife_ec2_delete.config[:purge] = true
|
113
|
-
@knife_ec2_delete.config[:chef_node_name] = nil
|
114
|
-
double_search = double(Chef::Search::Query)
|
115
|
-
double_node = double(Chef::Node)
|
116
|
-
expect(double_node).to receive(:name).and_return("baz")
|
117
|
-
expect(Chef::Node).to receive(:load).with('baz').and_return(double(:destroy=>true))
|
118
|
-
expect(Chef::ApiClient).to receive(:load).with('baz').and_return(double(:destroy=>true))
|
119
|
-
expect(double_search).to receive(:search).with(:node,"ec2_instance_id:i-foo").and_return([[double_node],nil,nil])
|
120
|
-
expect(Chef::Search::Query).to receive(:new).and_return(double_search)
|
121
|
-
@knife_ec2_delete.run
|
122
|
-
end
|
123
|
-
|
124
|
-
it "should use the instance id if search does not return anything" do
|
125
|
-
expect(@ec2_servers).to receive(:get).with('i-foo').and_return(@ec2_server)
|
126
|
-
expect(Fog::Compute::AWS).to receive(:new).and_return(@ec2_connection)
|
127
|
-
@knife_ec2_delete.name_args = ['i-foo']
|
128
|
-
expect(@knife_ec2_delete).to receive(:validate!)
|
129
|
-
expect(@ec2_server).to receive(:destroy)
|
130
|
-
@knife_ec2_delete.config[:purge] = true
|
131
|
-
@knife_ec2_delete.config[:chef_node_name] = nil
|
132
|
-
expect(Chef::Node).to receive(:load).with('i-foo').and_return(double(:destroy=>true))
|
133
|
-
expect(Chef::ApiClient).to receive(:load).with('i-foo').and_return(double(:destroy=>true))
|
134
|
-
double_search = double(Chef::Search::Query)
|
135
|
-
expect(double_search).to receive(:search).with(:node,"ec2_instance_id:i-foo").and_return([[],nil,nil])
|
136
|
-
expect(Chef::Search::Query).to receive(:new).and_return(double_search)
|
137
|
-
@knife_ec2_delete.run
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
1
|
+
# License:: Apache License, Version 2.0
|
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
|
+
|
16
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
17
|
+
require 'fog/aws'
|
18
|
+
|
19
|
+
|
20
|
+
describe Chef::Knife::Ec2ServerDelete do
|
21
|
+
before do
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "run" do
|
25
|
+
before(:each) do
|
26
|
+
{
|
27
|
+
:image => 'image',
|
28
|
+
:ssh_key_name => 'ssh_key_name',
|
29
|
+
:aws_access_key_id => 'aws_access_key_id',
|
30
|
+
:aws_secret_access_key => 'aws_secret_access_key'
|
31
|
+
}.each do |key, value|
|
32
|
+
Chef::Config[:knife][key] = value
|
33
|
+
end
|
34
|
+
|
35
|
+
@ec2_server_attribs = { :id => 'i-39382318',
|
36
|
+
:flavor_id => 'm1.small',
|
37
|
+
:image_id => 'ami-47241231',
|
38
|
+
:availability_zone => 'us-west-1',
|
39
|
+
:key_name => 'my_ssh_key',
|
40
|
+
:groups => ['group1', 'group2'],
|
41
|
+
:security_group_ids => ['sg-00aa11bb'],
|
42
|
+
:dns_name => 'ec2-75.101.253.10.compute-1.amazonaws.com',
|
43
|
+
:iam_instance_profile => {},
|
44
|
+
:public_ip_address => '75.101.253.10',
|
45
|
+
:private_dns_name => 'ip-10-251-75-20.ec2.internal',
|
46
|
+
:private_ip_address => '10.251.75.20',
|
47
|
+
:root_device_type => 'not_ebs',
|
48
|
+
:tags => {'Name' => 'foo'}
|
49
|
+
}
|
50
|
+
@knife_ec2_delete = Chef::Knife::Ec2ServerDelete.new
|
51
|
+
@ec2_servers = double()
|
52
|
+
allow(@knife_ec2_delete.ui).to receive(:confirm)
|
53
|
+
allow(@knife_ec2_delete).to receive(:msg_pair)
|
54
|
+
@ec2_server = double(@ec2_server_attribs)
|
55
|
+
@ec2_connection = double(Fog::Compute::AWS)
|
56
|
+
allow(@ec2_connection).to receive(:servers).and_return(@ec2_servers)
|
57
|
+
allow(@knife_ec2_delete.ui).to receive(:warn)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should invoke validate!" do
|
61
|
+
knife_ec2_delete = Chef::Knife::Ec2ServerDelete.new
|
62
|
+
expect(knife_ec2_delete).to receive(:validate!)
|
63
|
+
knife_ec2_delete.run
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should use invoke fog api to delete instance if instance id is passed" do
|
67
|
+
expect(@ec2_servers).to receive(:get).with('foo').and_return(@ec2_server)
|
68
|
+
expect(Fog::Compute::AWS).to receive(:new).and_return(@ec2_connection)
|
69
|
+
@knife_ec2_delete.name_args = ['foo']
|
70
|
+
expect(@knife_ec2_delete).to receive(:validate!)
|
71
|
+
expect(@ec2_server).to receive(:destroy)
|
72
|
+
@knife_ec2_delete.run
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should use node_name to figure out instance id if not specified explicitly" do
|
76
|
+
expect(@ec2_servers).to receive(:get).with('foo').and_return(@ec2_server)
|
77
|
+
expect(Fog::Compute::AWS).to receive(:new).and_return(@ec2_connection)
|
78
|
+
expect(@knife_ec2_delete).to receive(:validate!)
|
79
|
+
expect(@ec2_server).to receive(:destroy)
|
80
|
+
@knife_ec2_delete.config[:purge] = false
|
81
|
+
@knife_ec2_delete.config[:chef_node_name] = 'baz'
|
82
|
+
double_node = double(Chef::Node)
|
83
|
+
expect(double_node).to receive(:attribute?).with('ec2').and_return(true)
|
84
|
+
expect(double_node).to receive(:[]).with('ec2').and_return('instance_id'=>'foo')
|
85
|
+
double_search = double(Chef::Search::Query)
|
86
|
+
expect(double_search).to receive(:search).with(:node,"name:baz").and_return([[double_node],nil,nil])
|
87
|
+
expect(Chef::Search::Query).to receive(:new).and_return(double_search)
|
88
|
+
@knife_ec2_delete.name_args = []
|
89
|
+
@knife_ec2_delete.run
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "when --purge is passed" do
|
93
|
+
it "should use the node name if its set" do
|
94
|
+
expect(@ec2_servers).to receive(:get).with('foo').and_return(@ec2_server)
|
95
|
+
expect(Fog::Compute::AWS).to receive(:new).and_return(@ec2_connection)
|
96
|
+
@knife_ec2_delete.name_args = ['foo']
|
97
|
+
expect(@knife_ec2_delete).to receive(:validate!)
|
98
|
+
expect(@ec2_server).to receive(:destroy)
|
99
|
+
@knife_ec2_delete.config[:purge] = true
|
100
|
+
@knife_ec2_delete.config[:chef_node_name] = 'baz'
|
101
|
+
expect(Chef::Node).to receive(:load).with('baz').and_return(double(:destroy=>true))
|
102
|
+
expect(Chef::ApiClient).to receive(:load).with('baz').and_return(double(:destroy=>true))
|
103
|
+
@knife_ec2_delete.run
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should search for the node name using the instance id when node name is not specified" do
|
107
|
+
expect(@ec2_servers).to receive(:get).with('i-foo').and_return(@ec2_server)
|
108
|
+
expect(Fog::Compute::AWS).to receive(:new).and_return(@ec2_connection)
|
109
|
+
@knife_ec2_delete.name_args = ['i-foo']
|
110
|
+
expect(@knife_ec2_delete).to receive(:validate!)
|
111
|
+
expect(@ec2_server).to receive(:destroy)
|
112
|
+
@knife_ec2_delete.config[:purge] = true
|
113
|
+
@knife_ec2_delete.config[:chef_node_name] = nil
|
114
|
+
double_search = double(Chef::Search::Query)
|
115
|
+
double_node = double(Chef::Node)
|
116
|
+
expect(double_node).to receive(:name).and_return("baz")
|
117
|
+
expect(Chef::Node).to receive(:load).with('baz').and_return(double(:destroy=>true))
|
118
|
+
expect(Chef::ApiClient).to receive(:load).with('baz').and_return(double(:destroy=>true))
|
119
|
+
expect(double_search).to receive(:search).with(:node,"ec2_instance_id:i-foo").and_return([[double_node],nil,nil])
|
120
|
+
expect(Chef::Search::Query).to receive(:new).and_return(double_search)
|
121
|
+
@knife_ec2_delete.run
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should use the instance id if search does not return anything" do
|
125
|
+
expect(@ec2_servers).to receive(:get).with('i-foo').and_return(@ec2_server)
|
126
|
+
expect(Fog::Compute::AWS).to receive(:new).and_return(@ec2_connection)
|
127
|
+
@knife_ec2_delete.name_args = ['i-foo']
|
128
|
+
expect(@knife_ec2_delete).to receive(:validate!)
|
129
|
+
expect(@ec2_server).to receive(:destroy)
|
130
|
+
@knife_ec2_delete.config[:purge] = true
|
131
|
+
@knife_ec2_delete.config[:chef_node_name] = nil
|
132
|
+
expect(Chef::Node).to receive(:load).with('i-foo').and_return(double(:destroy=>true))
|
133
|
+
expect(Chef::ApiClient).to receive(:load).with('i-foo').and_return(double(:destroy=>true))
|
134
|
+
double_search = double(Chef::Search::Query)
|
135
|
+
expect(double_search).to receive(:search).with(:node,"ec2_instance_id:i-foo").and_return([[],nil,nil])
|
136
|
+
expect(Chef::Search::Query).to receive(:new).and_return(double_search)
|
137
|
+
@knife_ec2_delete.run
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -1,24 +1,24 @@
|
|
1
|
-
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
-
|
3
|
-
#This spec can only be run separately from the rest due to inclusion of fog library in other specs.
|
4
|
-
#rspec spec/unit/s3_source_deps_spec.rb
|
5
|
-
|
6
|
-
describe 'Check Dependencies', :exclude => Object.constants.include?(:Fog) do
|
7
|
-
before(:each) do
|
8
|
-
end
|
9
|
-
it 'should not load fog by default' do
|
10
|
-
begin
|
11
|
-
Fog::Storage::AWS.new()
|
12
|
-
rescue Exception => e
|
13
|
-
expect(e).to be_a_kind_of(NameError)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'lazy loads fog' do
|
18
|
-
begin
|
19
|
-
Chef::Knife::S3Source.fetch('test')
|
20
|
-
rescue Exception => e
|
21
|
-
expect(e).to be_a_kind_of(ArgumentError)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
#This spec can only be run separately from the rest due to inclusion of fog library in other specs.
|
4
|
+
#rspec spec/unit/s3_source_deps_spec.rb
|
5
|
+
|
6
|
+
describe 'Check Dependencies', :exclude => Object.constants.include?(:Fog) do
|
7
|
+
before(:each) do
|
8
|
+
end
|
9
|
+
it 'should not load fog by default' do
|
10
|
+
begin
|
11
|
+
Fog::Storage::AWS.new()
|
12
|
+
rescue Exception => e
|
13
|
+
expect(e).to be_a_kind_of(NameError)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'lazy loads fog' do
|
18
|
+
begin
|
19
|
+
Chef::Knife::S3Source.fetch('test')
|
20
|
+
rescue Exception => e
|
21
|
+
expect(e).to be_a_kind_of(ArgumentError)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/spec/unit/s3_source_spec.rb
CHANGED
@@ -1,75 +1,75 @@
|
|
1
|
-
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
-
require 'fog/aws'
|
3
|
-
|
4
|
-
describe Chef::Knife::S3Source do
|
5
|
-
before(:each) do
|
6
|
-
@bucket_name = 'mybucket'
|
7
|
-
@test_file_path = 'path/file.pem'
|
8
|
-
@test_file_content = "TEST CONTENT\n"
|
9
|
-
|
10
|
-
Fog.mock!
|
11
|
-
|
12
|
-
{
|
13
|
-
aws_access_key_id: 'aws_access_key_id',
|
14
|
-
aws_secret_access_key: 'aws_secret_access_key'
|
15
|
-
}.each do |key, value|
|
16
|
-
Chef::Config[:knife][key] = value
|
17
|
-
end
|
18
|
-
|
19
|
-
fog = Fog::Storage::AWS.new(
|
20
|
-
aws_access_key_id: 'aws_access_key_id',
|
21
|
-
aws_secret_access_key: 'aws_secret_access_key'
|
22
|
-
)
|
23
|
-
test_dir_obj = fog.directories.create('key' => @bucket_name)
|
24
|
-
test_file_obj = test_dir_obj.files.create('key' => @test_file_path)
|
25
|
-
test_file_obj.body = @test_file_content
|
26
|
-
test_file_obj.save
|
27
|
-
|
28
|
-
@s3_connection = double(Fog::Storage::AWS)
|
29
|
-
@s3_source = Chef::Knife::S3Source.new
|
30
|
-
end
|
31
|
-
|
32
|
-
context "for http URL format" do
|
33
|
-
it 'converts URI to path with leading / removed' do
|
34
|
-
@s3_source.url = "http://s3.amazonaws.com/#{@bucket_name}/#{@test_file_path}"
|
35
|
-
@s3_source.instance_eval { path }
|
36
|
-
expect(@s3_source.instance_eval { path }).to eq(@test_file_path)
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'correctly retrieves the bucket name from the URI' do
|
40
|
-
@s3_source.url = "http://s3.amazonaws.com/#{@bucket_name}/#{@test_file_path}"
|
41
|
-
@s3_source.instance_eval { bucket }
|
42
|
-
expect(@s3_source.instance_eval { bucket }).to eq(@bucket_name)
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'gets back the correct bucket contents' do
|
46
|
-
@s3_source.url = "http://s3.amazonaws.com/#{@bucket_name}/#{@test_file_path}"
|
47
|
-
expect(@s3_source.body).to eq(@test_file_content)
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'gets back a bucket object with bucket_obj' do
|
51
|
-
@s3_source.url = "http://s3.amazonaws.com/#{@bucket_name}/#{@test_file_path}"
|
52
|
-
@s3_source.instance_eval { bucket_obj }
|
53
|
-
expect(@s3_source.instance_eval { bucket_obj }).to be_kind_of(Fog::Storage::AWS::Directory)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context "for s3 URL format" do
|
58
|
-
it 'correctly retrieves the bucket name from the URI' do
|
59
|
-
@s3_source.url = "s3://#{@bucket_name}/#{@test_file_path}"
|
60
|
-
@s3_source.instance_eval { bucket }
|
61
|
-
expect(@s3_source.instance_eval { bucket }).to eq(@bucket_name)
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'gets back the correct bucket contents' do
|
65
|
-
@s3_source.url = "s3://#{@bucket_name}/#{@test_file_path}"
|
66
|
-
expect(@s3_source.body).to eq(@test_file_content)
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'gets back a bucket object with bucket_obj' do
|
70
|
-
@s3_source.url = "s3://#{@bucket_name}/#{@test_file_path}"
|
71
|
-
@s3_source.instance_eval { bucket_obj }
|
72
|
-
expect(@s3_source.instance_eval { bucket_obj }).to be_kind_of(Fog::Storage::AWS::Directory)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
require 'fog/aws'
|
3
|
+
|
4
|
+
describe Chef::Knife::S3Source do
|
5
|
+
before(:each) do
|
6
|
+
@bucket_name = 'mybucket'
|
7
|
+
@test_file_path = 'path/file.pem'
|
8
|
+
@test_file_content = "TEST CONTENT\n"
|
9
|
+
|
10
|
+
Fog.mock!
|
11
|
+
|
12
|
+
{
|
13
|
+
aws_access_key_id: 'aws_access_key_id',
|
14
|
+
aws_secret_access_key: 'aws_secret_access_key'
|
15
|
+
}.each do |key, value|
|
16
|
+
Chef::Config[:knife][key] = value
|
17
|
+
end
|
18
|
+
|
19
|
+
fog = Fog::Storage::AWS.new(
|
20
|
+
aws_access_key_id: 'aws_access_key_id',
|
21
|
+
aws_secret_access_key: 'aws_secret_access_key'
|
22
|
+
)
|
23
|
+
test_dir_obj = fog.directories.create('key' => @bucket_name)
|
24
|
+
test_file_obj = test_dir_obj.files.create('key' => @test_file_path)
|
25
|
+
test_file_obj.body = @test_file_content
|
26
|
+
test_file_obj.save
|
27
|
+
|
28
|
+
@s3_connection = double(Fog::Storage::AWS)
|
29
|
+
@s3_source = Chef::Knife::S3Source.new
|
30
|
+
end
|
31
|
+
|
32
|
+
context "for http URL format" do
|
33
|
+
it 'converts URI to path with leading / removed' do
|
34
|
+
@s3_source.url = "http://s3.amazonaws.com/#{@bucket_name}/#{@test_file_path}"
|
35
|
+
@s3_source.instance_eval { path }
|
36
|
+
expect(@s3_source.instance_eval { path }).to eq(@test_file_path)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'correctly retrieves the bucket name from the URI' do
|
40
|
+
@s3_source.url = "http://s3.amazonaws.com/#{@bucket_name}/#{@test_file_path}"
|
41
|
+
@s3_source.instance_eval { bucket }
|
42
|
+
expect(@s3_source.instance_eval { bucket }).to eq(@bucket_name)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'gets back the correct bucket contents' do
|
46
|
+
@s3_source.url = "http://s3.amazonaws.com/#{@bucket_name}/#{@test_file_path}"
|
47
|
+
expect(@s3_source.body).to eq(@test_file_content)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'gets back a bucket object with bucket_obj' do
|
51
|
+
@s3_source.url = "http://s3.amazonaws.com/#{@bucket_name}/#{@test_file_path}"
|
52
|
+
@s3_source.instance_eval { bucket_obj }
|
53
|
+
expect(@s3_source.instance_eval { bucket_obj }).to be_kind_of(Fog::Storage::AWS::Directory)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "for s3 URL format" do
|
58
|
+
it 'correctly retrieves the bucket name from the URI' do
|
59
|
+
@s3_source.url = "s3://#{@bucket_name}/#{@test_file_path}"
|
60
|
+
@s3_source.instance_eval { bucket }
|
61
|
+
expect(@s3_source.instance_eval { bucket }).to eq(@bucket_name)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'gets back the correct bucket contents' do
|
65
|
+
@s3_source.url = "s3://#{@bucket_name}/#{@test_file_path}"
|
66
|
+
expect(@s3_source.body).to eq(@test_file_content)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'gets back a bucket object with bucket_obj' do
|
70
|
+
@s3_source.url = "s3://#{@bucket_name}/#{@test_file_path}"
|
71
|
+
@s3_source.instance_eval { bucket_obj }
|
72
|
+
expect(@s3_source.instance_eval { bucket_obj }).to be_kind_of(Fog::Storage::AWS::Directory)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|