forked from gina-alaska/chef-essentials-hackday-2016
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThorfile
77 lines (66 loc) · 2.02 KB
/
Thorfile
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
75
76
77
# encoding: utf-8
# Copyright (c) 2016 The Authors, All Rights Reserved.
require 'bundler'
require 'bundler/setup'
require 'berkshelf/thor'
begin
require 'kitchen/thor_tasks'
Kitchen::ThorTasks.new
rescue LoadError
puts '>>>>> Kitchen gem not loaded, omitting tasks' unless ENV['CI']
end
# Lint Class. Can run foodcritic, rubocop, or both.
class Lint < Thor
default_task :all
desc 'rubocop', 'Run RuboCop on all Ruby files'
def rubocop
say 'Performing linting and style checking with RuboCop...', :white
success = system 'rubocop'
exit(10) unless success
say 'Finished RuboCop linting with no offenses.', :green
end
desc 'foodcritic', 'Lint Chef cookbooks with Foodcritic'
def foodcritic
say 'Performing Chef cookbook linting with Foodcritic...', :white
success = system('foodcritic', '-P', '-f correctness', '-X spec/**/*',
Dir.pwd)
exit(10) unless success
say 'Finished Foodcritic linting with no offenses.', :green
end
desc 'all', 'Run all lint tasks'
def all
say 'Running all linters...', :white
rubocop
foodcritic
end
end
# Unit testing Class. Can run chefspec.
class Unit < Thor
default_task :all
desc 'chefspec', 'Run Chefspec'
def chefspec
say 'Running chefspec...', :white
success = system('rspec --color --format documentation')
exit(10) unless success
say 'Finished running Chefspec with no failures.', :green
end
desc 'all', 'Run all unit tests'
def all
say 'Running all unit tests...', :white
chefspec
end
end
# Acceptance testing class. Runs all tests and must validate before push/merge.
class Acceptance < Thor
default_task :all
desc 'all', 'Run all acceptance tests. First runs all lint tests, then unit,'\
' and then kitchen converge.'
def all
say 'Running all acceptance tests...', :white
invoke 'lint:all'
invoke 'unit:all'
invoke 'kitchen:all'
say 'Finishing running all acceptance tests with no issues. Changes should'\
' now be valid for push/merge.', :green
end
end