This repository has been archived by the owner on Oct 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathRakefile
74 lines (62 loc) · 2.08 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# !/usr/bin/env rake
require 'foodcritic'
require 'rspec/core/rake_task'
require 'cookstyle'
desc 'Runs knife cookbook test'
task :knife do
sh 'bundle exec knife cookbook test cookbook -o ./ -a'
end
desc 'Runs ChefSpec tests'
task :chefspec do
sh 'rspec'
end
desc 'Runs foodcritic test'
task :foodcritic do
FoodCritic::Rake::LintTask.new
sh 'bundle exec foodcritic -f any .'
end
desc 'Runs rspec tests in test/unit folder'
task :unit do
RSpec::Core::RakeTask.new(:unit) do |t|
t.pattern = 'test/unit/**/*_spec.rb'
end
end
desc 'Runs cookstyle'
task :cookstyle do
sh 'bundle exec cookstyle'
end
desc 'Run Test Kitchen integration tests'
namespace :integration do
# Gets a collection of instances.
#
# @param regexp [String] regular expression to match against instance names.
# @param config [Hash] configuration values for the `Kitchen::Config` class.
# @return [Collection<Instance>] all instances.
def kitchen_instances(regexp, config)
instances = Kitchen::Config.new(config).instances
return instances if regexp.nil? || regexp == 'all'
instances.get_all(Regexp.new(regexp))
end
# Runs a test kitchen action against some instances.
#
# @param action [String] kitchen action to run (defaults to `'test'`).
# @param regexp [String] regular expression to match against instance names.
# @param loader_config [Hash] loader configuration options.
# @return void
def run_kitchen(action, regexp, loader_config = {})
action = 'test' if action.nil?
require 'kitchen'
Kitchen.logger = Kitchen.default_file_logger
config = { loader: Kitchen::Loader::YAML.new(loader_config) }
kitchen_instances(regexp, config).each { |i| i.send(action) }
end
desc 'Run integration tests with kitchen-vagrant'
task :vagrant, [:regexp, :action] do |_t, args|
run_kitchen(args.action, args.regexp)
end
desc 'Run integration tests with kitchen-docker'
task :docker, [:regexp, :action] do |_t, args|
run_kitchen(args.action, args.regexp, local_config: '.kitchen.docker.yml')
end
end
task default: [:foodcritic, :knife, :unit, :chefspec, :cookstyle]