chef-dk 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.md +192 -0
  3. data/LICENSE +201 -0
  4. data/README.md +198 -0
  5. data/Rakefile +18 -0
  6. data/bin/chef +25 -0
  7. data/lib/chef-dk.rb +19 -0
  8. data/lib/chef-dk/builtin_commands.rb +31 -0
  9. data/lib/chef-dk/chef_runner.rb +83 -0
  10. data/lib/chef-dk/cli.rb +135 -0
  11. data/lib/chef-dk/command/base.rb +71 -0
  12. data/lib/chef-dk/command/exec.rb +33 -0
  13. data/lib/chef-dk/command/gem.rb +47 -0
  14. data/lib/chef-dk/command/generate.rb +97 -0
  15. data/lib/chef-dk/command/generator_commands.rb +417 -0
  16. data/lib/chef-dk/command/shell_init.rb +80 -0
  17. data/lib/chef-dk/command/verify.rb +226 -0
  18. data/lib/chef-dk/commands_map.rb +115 -0
  19. data/lib/chef-dk/component_test.rb +142 -0
  20. data/lib/chef-dk/cookbook_metadata.rb +36 -0
  21. data/lib/chef-dk/cookbook_omnifetch.rb +29 -0
  22. data/lib/chef-dk/cookbook_profiler/git.rb +95 -0
  23. data/lib/chef-dk/cookbook_profiler/identifiers.rb +79 -0
  24. data/lib/chef-dk/cookbook_profiler/null_scm.rb +32 -0
  25. data/lib/chef-dk/exceptions.rb +46 -0
  26. data/lib/chef-dk/generator.rb +70 -0
  27. data/lib/chef-dk/helpers.rb +95 -0
  28. data/lib/chef-dk/policyfile/chef_server_cookbook_source.rb +46 -0
  29. data/lib/chef-dk/policyfile/community_cookbook_source.rb +84 -0
  30. data/lib/chef-dk/policyfile/cookbook_sources.rb +20 -0
  31. data/lib/chef-dk/policyfile/cookbook_spec.rb +96 -0
  32. data/lib/chef-dk/policyfile/dsl.rb +148 -0
  33. data/lib/chef-dk/policyfile/null_cookbook_source.rb +37 -0
  34. data/lib/chef-dk/policyfile_compiler.rb +217 -0
  35. data/lib/chef-dk/policyfile_lock.rb +243 -0
  36. data/lib/chef-dk/shell_out.rb +36 -0
  37. data/lib/chef-dk/skeletons/code_generator/files/default/Berksfile +3 -0
  38. data/lib/chef-dk/skeletons/code_generator/files/default/chefignore +96 -0
  39. data/lib/chef-dk/skeletons/code_generator/files/default/converge_spec.rb +9 -0
  40. data/lib/chef-dk/skeletons/code_generator/files/default/gitignore +16 -0
  41. data/lib/chef-dk/skeletons/code_generator/files/default/spec_helper.rb +8 -0
  42. data/lib/chef-dk/skeletons/code_generator/metadata.rb +8 -0
  43. data/lib/chef-dk/skeletons/code_generator/recipes/app.rb +65 -0
  44. data/lib/chef-dk/skeletons/code_generator/recipes/attribute.rb +12 -0
  45. data/lib/chef-dk/skeletons/code_generator/recipes/cookbook.rb +50 -0
  46. data/lib/chef-dk/skeletons/code_generator/recipes/cookbook_file.rb +24 -0
  47. data/lib/chef-dk/skeletons/code_generator/recipes/lwrp.rb +23 -0
  48. data/lib/chef-dk/skeletons/code_generator/recipes/recipe.rb +9 -0
  49. data/lib/chef-dk/skeletons/code_generator/recipes/template.rb +32 -0
  50. data/lib/chef-dk/skeletons/code_generator/templates/default/README.md.erb +4 -0
  51. data/lib/chef-dk/skeletons/code_generator/templates/default/attribute.rb.erb +0 -0
  52. data/lib/chef-dk/skeletons/code_generator/templates/default/cookbook_file.erb +0 -0
  53. data/lib/chef-dk/skeletons/code_generator/templates/default/default_recipe.rb.erb +8 -0
  54. data/lib/chef-dk/skeletons/code_generator/templates/default/kitchen.yml.erb +16 -0
  55. data/lib/chef-dk/skeletons/code_generator/templates/default/metadata.rb.erb +8 -0
  56. data/lib/chef-dk/skeletons/code_generator/templates/default/provider.rb.erb +0 -0
  57. data/lib/chef-dk/skeletons/code_generator/templates/default/recipe.rb.erb +0 -0
  58. data/lib/chef-dk/skeletons/code_generator/templates/default/resource.rb.erb +0 -0
  59. data/lib/chef-dk/skeletons/code_generator/templates/default/template.erb +0 -0
  60. data/lib/chef-dk/version.rb +20 -0
  61. data/spec/shared/setup_git_cookbooks.rb +53 -0
  62. data/spec/spec_helper.rb +32 -0
  63. data/spec/test_helpers.rb +59 -0
  64. data/spec/unit/chef_runner_spec.rb +70 -0
  65. data/spec/unit/cli_spec.rb +151 -0
  66. data/spec/unit/command/base_spec.rb +88 -0
  67. data/spec/unit/command/exec_spec.rb +123 -0
  68. data/spec/unit/command/generate_spec.rb +102 -0
  69. data/spec/unit/command/generator_commands_spec.rb +504 -0
  70. data/spec/unit/command/shell_init_spec.rb +109 -0
  71. data/spec/unit/command/verify_spec.rb +311 -0
  72. data/spec/unit/commands_map_spec.rb +57 -0
  73. data/spec/unit/component_test_spec.rb +126 -0
  74. data/spec/unit/cookbook_metadata_spec.rb +62 -0
  75. data/spec/unit/cookbook_profiler/git_spec.rb +127 -0
  76. data/spec/unit/cookbook_profiler/identifiers_spec.rb +79 -0
  77. data/spec/unit/fixtures/chef-runner-cookbooks/test_cookbook/recipes/recipe_one.rb +9 -0
  78. data/spec/unit/fixtures/chef-runner-cookbooks/test_cookbook/recipes/recipe_two.rb +9 -0
  79. data/spec/unit/fixtures/command/cli_test_command.rb +26 -0
  80. data/spec/unit/fixtures/command/explicit_path_example.rb +7 -0
  81. data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/.kitchen.yml +16 -0
  82. data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/Berksfile +3 -0
  83. data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/README.md +4 -0
  84. data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/chefignore +96 -0
  85. data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/metadata.rb +8 -0
  86. data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/recipes/default.rb +8 -0
  87. data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/.kitchen.yml +16 -0
  88. data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/Berksfile +3 -0
  89. data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/README.md +4 -0
  90. data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/chefignore +96 -0
  91. data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/metadata.rb +8 -0
  92. data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/recipes/default.rb +8 -0
  93. data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/.kitchen.yml +16 -0
  94. data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/Berksfile +3 -0
  95. data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/README.md +4 -0
  96. data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/chefignore +96 -0
  97. data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/metadata.rb +8 -0
  98. data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/recipes/default.rb +8 -0
  99. data/spec/unit/fixtures/cookbooks_api/pruned_small_universe.json +1322 -0
  100. data/spec/unit/fixtures/cookbooks_api/small_universe.json +2987 -0
  101. data/spec/unit/fixtures/cookbooks_api/universe.json +1 -0
  102. data/spec/unit/fixtures/cookbooks_api/update_fixtures.rb +36 -0
  103. data/spec/unit/fixtures/dev_cookbooks/README.md +16 -0
  104. data/spec/unit/fixtures/dev_cookbooks/bar-cookbook.gitbundle +0 -0
  105. data/spec/unit/fixtures/eg_omnibus_dir/missing_apps/bin/.keep +0 -0
  106. data/spec/unit/fixtures/eg_omnibus_dir/missing_apps/embedded/.keep +0 -0
  107. data/spec/unit/fixtures/eg_omnibus_dir/missing_apps/embedded/bin/.keep +0 -0
  108. data/spec/unit/fixtures/eg_omnibus_dir/missing_component/bin/.keep +0 -0
  109. data/spec/unit/fixtures/eg_omnibus_dir/missing_component/embedded/apps/berkshelf/.keep +0 -0
  110. data/spec/unit/fixtures/eg_omnibus_dir/missing_component/embedded/apps/test-kitchen/.keep +0 -0
  111. data/spec/unit/fixtures/eg_omnibus_dir/missing_component/embedded/bin/.keep +0 -0
  112. data/spec/unit/fixtures/eg_omnibus_dir/valid/bin/.keep +0 -0
  113. data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/berkshelf/integration_test +2 -0
  114. data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/berkshelf/verify_me +5 -0
  115. data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/chef-dk/.keep +0 -0
  116. data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/chef/verify_me +3 -0
  117. data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/test-kitchen/verify_me +2 -0
  118. data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/bin/.keep +0 -0
  119. data/spec/unit/fixtures/example_app/Policyfile.rb +0 -0
  120. data/spec/unit/fixtures/example_cookbook/.gitignore +17 -0
  121. data/spec/unit/fixtures/example_cookbook/.kitchen.yml +16 -0
  122. data/spec/unit/fixtures/example_cookbook/Berksfile +3 -0
  123. data/spec/unit/fixtures/example_cookbook/README.md +4 -0
  124. data/spec/unit/fixtures/example_cookbook/chefignore +96 -0
  125. data/spec/unit/fixtures/example_cookbook/metadata.rb +8 -0
  126. data/spec/unit/fixtures/example_cookbook/recipes/default.rb +8 -0
  127. data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/.kitchen.yml +16 -0
  128. data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/Berksfile +3 -0
  129. data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/README.md +4 -0
  130. data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/chefignore +96 -0
  131. data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/metadata.rb +8 -0
  132. data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/recipes/default.rb +8 -0
  133. data/spec/unit/fixtures/local_path_cookbooks/metadata-missing/README.md +2 -0
  134. data/spec/unit/policyfile/chef_server_cookbook_source_spec.rb +34 -0
  135. data/spec/unit/policyfile/community_cookbook_source_spec.rb +51 -0
  136. data/spec/unit/policyfile/cookbook_spec_spec.rb +200 -0
  137. data/spec/unit/policyfile/null_cookbook_source_spec.rb +35 -0
  138. data/spec/unit/policyfile_builder_spec.rb +489 -0
  139. data/spec/unit/policyfile_demands_spec.rb +484 -0
  140. data/spec/unit/policyfile_evaluation_spec.rb +284 -0
  141. data/spec/unit/shell_out_spec.rb +34 -0
  142. metadata +422 -0
@@ -0,0 +1,109 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2014 Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'spec_helper'
19
+ require 'chef-dk/command/shell_init'
20
+
21
+ describe ChefDK::Command::ShellInit do
22
+
23
+ let(:stdout_io) { StringIO.new }
24
+ let(:stderr_io) { StringIO.new }
25
+
26
+ let(:command_instance) do
27
+ ChefDK::Command::ShellInit.new.tap do |c|
28
+ c.stub(:stdout).and_return(stdout_io)
29
+ c.stub(:stderr).and_return(stderr_io)
30
+ end
31
+ end
32
+
33
+ let(:argv) { ['bash'] }
34
+
35
+ let(:user_bin_dir) { File.expand_path(File.join(Gem.user_dir, 'bin')) }
36
+
37
+ let(:expected_path) { "#{omnibus_bin_dir}:#{user_bin_dir}:#{omnibus_embedded_bin_dir}:#{ENV['PATH']}" }
38
+
39
+ let(:expected_gem_root) { Gem.default_dir.to_s }
40
+
41
+ let(:expected_gem_home) { ENV['GEM_HOME'] }
42
+
43
+ let(:expected_gem_path) { Gem.path.join(':') }
44
+
45
+ let(:expected_environment_commands) do
46
+ <<-EOH
47
+ export PATH=#{expected_path}
48
+ export GEM_ROOT="#{expected_gem_root}"
49
+ export GEM_HOME=#{expected_gem_home}
50
+ export GEM_PATH=#{expected_gem_path}
51
+ EOH
52
+ end
53
+
54
+ context "with no explicit omnibus directory" do
55
+
56
+ let(:omnibus_bin_dir) { "/foo/bin" }
57
+ let(:omnibus_embedded_bin_dir) { "/foo/embedded/bin" }
58
+
59
+ before do
60
+ command_instance.stub(:omnibus_embedded_bin_dir).and_return(omnibus_embedded_bin_dir)
61
+ command_instance.stub(:omnibus_bin_dir).and_return(omnibus_bin_dir)
62
+ end
63
+
64
+ it "emits a script to add ChefDK's ruby to the shell environment" do
65
+ command_instance.run(argv)
66
+ expect(stdout_io.string).to eq(expected_environment_commands)
67
+ end
68
+
69
+ context "when no shell is specified" do
70
+
71
+ let(:argv) { [] }
72
+
73
+ it "exits with an error message" do
74
+ expect(command_instance.run(argv)).to eq(1)
75
+ expect(stderr_io.string).to include("Please specify what shell you are using")
76
+ end
77
+
78
+ end
79
+
80
+ context "when an unsupported shell is specified" do
81
+
82
+ let(:argv) { ['nosuchsh'] }
83
+
84
+ it "exits with an error message" do
85
+ expect(command_instance.run(argv)).to eq(1)
86
+ expect(stderr_io.string).to include("Shell `nosuchsh' is not currently supported")
87
+ expect(stderr_io.string).to include("Supported shells are: bash zsh sh")
88
+ end
89
+
90
+ end
91
+
92
+ end
93
+
94
+ context "with an explicit omnibus directory as an argument" do
95
+
96
+ let(:omnibus_root) { File.join(fixtures_path, "eg_omnibus_dir/valid/") }
97
+ let(:omnibus_bin_dir) { File.join(omnibus_root, "bin") }
98
+ let(:omnibus_embedded_bin_dir) { File.join(omnibus_root, "embedded/bin") }
99
+
100
+ let(:argv) { ["bash", "--omnibus-dir", omnibus_root] }
101
+
102
+ it "emits a script to add ChefDK's ruby to the shell environment" do
103
+ command_instance.run(argv)
104
+ expect(stdout_io.string).to eq(expected_environment_commands)
105
+ end
106
+ end
107
+
108
+ end
109
+
@@ -0,0 +1,311 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2014 Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'spec_helper'
19
+ require 'chef-dk/command/verify'
20
+
21
+ module Gem
22
+
23
+ # We stub Gem.ruby because `verify` uses it to locate the omnibus directory,
24
+ # but we also use it in some of the "test commands" in these tests.
25
+ class << self
26
+ alias :real_ruby :ruby
27
+ end
28
+ end
29
+
30
+ describe ChefDK::Command::Verify do
31
+ let(:command_instance) { ChefDK::Command::Verify.new() }
32
+
33
+ let(:command_options) { [] }
34
+
35
+ let(:components) { {} }
36
+
37
+ def run_command(expected_exit_code)
38
+ expect(command_instance.run(command_options)).to eq(expected_exit_code)
39
+ end
40
+
41
+ it "defines berks, tk, chef and chef-dk components by default" do
42
+ expect(command_instance.components).not_to be_empty
43
+ expect(command_instance.components.map(&:name)).to match_array(%w{berkshelf test-kitchen chef-client chef-dk})
44
+ end
45
+
46
+ it "has a usage banner" do
47
+ expect(command_instance.banner).to eq("Usage: chef verify [component, ...] [options]")
48
+ end
49
+
50
+ describe "when locating omnibus directory" do
51
+ it "should find omnibus app directory from ruby path" do
52
+ Gem.stub(:ruby).and_return(File.join(fixtures_path, "eg_omnibus_dir/valid/embedded/bin/ruby"))
53
+ expect(command_instance.omnibus_apps_dir).to include("eg_omnibus_dir/valid/embedded")
54
+ end
55
+
56
+ it "should raise OmnibusInstallNotFound if directory is not looking like omnibus" do
57
+ Gem.stub(:ruby).and_return(File.join(fixtures_path,".rbenv/versions/2.1.1/bin/ruby"))
58
+ expect{command_instance.omnibus_apps_dir}.to raise_error(ChefDK::OmnibusInstallNotFound)
59
+ end
60
+
61
+ it "raises OmnibusInstallNotFound if omnibus directory doesn't exist" do
62
+ Gem.stub(:ruby).and_return(File.join(fixtures_path,"eg_omnibus_dir/missing_apps/embedded/bin/ruby"))
63
+ expect{command_instance.omnibus_apps_dir}.to raise_error(ChefDK::OmnibusInstallNotFound)
64
+ end
65
+
66
+ it "raises MissingComponentError when a component doesn't exist" do
67
+ Gem.stub(:ruby).and_return(File.join(fixtures_path,"eg_omnibus_dir/missing_component/embedded/bin/ruby"))
68
+ expect{command_instance.validate_components!}.to raise_error(ChefDK::MissingComponentError)
69
+ end
70
+ end
71
+
72
+ describe "when running verify command" do
73
+ let(:stdout_io) { StringIO.new }
74
+ let(:ruby_path) { File.join(fixtures_path, "eg_omnibus_dir/valid/embedded/bin/ruby") }
75
+
76
+ def run_unit_test
77
+ # Set rubyopt to empty to prevent bundler from infecting the ruby
78
+ # subcommands (and loading a bunch of extra gems).
79
+ lambda { |_self| sh("#{Gem.real_ruby} verify_me", env: { "RUBYOPT" => ""}) }
80
+ end
81
+
82
+ def run_integration_test
83
+ lambda { |_self| sh("#{Gem.real_ruby} integration_test", env: { "RUBYOPT" => ""}) }
84
+ end
85
+
86
+ let(:all_tests_ok) do
87
+ ChefDK::ComponentTest.new("successful_comp").tap do |c|
88
+ c.base_dir = "berkshelf"
89
+ c.unit_test(&run_unit_test)
90
+ c.integration_test(&run_integration_test)
91
+ c.smoke_test { sh("true") }
92
+ end
93
+ end
94
+
95
+ let(:all_tests_ok_2) do
96
+ ChefDK::ComponentTest.new("successful_comp_2").tap do |c|
97
+ c.base_dir = "test-kitchen"
98
+ c.unit_test(&run_unit_test)
99
+ c.smoke_test { sh("true") }
100
+ end
101
+ end
102
+
103
+ let(:failing_unit_test) do
104
+ ChefDK::ComponentTest.new("failing_comp").tap do |c|
105
+ c.base_dir = "chef"
106
+ c.unit_test(&run_unit_test)
107
+ c.smoke_test { sh("true") }
108
+ end
109
+ end
110
+
111
+ let(:passing_smoke_test_only) do
112
+ component = failing_unit_test.dup
113
+ component.smoke_test { sh("true") }
114
+ component
115
+ end
116
+
117
+ let(:failing_smoke_test_only) do
118
+ component = all_tests_ok.dup
119
+ component.smoke_test { sh("false") }
120
+ component
121
+ end
122
+
123
+ let(:component_without_integration_tests) do
124
+ ChefDK::ComponentTest.new("successful_comp").tap do |c|
125
+ c.base_dir = "berkshelf"
126
+ c.unit_test { sh("./verify_me") }
127
+ c.smoke_test { sh("true") }
128
+ end
129
+ end
130
+
131
+ def stdout
132
+ stdout_io.string
133
+ end
134
+
135
+ before do
136
+ Gem.stub(:ruby).and_return(ruby_path)
137
+ command_instance.stub(:stdout).and_return(stdout_io)
138
+ command_instance.stub(:components).and_return(components)
139
+ end
140
+
141
+ context "when running smoke tests only" do
142
+ describe "with single command with success" do
143
+ let(:components) do
144
+ [ passing_smoke_test_only ]
145
+ end
146
+
147
+ before do
148
+ run_command(0)
149
+ end
150
+
151
+ it "should report the success of the command" do
152
+ expect(stdout).to include("Verification of component 'failing_comp' succeeded.")
153
+ end
154
+
155
+ end
156
+
157
+ describe "with single command with failure" do
158
+ let(:components) do
159
+ [ failing_smoke_test_only ]
160
+ end
161
+
162
+ before do
163
+ run_command(1)
164
+ end
165
+
166
+ it "should report the failure of the command" do
167
+ expect(stdout).to include("Verification of component 'successful_comp' failed.")
168
+ end
169
+
170
+ end
171
+ end
172
+
173
+ context "when running unit tests" do
174
+
175
+ let(:command_options) { %w{--unit --verbose} }
176
+
177
+ let(:components) do
178
+ [ all_tests_ok ]
179
+ end
180
+
181
+ describe "with single command with success" do
182
+ before do
183
+ run_command(0)
184
+ end
185
+
186
+ it "should have embedded/bin on the PATH" do
187
+ expect(stdout).to include(File.join(fixtures_path, "eg_omnibus_dir/valid/embedded/bin"))
188
+ end
189
+
190
+ it "should report the success of the command" do
191
+ expect(stdout).to include("Verification of component 'successful_comp' succeeded.")
192
+ end
193
+
194
+ it "reports the component test output" do
195
+ expect(stdout).to include("you are good to go...")
196
+ end
197
+
198
+ context "and --verbose is not enabled" do
199
+
200
+ let(:command_options) { %w{--unit} }
201
+
202
+ it "omits the component test output" do
203
+ expect(stdout).to_not include("you are good to go...")
204
+ end
205
+ end
206
+
207
+ context "and --integration flag is given" do
208
+
209
+ let(:command_options) { %w{--integration --verbose} }
210
+
211
+ it "should run the integration command also" do
212
+ expect(stdout).to include("integration tests OK")
213
+ end
214
+
215
+ context "and no integration test command is specifed for the component" do
216
+
217
+ let(:components) do
218
+ [ component_without_integration_tests ]
219
+ end
220
+
221
+ it "skips the integration test and succeeds" do
222
+ expect(stdout).to include("Verification of component 'successful_comp' succeeded.")
223
+ end
224
+
225
+ end
226
+
227
+ end
228
+
229
+ end
230
+
231
+ describe "with single command with failure" do
232
+ let(:components) do
233
+ [ failing_unit_test ]
234
+ end
235
+
236
+ before do
237
+ run_command(1)
238
+ end
239
+
240
+ it "should report the failure of the command" do
241
+ expect(stdout).to include("Verification of component 'failing_comp' failed.")
242
+ end
243
+
244
+ it "reports the component test output" do
245
+ expect(stdout).to include("i'm not feeling good today...")
246
+ end
247
+ end
248
+
249
+ describe "with multiple commands with success" do
250
+ let(:components) do
251
+ [ all_tests_ok, all_tests_ok_2 ]
252
+ end
253
+
254
+ before do
255
+ run_command(0)
256
+ end
257
+
258
+ it "should report the success of the command" do
259
+ expect(stdout).to include("Verification of component 'successful_comp' succeeded.")
260
+ expect(stdout).to include("Verification of component 'successful_comp_2' succeeded.")
261
+ end
262
+
263
+ it "reports the component test outputs" do
264
+ expect(stdout).to include("you are good to go...")
265
+ expect(stdout).to include("my friend everything is good...")
266
+ end
267
+
268
+ it "should report the output of the first verification first" do
269
+ index_first = stdout.index("you are good to go...")
270
+ index_second = stdout.index("my friend everything is good...")
271
+ expect(index_second > index_first).to be_true
272
+ end
273
+
274
+ context "and components are filtered by CLI args" do
275
+
276
+ let(:command_options) { [ "successful_comp_2" ] }
277
+
278
+ it "verifies only the desired component" do
279
+ expect(stdout).to_not include("Verification of component 'successful_comp_1' succeeded.")
280
+ expect(stdout).to include("Verification of component 'successful_comp_2' succeeded.")
281
+ end
282
+
283
+ end
284
+ end
285
+
286
+ describe "with multiple commands with failures" do
287
+ let(:components) do
288
+ [ all_tests_ok, all_tests_ok_2, failing_unit_test ]
289
+ end
290
+
291
+ before do
292
+ run_command(1)
293
+ end
294
+
295
+ it "should report the success and failure of the commands" do
296
+ expect(stdout).to include("Verification of component 'successful_comp' succeeded.")
297
+ expect(stdout).to include("Verification of component 'successful_comp_2' succeeded.")
298
+ expect(stdout).to include("Verification of component 'failing_comp' failed.")
299
+ end
300
+
301
+ it "reports the component test outputs" do
302
+ expect(stdout).to include("you are good to go...")
303
+ expect(stdout).to include("my friend everything is good...")
304
+ expect(stdout).to include("i'm not feeling good today...")
305
+ end
306
+ end
307
+
308
+ end
309
+ end
310
+
311
+ end
@@ -0,0 +1,57 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2014 Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'spec_helper'
19
+ require 'chef-dk/commands_map'
20
+ require 'stringio'
21
+
22
+ describe ChefDK::CommandsMap do
23
+
24
+ subject(:mapping) { ChefDK::CommandsMap.new }
25
+
26
+ before do
27
+ mapping.builtin("example", :Example)
28
+ mapping.builtin("hypenated-example", :HyphenatedExample)
29
+ mapping.builtin("explicit-path-example", :ExplicitPathExample, require_path: "unit/fixtures/command/explicit_path_example")
30
+ mapping.builtin("documented-example", :DocumentedExample, desc: "I have documentation")
31
+ end
32
+
33
+ it "defines a subcommand mapping" do
34
+ expect(mapping.have_command?("example")).to be_true
35
+ end
36
+
37
+ it "infers a non-hypenated command's require path" do
38
+ expect(mapping.spec_for("example").require_path).to eq("chef-dk/command/example")
39
+ end
40
+
41
+ it "infers a hyphenated command's require path" do
42
+ expect(mapping.spec_for("hypenated-example").require_path).to eq("chef-dk/command/hypenated_example")
43
+ end
44
+
45
+ it "lists the available commands" do
46
+ expect(mapping.command_names).to match_array(%w[example hypenated-example explicit-path-example documented-example])
47
+ end
48
+
49
+ it "keeps the docstring of a command" do
50
+ expect(mapping.spec_for("documented-example").description).to eq("I have documentation")
51
+ end
52
+
53
+ it "creates an instance of a command" do
54
+ expect(mapping.instantiate("explicit-path-example")).to be_an_instance_of(ChefDK::Command::ExplicitPathExample)
55
+ end
56
+
57
+ end