test-kitchen 1.0.0.beta.4 → 1.0.0.rc.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +50 -1
- data/Gemfile +1 -1
- data/README.md +18 -7
- data/Rakefile +8 -1
- data/features/kitchen_init_command.feature +90 -11
- data/features/step_definitions/git_steps.rb +3 -0
- data/lib/kitchen/busser.rb +79 -45
- data/lib/kitchen/cli.rb +14 -13
- data/lib/kitchen/config.rb +79 -138
- data/lib/kitchen/data_munger.rb +224 -0
- data/lib/kitchen/driver/base.rb +4 -31
- data/lib/kitchen/driver/ssh_base.rb +6 -16
- data/lib/kitchen/driver.rb +4 -0
- data/lib/kitchen/generator/init.rb +20 -9
- data/lib/kitchen/instance.rb +53 -58
- data/lib/kitchen/lazy_hash.rb +50 -0
- data/lib/kitchen/platform.rb +2 -31
- data/lib/kitchen/provisioner/base.rb +55 -9
- data/lib/kitchen/provisioner/chef/berkshelf.rb +76 -0
- data/lib/kitchen/provisioner/chef/librarian.rb +72 -0
- data/lib/kitchen/provisioner/chef_base.rb +159 -78
- data/lib/kitchen/provisioner/chef_solo.rb +6 -36
- data/lib/kitchen/provisioner/chef_zero.rb +70 -59
- data/lib/kitchen/provisioner/dummy.rb +28 -0
- data/lib/kitchen/provisioner.rb +6 -4
- data/lib/kitchen/shell_out.rb +2 -5
- data/lib/kitchen/ssh.rb +1 -1
- data/lib/kitchen/suite.rb +10 -79
- data/lib/kitchen/util.rb +2 -2
- data/lib/kitchen/version.rb +2 -2
- data/lib/kitchen.rb +5 -0
- data/spec/kitchen/config_spec.rb +84 -123
- data/spec/kitchen/data_munger_spec.rb +1412 -0
- data/spec/kitchen/driver/base_spec.rb +30 -0
- data/spec/kitchen/instance_spec.rb +868 -86
- data/spec/kitchen/lazy_hash_spec.rb +63 -0
- data/spec/kitchen/platform_spec.rb +0 -22
- data/spec/kitchen/provisioner/base_spec.rb +210 -0
- data/spec/kitchen/provisioner_spec.rb +70 -0
- data/spec/kitchen/suite_spec.rb +25 -38
- data/spec/spec_helper.rb +1 -0
- data/support/chef-client-zero.rb +51 -35
- data/support/dummy-validation.pem +27 -0
- data/templates/init/kitchen.yml.erb +10 -22
- data/test-kitchen.gemspec +1 -2
- metadata +20 -18
@@ -0,0 +1,63 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Author:: Fletcher Nichol (<fnichol@nichol.ca>)
|
4
|
+
#
|
5
|
+
# Copyright (C) 2013, Fletcher Nichol
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
|
19
|
+
require_relative '../spec_helper'
|
20
|
+
|
21
|
+
require 'kitchen/lazy_hash'
|
22
|
+
|
23
|
+
describe Kitchen::LazyHash do
|
24
|
+
|
25
|
+
let(:context) do
|
26
|
+
stub(:color => "blue", :metal => "heavy")
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:hash) do
|
30
|
+
{
|
31
|
+
:shed_color => lambda { |c| c.color },
|
32
|
+
:barn => "locked",
|
33
|
+
:genre => Proc.new { |c| "#{c.metal} metal"}
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#[]" do
|
38
|
+
|
39
|
+
it "returns regular values for keys" do
|
40
|
+
Kitchen::LazyHash.new(hash, context)[:barn].must_equal "locked"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "invokes call on values that are lambdas" do
|
44
|
+
Kitchen::LazyHash.new(hash, context)[:shed_color].must_equal "blue"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "invokes call on values that are Procs" do
|
48
|
+
Kitchen::LazyHash.new(hash, context)[:genre].must_equal "heavy metal"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "#to_hash" do
|
53
|
+
|
54
|
+
it "invokes any callable values and returns a Hash object" do
|
55
|
+
converted = Kitchen::LazyHash.new(hash, context).to_hash
|
56
|
+
|
57
|
+
converted.must_be_instance_of Hash
|
58
|
+
converted.fetch(:shed_color).must_equal "blue"
|
59
|
+
converted.fetch(:barn).must_equal "locked"
|
60
|
+
converted.fetch(:genre).must_equal "heavy metal"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -30,26 +30,4 @@ describe Kitchen::Platform do
|
|
30
30
|
opts.delete(:name)
|
31
31
|
proc { Kitchen::Platform.new(opts) }.must_raise Kitchen::ClientError
|
32
32
|
end
|
33
|
-
|
34
|
-
describe 'Cheflike' do
|
35
|
-
|
36
|
-
let(:platform) do
|
37
|
-
Kitchen::Platform.new(opts).extend(Kitchen::Platform::Cheflike)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "returns an empty Array given no run_list" do
|
41
|
-
platform.run_list.must_equal []
|
42
|
-
end
|
43
|
-
|
44
|
-
it "returns an empty Hash given no attributes" do
|
45
|
-
platform.attributes.must_equal Hash.new
|
46
|
-
end
|
47
|
-
|
48
|
-
it "returns attributes from constructor" do
|
49
|
-
opts.merge!({ :run_list => ['a', 'b'], :attributes => { :c => 'd' } })
|
50
|
-
platform.name.must_equal 'plata'
|
51
|
-
platform.run_list.must_equal ['a', 'b']
|
52
|
-
platform.attributes.must_equal({ :c => 'd' })
|
53
|
-
end
|
54
|
-
end
|
55
33
|
end
|
@@ -0,0 +1,210 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Author:: Fletcher Nichol (<fnichol@nichol.ca>)
|
4
|
+
#
|
5
|
+
# Copyright (C) 2013, Fletcher Nichol
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
|
19
|
+
require_relative '../../spec_helper'
|
20
|
+
require 'stringio'
|
21
|
+
|
22
|
+
require 'kitchen'
|
23
|
+
|
24
|
+
module Kitchen
|
25
|
+
|
26
|
+
module Provisioner
|
27
|
+
|
28
|
+
class StaticDefaults < Base
|
29
|
+
|
30
|
+
default_config :rank, "captain"
|
31
|
+
default_config :tunables, { "foo" => "fa" }
|
32
|
+
default_config :nice, true
|
33
|
+
end
|
34
|
+
|
35
|
+
class SubclassDefaults < StaticDefaults
|
36
|
+
|
37
|
+
default_config :yea, "ya"
|
38
|
+
end
|
39
|
+
|
40
|
+
class ComputedDefaults < Base
|
41
|
+
|
42
|
+
default_config :beans, "kidney"
|
43
|
+
default_config :fetch_command, "curl"
|
44
|
+
default_config :beans_url do |provisioner|
|
45
|
+
"http://gim.me/#{provisioner[:beans]}"
|
46
|
+
end
|
47
|
+
default_config :command do |provisioner|
|
48
|
+
"#{provisioner[:fetch_command]} #{provisioner[:beans_url]}"
|
49
|
+
end
|
50
|
+
default_config :fetch_url do |provisioner|
|
51
|
+
"http://gim.me/beans-for/#{provisioner.instance.name}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe Kitchen::Provisioner::Base do
|
58
|
+
|
59
|
+
let(:config) { Hash.new }
|
60
|
+
let(:logger_io) { StringIO.new }
|
61
|
+
let(:instance_logger) { Kitchen::Logger.new(:logdev => logger_io) }
|
62
|
+
|
63
|
+
let(:instance) do
|
64
|
+
stub(:name => "coolbeans", :logger => instance_logger)
|
65
|
+
end
|
66
|
+
|
67
|
+
let(:provisioner) do
|
68
|
+
p = Kitchen::Provisioner::Base.new(config)
|
69
|
+
p.instance = instance
|
70
|
+
p
|
71
|
+
end
|
72
|
+
|
73
|
+
it "#instance returns its instance" do
|
74
|
+
provisioner.instance.must_equal instance
|
75
|
+
end
|
76
|
+
|
77
|
+
it "#name returns its class name as a string" do
|
78
|
+
provisioner.name.must_equal "Base"
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "user config" do
|
82
|
+
|
83
|
+
before do
|
84
|
+
config[:animals] = %w{cats dogs}
|
85
|
+
config[:coolness] = true
|
86
|
+
end
|
87
|
+
|
88
|
+
it "injects config into the provisioner" do
|
89
|
+
provisioner[:animals].must_equal ["cats", "dogs"]
|
90
|
+
provisioner[:coolness].must_equal true
|
91
|
+
end
|
92
|
+
|
93
|
+
it ":root_path defaults to /tmp/kitchen" do
|
94
|
+
provisioner[:root_path].must_equal "/tmp/kitchen"
|
95
|
+
end
|
96
|
+
|
97
|
+
it ":sudo defaults to true" do
|
98
|
+
provisioner[:sudo].must_equal true
|
99
|
+
end
|
100
|
+
|
101
|
+
it "#config_keys returns the config keys" do
|
102
|
+
provisioner.config_keys.sort.
|
103
|
+
must_equal [:animals, :coolness, :root_path, :sudo]
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe ".default_config" do
|
108
|
+
|
109
|
+
describe "static default config" do
|
110
|
+
|
111
|
+
let(:provisioner) do
|
112
|
+
p = Kitchen::Provisioner::StaticDefaults.new(config)
|
113
|
+
p.instance = instance
|
114
|
+
p
|
115
|
+
end
|
116
|
+
|
117
|
+
it "uses default config" do
|
118
|
+
provisioner[:rank].must_equal "captain"
|
119
|
+
provisioner[:tunables]["foo"].must_equal "fa"
|
120
|
+
provisioner[:nice].must_equal true
|
121
|
+
end
|
122
|
+
|
123
|
+
it "uses user config over default config" do
|
124
|
+
config[:rank] = "commander"
|
125
|
+
config[:nice] = :maybe
|
126
|
+
|
127
|
+
provisioner[:rank].must_equal "commander"
|
128
|
+
provisioner[:tunables]["foo"].must_equal "fa"
|
129
|
+
provisioner[:nice].must_equal :maybe
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "inherited static default config" do
|
134
|
+
|
135
|
+
let(:provisioner) do
|
136
|
+
p = Kitchen::Provisioner::SubclassDefaults.new(config)
|
137
|
+
p.instance = instance
|
138
|
+
p
|
139
|
+
end
|
140
|
+
|
141
|
+
it "contains defaults from superclass" do
|
142
|
+
provisioner[:rank].must_equal "captain"
|
143
|
+
provisioner[:tunables]["foo"].must_equal "fa"
|
144
|
+
provisioner[:nice].must_equal true
|
145
|
+
provisioner[:yea].must_equal "ya"
|
146
|
+
end
|
147
|
+
|
148
|
+
it "uses user config over default config" do
|
149
|
+
config[:rank] = "commander"
|
150
|
+
config[:nice] = :maybe
|
151
|
+
|
152
|
+
provisioner[:rank].must_equal "commander"
|
153
|
+
provisioner[:tunables]["foo"].must_equal "fa"
|
154
|
+
provisioner[:nice].must_equal :maybe
|
155
|
+
provisioner[:yea].must_equal "ya"
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe "computed default config" do
|
160
|
+
|
161
|
+
let(:provisioner) do
|
162
|
+
p = Kitchen::Provisioner::ComputedDefaults.new(config)
|
163
|
+
p.instance = instance
|
164
|
+
p
|
165
|
+
end
|
166
|
+
|
167
|
+
it "uses computed config" do
|
168
|
+
provisioner[:beans_url].must_equal "http://gim.me/kidney"
|
169
|
+
provisioner[:command].must_equal "curl http://gim.me/kidney"
|
170
|
+
end
|
171
|
+
|
172
|
+
it "has access to instance object" do
|
173
|
+
provisioner[:fetch_url].must_equal "http://gim.me/beans-for/coolbeans"
|
174
|
+
end
|
175
|
+
|
176
|
+
it "uses user config over default config" do
|
177
|
+
config[:command] = "echo listentome"
|
178
|
+
|
179
|
+
provisioner[:command].must_equal "echo listentome"
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
describe "#logger" do
|
185
|
+
|
186
|
+
it "if instance is set, use its logger" do
|
187
|
+
provisioner.send(:logger).must_equal instance_logger
|
188
|
+
end
|
189
|
+
|
190
|
+
it "if instance is not set, use Kitchen.logger" do
|
191
|
+
provisioner.instance = nil
|
192
|
+
provisioner.send(:logger).must_equal Kitchen.logger
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
describe "#sudo" do
|
197
|
+
|
198
|
+
it "if :sudo is set, prepend sudo command" do
|
199
|
+
config[:sudo] = true
|
200
|
+
|
201
|
+
provisioner.send(:sudo, "wakka").must_equal("sudo -E wakka")
|
202
|
+
end
|
203
|
+
|
204
|
+
it "if :sudo is falsy, do not include sudo command" do
|
205
|
+
config[:sudo] = false
|
206
|
+
|
207
|
+
provisioner.send(:sudo, "wakka").must_equal("wakka")
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Author:: Fletcher Nichol (<fnichol@nichol.ca>)
|
4
|
+
#
|
5
|
+
# Copyright (C) 2013, Fletcher Nichol
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
|
19
|
+
require_relative '../spec_helper'
|
20
|
+
|
21
|
+
require 'kitchen/errors'
|
22
|
+
require 'kitchen/logging'
|
23
|
+
require 'kitchen/provisioner'
|
24
|
+
require 'kitchen/provisioner/base'
|
25
|
+
|
26
|
+
module Kitchen
|
27
|
+
|
28
|
+
module Provisioner
|
29
|
+
|
30
|
+
class Coolbeans < Kitchen::Provisioner::Base
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe Kitchen::Provisioner do
|
36
|
+
|
37
|
+
describe ".for_plugin" do
|
38
|
+
|
39
|
+
before do
|
40
|
+
Kitchen::Provisioner.stubs(:require).returns(true)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns a provisioner object of the correct class" do
|
44
|
+
provisioner = Kitchen::Provisioner.for_plugin("coolbeans", {})
|
45
|
+
|
46
|
+
provisioner.must_be_kind_of Kitchen::Provisioner::Coolbeans
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns a provisioner initialized with its config" do
|
50
|
+
provisioner = Kitchen::Provisioner.for_plugin("coolbeans", :foo => "bar")
|
51
|
+
|
52
|
+
provisioner[:foo].must_equal "bar"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "raises ClientError if the provisioner could not be required" do
|
56
|
+
Kitchen::Provisioner.stubs(:require).raises(LoadError)
|
57
|
+
|
58
|
+
proc { Kitchen::Provisioner.for_plugin("coolbeans", {}) }.
|
59
|
+
must_raise Kitchen::ClientError
|
60
|
+
end
|
61
|
+
|
62
|
+
it "raises ClientError if the provisioner's class constant was not found" do
|
63
|
+
# pretend require worked
|
64
|
+
Kitchen::Provisioner.stubs(:require).returns(true)
|
65
|
+
|
66
|
+
proc { Kitchen::Provisioner.for_plugin('nope', {}) }.
|
67
|
+
must_raise Kitchen::ClientError
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/spec/kitchen/suite_spec.rb
CHANGED
@@ -23,53 +23,40 @@ require 'kitchen/suite'
|
|
23
23
|
|
24
24
|
describe Kitchen::Suite do
|
25
25
|
|
26
|
-
let(:opts) do
|
26
|
+
let(:opts) do
|
27
|
+
{
|
28
|
+
:name => "suitezy",
|
29
|
+
:includes => ["testbuntu", "testcent"],
|
30
|
+
:excludes => ["prodbuntu"]
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
27
34
|
let(:suite) { Kitchen::Suite.new(opts) }
|
28
35
|
|
36
|
+
it "returns the name" do
|
37
|
+
suite.name.must_equal "suitezy"
|
38
|
+
end
|
39
|
+
|
29
40
|
it "raises an ArgumentError if name is missing" do
|
30
41
|
opts.delete(:name)
|
31
42
|
proc { Kitchen::Suite.new(opts) }.must_raise Kitchen::ClientError
|
32
43
|
end
|
33
44
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
it "returns an empty Hash given no attributes" do
|
39
|
-
suite.attributes.must_equal Hash.new
|
40
|
-
end
|
41
|
-
|
42
|
-
it "returns an empty Array given no excludes" do
|
43
|
-
suite.excludes.must_equal Array.new
|
44
|
-
end
|
45
|
-
|
46
|
-
it "returns nil given no data_bags_path" do
|
47
|
-
suite.data_bags_path.must_be_nil
|
48
|
-
end
|
49
|
-
|
50
|
-
it "returns nil given no roles_path" do
|
51
|
-
suite.roles_path.must_be_nil
|
52
|
-
end
|
45
|
+
it "returns the includes" do
|
46
|
+
suite.includes.must_equal ["testbuntu", "testcent"]
|
47
|
+
end
|
53
48
|
|
54
|
-
|
55
|
-
|
56
|
-
|
49
|
+
it "returns an empty Array when includes not given" do
|
50
|
+
opts.delete(:includes)
|
51
|
+
suite.includes.must_equal []
|
52
|
+
end
|
57
53
|
|
58
|
-
|
59
|
-
|
60
|
-
|
54
|
+
it "returns the excludes" do
|
55
|
+
suite.excludes.must_equal ["prodbuntu"]
|
56
|
+
end
|
61
57
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
:encrypted_data_bag_secret_key_path => 'secret' })
|
66
|
-
suite.name.must_equal 'suitezy'
|
67
|
-
suite.run_list.must_equal ['doowah']
|
68
|
-
suite.attributes.must_equal({ :a => 'b' })
|
69
|
-
suite.data_bags_path.must_equal 'crazy'
|
70
|
-
suite.roles_path.must_equal 'town'
|
71
|
-
suite.nodes_path.must_equal 'woowoo'
|
72
|
-
suite.encrypted_data_bag_secret_key_path.must_equal 'secret'
|
73
|
-
end
|
58
|
+
it "returns an empty Array when excludes not given" do
|
59
|
+
opts.delete(:excludes)
|
60
|
+
suite.excludes.must_equal []
|
74
61
|
end
|
75
62
|
end
|