Class: ChefDK::ComponentTest
- Inherits:
-
Object
- Object
- ChefDK::ComponentTest
show all
- Includes:
- Helpers
- Defined in:
- lib/chef-dk/component_test.rb
Defined Under Namespace
Classes: NullTestResult
Constant Summary
collapse
- DEFAULT_TEST =
lambda { |context| NullTestResult.new }
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Helpers
#err, #msg, #omnibus_apps_dir, #omnibus_bin_dir, #omnibus_embedded_bin_dir, #stderr, #stdout, #system_command
Constructor Details
Returns a new instance of ComponentTest.
48
49
50
51
52
53
|
# File 'lib/chef-dk/component_test.rb', line 48
def initialize(name)
@name = name
@unit_test = DEFAULT_TEST
@integration_test = DEFAULT_TEST
@smoke_test = DEFAULT_TEST
end
|
Instance Attribute Details
#base_dir ⇒ Object
Returns the value of attribute base_dir.
42
43
44
|
# File 'lib/chef-dk/component_test.rb', line 42
def base_dir
@base_dir
end
|
#name ⇒ Object
Returns the value of attribute name.
46
47
48
|
# File 'lib/chef-dk/component_test.rb', line 46
def name
@name
end
|
#omnibus_root ⇒ Object
128
129
130
|
# File 'lib/chef-dk/component_test.rb', line 128
def omnibus_root
@omnibus_root or raise "`omnibus_root` must be set before running tests"
end
|
Instance Method Details
#assert_present! ⇒ Object
102
103
104
105
106
|
# File 'lib/chef-dk/component_test.rb', line 102
def assert_present!
unless File.exists?( component_path )
raise MissingComponentError.new(name)
end
end
|
#component_path ⇒ Object
120
121
122
|
# File 'lib/chef-dk/component_test.rb', line 120
def component_path
File.join(omnibus_apps_dir, base_dir)
end
|
#default_command_options ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/chef-dk/component_test.rb', line 108
def default_command_options
{
:cwd => component_path,
:env => {
path_variable_key => omnibus_path
},
:timeout => 3600
}
end
|
#integration_test(&test_block) ⇒ Object
63
64
65
|
# File 'lib/chef-dk/component_test.rb', line 63
def integration_test(&test_block)
@integration_test = test_block
end
|
#omnibus_path ⇒ Object
132
133
134
|
# File 'lib/chef-dk/component_test.rb', line 132
def omnibus_path
[omnibus_bin_dir, omnibus_embedded_bin_dir, ENV['PATH']].join(File::PATH_SEPARATOR)
end
|
#path_variable_key ⇒ Object
136
137
138
|
# File 'lib/chef-dk/component_test.rb', line 136
def path_variable_key
ENV.keys.grep(/\Apath\Z/i).first
end
|
#run_in_tmpdir(command, options = {}) ⇒ Object
89
90
91
92
93
94
|
# File 'lib/chef-dk/component_test.rb', line 89
def run_in_tmpdir(command, options={})
tmpdir do |dir|
options[:cwd] = dir
sh(command, options)
end
end
|
#run_integration_test ⇒ Object
67
68
69
|
# File 'lib/chef-dk/component_test.rb', line 67
def run_integration_test
instance_eval(&@integration_test)
end
|
#run_smoke_test ⇒ Object
75
76
77
|
# File 'lib/chef-dk/component_test.rb', line 75
def run_smoke_test
instance_eval(&@smoke_test)
end
|
#run_unit_test ⇒ Object
59
60
61
|
# File 'lib/chef-dk/component_test.rb', line 59
def run_unit_test
instance_eval(&@unit_test)
end
|
#sh(command, options = {}) ⇒ Object
79
80
81
82
83
84
85
86
87
|
# File 'lib/chef-dk/component_test.rb', line 79
def sh(command, options={})
combined_opts = default_command_options.merge(options)
if options.key?(:env)
combined_opts[:env] = default_command_options[:env].merge(options[:env])
end
system_command(command, combined_opts)
end
|
#smoke_test(&test_block) ⇒ Object
71
72
73
|
# File 'lib/chef-dk/component_test.rb', line 71
def smoke_test(&test_block)
@smoke_test = test_block
end
|
#tmpdir ⇒ Object
96
97
98
99
100
|
# File 'lib/chef-dk/component_test.rb', line 96
def tmpdir
Dir.mktmpdir do |tmpdir|
yield tmpdir
end
end
|
#unit_test(&test_block) ⇒ Object
55
56
57
|
# File 'lib/chef-dk/component_test.rb', line 55
def unit_test(&test_block)
@unit_test = test_block
end
|