test-kitchen 0.5.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.
- data/bin/kitchen +7 -0
- data/config/Cheffile +55 -0
- data/config/Kitchenfile +39 -0
- data/config/Vagrantfile +109 -0
- data/cookbooks/test-kitchen/attributes/default.rb +25 -0
- data/cookbooks/test-kitchen/libraries/helpers.rb +25 -0
- data/cookbooks/test-kitchen/metadata.rb +27 -0
- data/cookbooks/test-kitchen/recipes/chef.rb +19 -0
- data/cookbooks/test-kitchen/recipes/compat.rb +39 -0
- data/cookbooks/test-kitchen/recipes/default.rb +51 -0
- data/cookbooks/test-kitchen/recipes/erlang.rb +19 -0
- data/cookbooks/test-kitchen/recipes/ruby.rb +40 -0
- data/lib/test-kitchen.rb +34 -0
- data/lib/test-kitchen/cli.rb +267 -0
- data/lib/test-kitchen/cli/destroy.rb +42 -0
- data/lib/test-kitchen/cli/init.rb +37 -0
- data/lib/test-kitchen/cli/platform_list.rb +37 -0
- data/lib/test-kitchen/cli/project_info.rb +44 -0
- data/lib/test-kitchen/cli/ssh.rb +36 -0
- data/lib/test-kitchen/cli/status.rb +36 -0
- data/lib/test-kitchen/cli/test.rb +60 -0
- data/lib/test-kitchen/dsl.rb +59 -0
- data/lib/test-kitchen/environment.rb +164 -0
- data/lib/test-kitchen/platform.rb +63 -0
- data/lib/test-kitchen/project.rb +23 -0
- data/lib/test-kitchen/project/base.rb +159 -0
- data/lib/test-kitchen/project/cookbook.rb +87 -0
- data/lib/test-kitchen/project/cookbook_copy.rb +58 -0
- data/lib/test-kitchen/project/ruby.rb +37 -0
- data/lib/test-kitchen/project/supported_platforms.rb +75 -0
- data/lib/test-kitchen/runner.rb +20 -0
- data/lib/test-kitchen/runner/base.rb +144 -0
- data/lib/test-kitchen/runner/vagrant.rb +92 -0
- data/lib/test-kitchen/scaffold.rb +73 -0
- data/lib/test-kitchen/ui.rb +73 -0
- data/lib/test-kitchen/version.rb +21 -0
- metadata +196 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2012 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'test-kitchen/cli'
|
20
|
+
require 'test-kitchen/runner'
|
21
|
+
|
22
|
+
module TestKitchen
|
23
|
+
module CLI
|
24
|
+
class Kitchen
|
25
|
+
class Ssh < Kitchen
|
26
|
+
|
27
|
+
banner "kitchen ssh (options)"
|
28
|
+
|
29
|
+
def run
|
30
|
+
runner.ssh
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2012 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'test-kitchen/cli'
|
20
|
+
require 'test-kitchen/runner'
|
21
|
+
|
22
|
+
module TestKitchen
|
23
|
+
module CLI
|
24
|
+
class Kitchen
|
25
|
+
class Status < Kitchen
|
26
|
+
|
27
|
+
banner "kitchen status (options)"
|
28
|
+
|
29
|
+
def run
|
30
|
+
runner.status
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2012 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'test-kitchen/cli'
|
20
|
+
require 'test-kitchen/runner'
|
21
|
+
|
22
|
+
module TestKitchen
|
23
|
+
module CLI
|
24
|
+
class Kitchen
|
25
|
+
class Test < Kitchen
|
26
|
+
|
27
|
+
banner "kitchen test (options)"
|
28
|
+
|
29
|
+
def run
|
30
|
+
warn_for_non_buildable_platforms(env.platform_names)
|
31
|
+
env.project.each_build(env.platform_names,
|
32
|
+
config[:configuration]) do |platform,configuration|
|
33
|
+
runner = TestKitchen::Runner.for_platform(env,
|
34
|
+
{:platform => platform, :configuration => configuration})
|
35
|
+
runner.preflight_check
|
36
|
+
begin
|
37
|
+
runner.provision
|
38
|
+
runner.test
|
39
|
+
rescue
|
40
|
+
raise
|
41
|
+
ensure
|
42
|
+
runner.destroy if config[:teardown]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def warn_for_non_buildable_platforms(platform_names)
|
50
|
+
if env.project.respond_to?(:non_buildable_platforms)
|
51
|
+
env.project.non_buildable_platforms(platform_names).each do |platform|
|
52
|
+
env.ui.info("Cookbook metadata specifies an unrecognized platform that will not be tested: #{platform}", :red)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2012 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'hashr'
|
20
|
+
require 'test-kitchen/project'
|
21
|
+
require 'test-kitchen/platform'
|
22
|
+
|
23
|
+
module TestKitchen
|
24
|
+
module DSL
|
25
|
+
|
26
|
+
module BasicDSL
|
27
|
+
def integration_test(name, &block)
|
28
|
+
env.project = Project::Ruby.new(name.to_s, &block)
|
29
|
+
end
|
30
|
+
|
31
|
+
def platform(name, &block)
|
32
|
+
env.platforms[name.to_s] = Platform.new(name, &block)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
module CookbookDSL
|
36
|
+
def cookbook(name, &block)
|
37
|
+
env.project = Project::Cookbook.new(name.to_s, &block)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class File
|
42
|
+
include BasicDSL
|
43
|
+
include CookbookDSL
|
44
|
+
|
45
|
+
attr_reader :env
|
46
|
+
|
47
|
+
def load(path, env)
|
48
|
+
@env = env
|
49
|
+
begin
|
50
|
+
self.instance_eval(::File.read(path))
|
51
|
+
rescue SyntaxError
|
52
|
+
env.ui.info('Your Kitchenfile could not be loaded. Please check it for errors.', :red)
|
53
|
+
raise
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2012 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'fileutils'
|
20
|
+
require 'hashr'
|
21
|
+
require 'pathname'
|
22
|
+
require 'yajl'
|
23
|
+
|
24
|
+
module TestKitchen
|
25
|
+
|
26
|
+
class Environment
|
27
|
+
|
28
|
+
attr_reader :root_path
|
29
|
+
attr_reader :tmp_path
|
30
|
+
attr_reader :cache_path
|
31
|
+
attr_reader :config
|
32
|
+
attr_reader :ui
|
33
|
+
attr_reader :kitchenfile_name
|
34
|
+
attr_accessor :project
|
35
|
+
|
36
|
+
KITCHEN_SUBDIRS = [".", "kitchen", "test/kitchen"]
|
37
|
+
|
38
|
+
def initialize(options={})
|
39
|
+
|
40
|
+
options[:kitchenfile_name] ||= []
|
41
|
+
options[:kitchenfile_name] = [options[:kitchenfile_name]] if !options[:kitchenfile_name].is_a?(Array)
|
42
|
+
options[:kitchenfile_name] += ["Kitchenfile", "kitchenfile"]
|
43
|
+
@kitchenfile_name = options[:kitchenfile_name]
|
44
|
+
|
45
|
+
if options[:ignore_kitchenfile] || ! root_path
|
46
|
+
@root_path = Pathname.new(Dir.pwd) + 'test' + 'kitchen'
|
47
|
+
@project = Project::Cookbook.new(File.basename(Dir.pwd))
|
48
|
+
end
|
49
|
+
|
50
|
+
@tmp_path = root_path.join('.kitchen')
|
51
|
+
@cache_path = tmp_path.join('.cache')
|
52
|
+
@ui = options[:ui]
|
53
|
+
|
54
|
+
setup_tmp_path
|
55
|
+
end
|
56
|
+
|
57
|
+
# Inspired by Vagrant::Environment.root_path...danke Mitchell!
|
58
|
+
#
|
59
|
+
# The root path is the path where the top-most (loaded last)
|
60
|
+
# Vagrantfile resides. It can be considered the project root for
|
61
|
+
# this environment.
|
62
|
+
#
|
63
|
+
# @return [String]
|
64
|
+
def root_path
|
65
|
+
return @root_path if defined?(@root_path)
|
66
|
+
|
67
|
+
KITCHEN_SUBDIRS.each do |dir|
|
68
|
+
path = Pathname.new(Dir.pwd).join(dir)
|
69
|
+
found = kitchenfile_name.find do |rootfile|
|
70
|
+
path.join(rootfile).exist?
|
71
|
+
end
|
72
|
+
@root_path = path if found
|
73
|
+
end
|
74
|
+
|
75
|
+
@root_path
|
76
|
+
end
|
77
|
+
|
78
|
+
def platforms
|
79
|
+
@platforms ||= {}
|
80
|
+
end
|
81
|
+
|
82
|
+
def all_platforms
|
83
|
+
Hash[*platforms.values.map do |p|
|
84
|
+
p.versions.map{|key,value| ["#{p.name}-#{key}", value]}
|
85
|
+
end.flatten]
|
86
|
+
end
|
87
|
+
|
88
|
+
def platform_names
|
89
|
+
all_platforms.keys
|
90
|
+
end
|
91
|
+
|
92
|
+
def create_tmp_file(file_name, contents)
|
93
|
+
File.open(tmp_path.join(file_name), 'w') do |f|
|
94
|
+
f.write(contents)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def cookbook_paths
|
99
|
+
@cookbook_paths ||= begin
|
100
|
+
p = [tmp_path.join('cookbooks').to_s]
|
101
|
+
p << root_path.join('cookbooks').to_s if root_path.join('cookbooks').exist?
|
102
|
+
p
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def setup_tmp_path
|
107
|
+
# pre-create required dirs
|
108
|
+
[ tmp_path, cache_path ].each do |dir|
|
109
|
+
FileUtils.mkdir_p(dir)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
#---------------------------------------------------------------
|
114
|
+
# Load Methods
|
115
|
+
#---------------------------------------------------------------
|
116
|
+
|
117
|
+
# Returns a boolean representing if the environment has been
|
118
|
+
# loaded or not.
|
119
|
+
#
|
120
|
+
# @return [Bool]
|
121
|
+
def loaded?
|
122
|
+
!!@loaded
|
123
|
+
end
|
124
|
+
|
125
|
+
def load!
|
126
|
+
if !loaded?
|
127
|
+
@loaded = true
|
128
|
+
load_kitchenfiles
|
129
|
+
end
|
130
|
+
|
131
|
+
self
|
132
|
+
end
|
133
|
+
|
134
|
+
private
|
135
|
+
|
136
|
+
# Inspired by Vagrant::Environment.find_vagrantfile...danke Mitchell!
|
137
|
+
#
|
138
|
+
# Finds the Kitchenfile in the given directory.
|
139
|
+
#
|
140
|
+
# @param [Pathname] path Path to search in.
|
141
|
+
# @return [Pathname]
|
142
|
+
def find_kitchenfile(search_path)
|
143
|
+
@kitchenfile_name.each do |kitchenfile|
|
144
|
+
current_path = search_path.join(kitchenfile)
|
145
|
+
return current_path if current_path.exist?
|
146
|
+
end
|
147
|
+
|
148
|
+
nil
|
149
|
+
end
|
150
|
+
|
151
|
+
def load_kitchenfiles
|
152
|
+
# load Kitchenfile that ships with gem...seeds defaults
|
153
|
+
kitchenfiles = [File.expand_path("config/Kitchenfile", TestKitchen.source_root)]
|
154
|
+
# Load the user's Kitchenfile
|
155
|
+
kitchenfiles << find_kitchenfile(root_path) if root_path
|
156
|
+
|
157
|
+
kitchenfiles.flatten.compact.each do |kitchenfile|
|
158
|
+
dsl_file = DSL::File.new
|
159
|
+
dsl_file.load(kitchenfile, self)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2012 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'hashr'
|
20
|
+
require 'chef/mixin/params_validate'
|
21
|
+
|
22
|
+
module TestKitchen
|
23
|
+
class Platform
|
24
|
+
include Chef::Mixin::ParamsValidate
|
25
|
+
|
26
|
+
attr_reader :name, :versions
|
27
|
+
|
28
|
+
def initialize(name, &block)
|
29
|
+
raise ArgumentError, "Platform name must be specified" if name.nil? || name.empty?
|
30
|
+
|
31
|
+
@name = name
|
32
|
+
@versions = {}
|
33
|
+
instance_eval(&block) if block_given?
|
34
|
+
end
|
35
|
+
|
36
|
+
def version(name, &block)
|
37
|
+
versions[name.to_s] = Version.new(name, &block)
|
38
|
+
end
|
39
|
+
|
40
|
+
class Version
|
41
|
+
include Chef::Mixin::ParamsValidate
|
42
|
+
|
43
|
+
attr_reader :name
|
44
|
+
attr_writer :box, :box_url
|
45
|
+
|
46
|
+
def initialize(name, &block)
|
47
|
+
raise ArgumentError, "Version name must be specified" if name.nil? || name.empty?
|
48
|
+
@name = name
|
49
|
+
instance_eval(&block) if block_given?
|
50
|
+
end
|
51
|
+
|
52
|
+
def box(arg=nil)
|
53
|
+
set_or_return(:box, arg, {})
|
54
|
+
end
|
55
|
+
|
56
|
+
def box_url(arg=nil)
|
57
|
+
set_or_return(:box_url, arg, {})
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2012 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'test-kitchen/project/base'
|
20
|
+
require 'test-kitchen/project/ruby'
|
21
|
+
require 'test-kitchen/project/supported_platforms'
|
22
|
+
require 'test-kitchen/project/cookbook_copy'
|
23
|
+
require 'test-kitchen/project/cookbook'
|