microwave 1.0.4 → 11.400.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CONTRIBUTING.md +155 -0
- data/README.md +89 -0
- data/Rakefile +2 -2
- data/bin/chef-apply +25 -0
- data/bin/chef-shell +34 -0
- data/bin/chef-solo +0 -2
- data/bin/shef +6 -5
- data/lib/chef.rb +2 -4
- data/spec/data/big_json.json +2 -1
- data/spec/data/big_json_plus_one.json +2 -1
- data/spec/data/cookbooks/chefignore +2 -0
- data/spec/data/cookbooks/openldap/attributes/default.rb +10 -9
- data/spec/data/cookbooks/openldap/attributes/smokey.rb +1 -1
- data/spec/data/git_bundles/sinatra-test-app-with-callback-files.gitbundle +0 -0
- data/spec/data/git_bundles/sinatra-test-app-with-symlinks.gitbundle +0 -0
- data/spec/data/git_bundles/sinatra-test-app.gitbundle +0 -0
- data/spec/data/lwrp/providers/inline_compiler.rb +26 -0
- data/spec/data/nodes/default.rb +3 -3
- data/spec/data/nodes/test.example.com.rb +3 -3
- data/spec/data/nodes/test.rb +3 -3
- data/spec/data/partial_one.erb +1 -0
- data/spec/data/run_context/cookbooks/circular-dep1/attributes/default.rb +4 -0
- data/spec/data/run_context/cookbooks/circular-dep1/definitions/circular_dep1_res.rb +1 -0
- data/spec/data/run_context/cookbooks/circular-dep1/libraries/lib.rb +2 -0
- data/spec/data/run_context/cookbooks/circular-dep1/metadata.rb +2 -0
- data/spec/data/run_context/cookbooks/circular-dep1/providers/provider.rb +1 -0
- data/spec/data/run_context/cookbooks/circular-dep1/recipes/default.rb +0 -0
- data/spec/data/run_context/cookbooks/circular-dep1/resources/resource.rb +1 -0
- data/spec/data/run_context/cookbooks/circular-dep2/attributes/default.rb +3 -0
- data/spec/data/run_context/cookbooks/circular-dep2/definitions/circular_dep2_res.rb +1 -0
- data/spec/data/run_context/cookbooks/circular-dep2/libraries/lib.rb +2 -0
- data/spec/data/run_context/cookbooks/circular-dep2/metadata.rb +2 -0
- data/spec/data/run_context/cookbooks/circular-dep2/providers/provider.rb +1 -0
- data/spec/data/run_context/cookbooks/circular-dep2/recipes/default.rb +0 -0
- data/spec/data/run_context/cookbooks/circular-dep2/resources/resource.rb +1 -0
- data/spec/data/run_context/cookbooks/dependency1/attributes/aa_first.rb +2 -0
- data/spec/data/run_context/cookbooks/dependency1/attributes/default.rb +2 -0
- data/spec/data/run_context/cookbooks/dependency1/attributes/zz_last.rb +3 -0
- data/spec/data/run_context/cookbooks/dependency1/definitions/dependency1_res.rb +1 -0
- data/spec/data/run_context/cookbooks/dependency1/libraries/lib.rb +2 -0
- data/spec/data/run_context/cookbooks/dependency1/providers/provider.rb +1 -0
- data/spec/data/run_context/cookbooks/dependency1/recipes/default.rb +0 -0
- data/spec/data/run_context/cookbooks/dependency1/resources/resource.rb +1 -0
- data/spec/data/run_context/cookbooks/dependency2/attributes/default.rb +3 -0
- data/spec/data/run_context/cookbooks/dependency2/definitions/dependency2_res.rb +1 -0
- data/spec/data/run_context/cookbooks/dependency2/libraries/lib.rb +2 -0
- data/spec/data/run_context/cookbooks/dependency2/providers/provider.rb +1 -0
- data/spec/data/run_context/cookbooks/dependency2/recipes/default.rb +0 -0
- data/spec/data/run_context/cookbooks/dependency2/resources/resource.rb +1 -0
- data/spec/data/run_context/cookbooks/no-default-attr/attributes/server.rb +3 -0
- data/spec/data/run_context/cookbooks/no-default-attr/definitions/no_default-attr_res.rb +1 -0
- data/spec/data/run_context/cookbooks/no-default-attr/providers/provider.rb +1 -0
- data/spec/data/run_context/cookbooks/no-default-attr/recipes/default.rb +0 -0
- data/spec/data/run_context/cookbooks/no-default-attr/resources/resource.rb +1 -0
- data/spec/data/run_context/cookbooks/test-with-circular-deps/attributes/default.rb +3 -0
- data/spec/data/run_context/cookbooks/test-with-circular-deps/definitions/test_with-circular-deps_res.rb +1 -0
- data/spec/data/run_context/cookbooks/test-with-circular-deps/libraries/lib.rb +2 -0
- data/spec/data/run_context/cookbooks/test-with-circular-deps/metadata.rb +2 -0
- data/spec/data/run_context/cookbooks/test-with-circular-deps/providers/provider.rb +1 -0
- data/spec/data/run_context/cookbooks/test-with-circular-deps/recipes/default.rb +0 -0
- data/spec/data/run_context/cookbooks/test-with-circular-deps/resources/resource.rb +1 -0
- data/spec/data/run_context/cookbooks/test-with-deps/attributes/default.rb +3 -0
- data/spec/data/run_context/cookbooks/test-with-deps/definitions/test_with-deps_res.rb +1 -0
- data/spec/data/run_context/cookbooks/test-with-deps/libraries/lib.rb +1 -0
- data/spec/data/run_context/cookbooks/test-with-deps/metadata.rb +3 -0
- data/spec/data/run_context/cookbooks/test-with-deps/providers/provider.rb +1 -0
- data/spec/data/run_context/cookbooks/test-with-deps/recipes/default.rb +0 -0
- data/spec/data/run_context/cookbooks/test-with-deps/recipes/server.rb +0 -0
- data/spec/data/run_context/cookbooks/test-with-deps/resources/resource.rb +1 -0
- data/spec/data/run_context/cookbooks/test/attributes/default.rb +0 -0
- data/spec/data/run_context/cookbooks/test/attributes/george.rb +1 -1
- data/spec/data/run_context/cookbooks/test/definitions/test_res.rb +1 -0
- data/spec/data/run_context/cookbooks/test/providers/provider.rb +1 -0
- data/spec/data/run_context/cookbooks/test/resources/resource.rb +1 -0
- data/spec/data/shef-config.rb +10 -0
- data/spec/functional/dsl/registry_helper_spec.rb +63 -0
- data/spec/functional/knife/cookbook_delete_spec.rb +0 -2
- data/spec/functional/knife/exec_spec.rb +4 -6
- data/spec/functional/knife/smoke_test.rb +34 -0
- data/spec/functional/knife/ssh_spec.rb +64 -3
- data/spec/functional/resource/cookbook_file_spec.rb +33 -2
- data/spec/functional/resource/deploy_revision_spec.rb +515 -0
- data/spec/functional/resource/directory_spec.rb +4 -0
- data/spec/functional/resource/file_spec.rb +56 -22
- data/spec/functional/resource/link_spec.rb +12 -10
- data/spec/functional/resource/registry_spec.rb +572 -0
- data/spec/functional/resource/remote_directory_spec.rb +142 -36
- data/spec/functional/resource/remote_file_spec.rb +28 -3
- data/spec/functional/resource/template_spec.rb +23 -2
- data/spec/functional/run_lock_spec.rb +238 -0
- data/spec/functional/shell_spec.rb +101 -0
- data/spec/functional/tiny_server_spec.rb +5 -4
- data/spec/functional/win32/registry_helper_spec.rb +632 -0
- data/spec/functional/win32/security_spec.rb +37 -0
- data/spec/spec_helper.rb +15 -3
- data/spec/stress/win32/security_spec.rb +5 -5
- data/spec/support/chef_helpers.rb +14 -3
- data/spec/support/lib/chef/resource/cat.rb +3 -5
- data/spec/support/lib/chef/resource/one_two_three_four.rb +8 -10
- data/spec/support/lib/chef/resource/zen_master.rb +8 -10
- data/spec/support/matchers/leak.rb +1 -1
- data/spec/support/platform_helpers.rb +18 -0
- data/spec/support/shared/functional/directory_resource.rb +85 -23
- data/spec/support/shared/functional/file_resource.rb +198 -53
- data/spec/support/shared/functional/securable_resource.rb +140 -105
- data/spec/support/shared/functional/securable_resource_with_reporting.rb +375 -0
- data/spec/support/shared/unit/file_system_support.rb +110 -0
- data/spec/support/shared/unit/platform_introspector.rb +162 -0
- data/spec/tiny_server.rb +29 -10
- data/spec/unit/api_client/registration_spec.rb +172 -0
- data/spec/unit/api_client_spec.rb +156 -103
- data/spec/unit/application/apply.rb +84 -0
- data/spec/unit/application/knife_spec.rb +5 -0
- data/spec/unit/application_spec.rb +57 -2
- data/spec/unit/chef_fs/diff_spec.rb +329 -0
- data/spec/unit/chef_fs/file_pattern_spec.rb +526 -0
- data/spec/unit/chef_fs/file_system/chef_server_root_dir_spec.rb +237 -0
- data/spec/unit/chef_fs/file_system/cookbooks_dir_spec.rb +568 -0
- data/spec/unit/chef_fs/file_system/data_bags_dir_spec.rb +220 -0
- data/spec/unit/chef_fs/file_system_spec.rb +136 -0
- data/spec/unit/client_spec.rb +188 -16
- data/spec/unit/config_spec.rb +54 -4
- data/spec/unit/cookbook/chefignore_spec.rb +2 -1
- data/spec/unit/cookbook/syntax_check_spec.rb +48 -109
- data/spec/unit/cookbook_loader_spec.rb +153 -91
- data/spec/unit/cookbook_manifest_spec.rb +81 -81
- data/spec/unit/cookbook_spec.rb +3 -20
- data/spec/unit/cookbook_version_spec.rb +23 -122
- data/spec/unit/digester_spec.rb +50 -0
- data/spec/unit/dsl/data_query_spec.rb +66 -0
- data/spec/unit/dsl/platform_introspection_spec.rb +130 -0
- data/spec/unit/dsl/regsitry_helper_spec.rb +55 -0
- data/spec/unit/encrypted_data_bag_item_spec.rb +126 -10
- data/spec/unit/environment_spec.rb +0 -130
- data/spec/unit/exceptions_spec.rb +2 -3
- data/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb +23 -3
- data/spec/unit/json_compat_spec.rb +69 -0
- data/spec/unit/knife/bootstrap_spec.rb +81 -28
- data/spec/unit/knife/client_reregister_spec.rb +23 -22
- data/spec/unit/knife/configure_spec.rb +29 -26
- data/spec/unit/knife/cookbook_metadata_spec.rb +11 -4
- data/spec/unit/knife/cookbook_site_install_spec.rb +12 -2
- data/spec/unit/knife/cookbook_test_spec.rb +1 -0
- data/spec/unit/knife/cookbook_upload_spec.rb +41 -2
- data/spec/unit/knife/core/bootstrap_context_spec.rb +8 -1
- data/spec/unit/knife/core/ui_spec.rb +156 -7
- data/spec/unit/knife/data_bag_create_spec.rb +14 -0
- data/spec/unit/knife/data_bag_edit_spec.rb +14 -4
- data/spec/unit/knife/data_bag_from_file_spec.rb +17 -5
- data/spec/unit/knife/data_bag_show_spec.rb +11 -4
- data/spec/unit/knife/index_rebuild_spec.rb +96 -33
- data/spec/unit/knife/knife_help.rb +7 -7
- data/spec/unit/knife/node_run_list_remove_spec.rb +2 -1
- data/spec/unit/knife/ssh_spec.rb +121 -15
- data/spec/unit/knife/status_spec.rb +2 -2
- data/spec/unit/knife/user_create_spec.rb +86 -0
- data/spec/unit/knife/user_delete_spec.rb +39 -0
- data/spec/unit/knife/user_edit_spec.rb +42 -0
- data/spec/unit/knife/user_list_spec.rb +32 -0
- data/spec/unit/knife/user_reregister_spec.rb +53 -0
- data/spec/unit/knife/user_show_spec.rb +41 -0
- data/spec/unit/knife_spec.rb +53 -0
- data/spec/unit/lwrp_spec.rb +59 -17
- data/spec/unit/mixin/checksum_spec.rb +2 -2
- data/spec/unit/mixin/deep_merge_spec.rb +56 -491
- data/spec/unit/mixin/deprecation_spec.rb +23 -0
- data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +6 -1
- data/spec/unit/mixin/params_validate_spec.rb +4 -2
- data/spec/unit/mixin/securable_spec.rb +5 -3
- data/spec/unit/mixin/template_spec.rb +119 -0
- data/spec/unit/node/attribute_spec.rb +272 -137
- data/spec/unit/node/immutable_collections_spec.rb +139 -0
- data/spec/unit/node_spec.rb +411 -339
- data/spec/unit/platform_spec.rb +8 -8
- data/spec/unit/provider/breakpoint_spec.rb +8 -8
- data/spec/unit/provider/cookbook_file_spec.rb +4 -8
- data/spec/unit/provider/deploy/revision_spec.rb +2 -8
- data/spec/unit/provider/deploy_spec.rb +6 -40
- data/spec/unit/provider/directory_spec.rb +103 -68
- data/spec/unit/provider/erl_call_spec.rb +0 -2
- data/spec/unit/provider/file_spec.rb +69 -59
- data/spec/unit/provider/git_spec.rb +0 -10
- data/spec/unit/provider/group/groupadd_spec.rb +1 -1
- data/spec/unit/provider/group/usermod_spec.rb +2 -2
- data/spec/unit/provider/http_request_spec.rb +28 -69
- data/spec/unit/provider/ifconfig_spec.rb +2 -2
- data/spec/unit/provider/link_spec.rb +1 -1
- data/spec/unit/provider/ohai_spec.rb +4 -4
- data/spec/unit/provider/package/apt_spec.rb +0 -1
- data/spec/unit/provider/package/ips_spec.rb +0 -1
- data/spec/unit/provider/package/rubygems_spec.rb +0 -18
- data/spec/unit/provider/package/yum_spec.rb +79 -15
- data/spec/unit/provider/package_spec.rb +7 -5
- data/spec/unit/provider/registry_key_spec.rb +269 -0
- data/spec/unit/provider/remote_directory_spec.rb +24 -7
- data/spec/unit/provider/remote_file_spec.rb +36 -0
- data/spec/unit/provider/route_spec.rb +3 -6
- data/spec/unit/provider/ruby_block_spec.rb +8 -0
- data/spec/unit/provider/service/arch_service_spec.rb +4 -4
- data/spec/unit/provider/service/debian_service_spec.rb +1 -1
- data/spec/unit/provider/service/freebsd_service_spec.rb +4 -4
- data/spec/unit/provider/service/init_service_spec.rb +26 -3
- data/spec/unit/provider/service/insserv_service_spec.rb +1 -1
- data/spec/unit/provider/service/invokercd_service_spec.rb +3 -3
- data/spec/unit/provider/service/redhat_spec.rb +1 -1
- data/spec/unit/provider/service/simple_service_spec.rb +3 -3
- data/spec/unit/provider/service/upstart_service_spec.rb +7 -7
- data/spec/unit/provider/service_spec.rb +2 -2
- data/spec/unit/provider/subversion_spec.rb +1 -1
- data/spec/unit/provider/template_spec.rb +35 -11
- data/spec/unit/provider/user/dscl_spec.rb +57 -31
- data/spec/unit/provider/user_spec.rb +7 -16
- data/spec/unit/provider_spec.rb +4 -3
- data/spec/unit/recipe_spec.rb +10 -8
- data/spec/unit/registry_helper_spec.rb +376 -0
- data/spec/unit/resource/log_spec.rb +9 -0
- data/spec/unit/resource/registry_key_spec.rb +171 -0
- data/spec/unit/resource/remote_file_spec.rb +21 -23
- data/spec/unit/resource/ruby_block_spec.rb +7 -3
- data/spec/unit/resource/service_spec.rb +11 -0
- data/spec/unit/resource_spec.rb +27 -4
- data/spec/unit/rest/auth_credentials_spec.rb +2 -14
- data/spec/unit/rest_spec.rb +122 -187
- data/spec/unit/run_context/cookbook_compiler_spec.rb +181 -0
- data/spec/unit/run_context_spec.rb +18 -4
- data/spec/unit/run_list_spec.rb +0 -209
- data/spec/unit/run_lock_spec.rb +37 -0
- data/spec/unit/runner_spec.rb +101 -2
- data/spec/unit/scan_access_control_spec.rb +4 -4
- data/spec/unit/{shef → shell}/model_wrapper_spec.rb +5 -5
- data/spec/unit/{shef/shef_ext_spec.rb → shell/shell_ext_spec.rb} +21 -21
- data/spec/unit/{shef/shef_session_spec.rb → shell/shell_session_spec.rb} +12 -12
- data/spec/unit/shell_out_spec.rb +18 -0
- data/spec/unit/{shef_spec.rb → shell_spec.rb} +20 -20
- data/spec/unit/user_spec.rb +255 -0
- metadata +162 -157
- data/README.rdoc +0 -177
- data/spec/unit/certificate_spec.rb +0 -76
- data/spec/unit/checksum_cache_spec.rb +0 -209
- data/spec/unit/checksum_spec.rb +0 -94
- data/spec/unit/couchdb_spec.rb +0 -274
- data/spec/unit/index_queue_spec.rb +0 -391
- data/spec/unit/json_compat_spect.rb +0 -53
- data/spec/unit/mixin/language_spec.rb +0 -305
- data/spec/unit/openid_registration_spec.rb +0 -153
- data/spec/unit/solr_query/query_transform_spec.rb +0 -454
- data/spec/unit/solr_query/solr_http_request_spec.rb +0 -244
- data/spec/unit/solr_query_spec.rb +0 -203
- data/spec/unit/webui_user_spec.rb +0 -238
data/spec/unit/config_spec.rb
CHANGED
@@ -62,6 +62,58 @@ describe Chef::Config do
|
|
62
62
|
it_behaves_like "server URL"
|
63
63
|
end
|
64
64
|
|
65
|
+
describe "when configuring formatters" do
|
66
|
+
# if TTY and not(force-logger)
|
67
|
+
# formatter = configured formatter or default formatter
|
68
|
+
# formatter goes to STDOUT/ERR
|
69
|
+
# if log file is writeable
|
70
|
+
# log level is configured level or info
|
71
|
+
# log location is file
|
72
|
+
# else
|
73
|
+
# log level is warn
|
74
|
+
# log location is STDERR
|
75
|
+
# end
|
76
|
+
# elsif not(TTY) and force formatter
|
77
|
+
# formatter = configured formatter or default formatter
|
78
|
+
# if log_location specified
|
79
|
+
# formatter goes to log_location
|
80
|
+
# else
|
81
|
+
# formatter goes to STDOUT/ERR
|
82
|
+
# end
|
83
|
+
# else
|
84
|
+
# formatter = "null"
|
85
|
+
# log_location = configured-value or defualt
|
86
|
+
# log_level = info or defualt
|
87
|
+
# end
|
88
|
+
#
|
89
|
+
before do
|
90
|
+
@config_class = Class.new(Chef::Config)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "has an empty list of formatters by default" do
|
94
|
+
@config_class.formatters.should == []
|
95
|
+
end
|
96
|
+
|
97
|
+
it "configures a formatter with a short name" do
|
98
|
+
@config_class.add_formatter(:doc)
|
99
|
+
@config_class.formatters.should == [[:doc, nil]]
|
100
|
+
end
|
101
|
+
|
102
|
+
it "configures a formatter with a file output" do
|
103
|
+
@config_class.add_formatter(:doc, "/var/log/formatter.log")
|
104
|
+
@config_class.formatters.should == [[:doc, "/var/log/formatter.log"]]
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
context "when the url is a frozen string" do
|
110
|
+
before do
|
111
|
+
Chef::Config.chef_server_url = " https://junglist.gen.nz".freeze
|
112
|
+
end
|
113
|
+
|
114
|
+
it_behaves_like "server URL"
|
115
|
+
end
|
116
|
+
|
65
117
|
describe "class method: manage_secret_key" do
|
66
118
|
before do
|
67
119
|
Chef::FileCache.stub!(:load).and_return(true)
|
@@ -129,16 +181,14 @@ describe Chef::Config do
|
|
129
181
|
it "should return given path on non-windows systems" do
|
130
182
|
platform_mock :unix do
|
131
183
|
path = "/etc/chef/cookbooks"
|
132
|
-
Chef::Config.platform_specific_path(path).should == "#{
|
184
|
+
Chef::Config.platform_specific_path(path).should == "#{Chef::Config[:alt_root]}/etc/chef/cookbooks"
|
133
185
|
end
|
134
186
|
end
|
135
187
|
|
136
188
|
it "should return a windows path on windows systems" do
|
137
189
|
platform_mock :windows do
|
138
190
|
path = "/etc/chef/cookbooks"
|
139
|
-
|
140
|
-
expected_microwave_root = save_microwave_root.gsub(File::SEPARATOR, (File::ALT_SEPARATOR || '\\'))
|
141
|
-
ENV.stub!(:[]).with('MICROWAVE_ROOT').and_return(save_microwave_root)
|
191
|
+
expected_microwave_root = Chef::Config[:alt_root].gsub(File::SEPARATOR, (File::ALT_SEPARATOR || '\\'))
|
142
192
|
ENV.stub!(:[]).with('SYSTEMDRIVE').and_return('C:')
|
143
193
|
# match on a regex that looks for the base path with an optional
|
144
194
|
# system drive at the beginning (c:)
|
@@ -23,7 +23,7 @@ describe Chef::Cookbook::Chefignore do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it "loads the globs in the chefignore file" do
|
26
|
-
@chefignore.ignores.should =~ %w[recipes/ignoreme.rb]
|
26
|
+
@chefignore.ignores.should =~ %w[recipes/ignoreme.rb ignored]
|
27
27
|
end
|
28
28
|
|
29
29
|
it "removes items from an array that match the ignores" do
|
@@ -32,6 +32,7 @@ describe Chef::Cookbook::Chefignore do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it "determines if a file is ignored" do
|
35
|
+
@chefignore.ignored?('ignored').should be_true
|
35
36
|
@chefignore.ignored?('recipes/ignoreme.rb').should be_true
|
36
37
|
@chefignore.ignored?('recipes/dontignoreme.rb').should be_false
|
37
38
|
end
|
@@ -16,175 +16,114 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
###################################################
|
20
|
-
# OLD:
|
21
|
-
###################################################
|
22
|
-
# def test_ruby(cookbook_dir)
|
23
|
-
# cache = Chef::ChecksumCache.instance
|
24
|
-
# Dir[File.join(cookbook_dir, '**', '*.rb')].each do |ruby_file|
|
25
|
-
# key = cache.generate_key(ruby_file, "chef-test")
|
26
|
-
# fstat = File.stat(ruby_file)
|
27
|
-
#
|
28
|
-
# if cache.lookup_checksum(key, fstat)
|
29
|
-
# Chef::Log.info("No change in checksum of #{ruby_file}")
|
30
|
-
# else
|
31
|
-
# Chef::Log.info("Testing #{ruby_file} for syntax errors...")
|
32
|
-
# Chef::Mixin::Command.run_command(:command => "ruby -c #{ruby_file}", :output_on_failure => true)
|
33
|
-
# cache.generate_checksum(key, ruby_file, fstat)
|
34
|
-
# end
|
35
|
-
# end
|
36
|
-
# end
|
37
|
-
#
|
38
|
-
#def test_templates(cookbook_dir)
|
39
|
-
# cache = Chef::ChecksumCache.instance
|
40
|
-
# Dir[File.join(cookbook_dir, '**', '*.erb')].each do |erb_file|
|
41
|
-
# key = cache.generate_key(erb_file, "chef-test")
|
42
|
-
# fstat = File.stat(erb_file)
|
43
|
-
#
|
44
|
-
# if cache.lookup_checksum(key, fstat)
|
45
|
-
# Chef::Log.info("No change in checksum of #{erb_file}")
|
46
|
-
# else
|
47
|
-
# Chef::Log.info("Testing template #{erb_file} for syntax errors...")
|
48
|
-
# Chef::Mixin::Command.run_command(:command => "sh -c 'erubis -x #{erb_file} | ruby -c'", :output_on_failure => true)
|
49
|
-
# cache.generate_checksum(key, erb_file, fstat)
|
50
|
-
# end
|
51
|
-
# end
|
52
|
-
#end
|
53
|
-
#
|
54
|
-
|
55
|
-
###################################################
|
56
|
-
# NEW:
|
57
|
-
###################################################
|
58
|
-
# def test_template_file(cookbook_dir, erb_file)
|
59
|
-
# Chef::Log.debug("Testing template #{erb_file} for syntax errors...")
|
60
|
-
# result = shell_out("sh -c 'erubis -x #{erb_file} | ruby -c'")
|
61
|
-
# result.error!
|
62
|
-
# rescue Mixlib::ShellOut::ShellCommandFailed
|
63
|
-
# file_relative_path = erb_file[/^#{Regexp.escape(cookbook_dir+File::Separator)}(.*)/, 1]
|
64
|
-
# Chef::Log.fatal("Erb template #{file_relative_path} has a syntax error:")
|
65
|
-
# result.stderr.each_line { |l| Chef::Log.fatal(l.chomp) }
|
66
|
-
# exit(1)
|
67
|
-
# end
|
68
|
-
#
|
69
|
-
# def test_ruby_file(cookbook_dir, ruby_file)
|
70
|
-
# Chef::Log.debug("Testing #{ruby_file} for syntax errors...")
|
71
|
-
# result = shell_out("ruby -c #{ruby_file}")
|
72
|
-
# result.error!
|
73
|
-
# rescue Mixlib::ShellOut::ShellCommandFailed
|
74
|
-
# file_relative_path = ruby_file[/^#{Regexp.escape(cookbook_dir+File::Separator)}(.*)/, 1]
|
75
|
-
# Chef::Log.fatal("Cookbook file #{file_relative_path} has a syntax error:")
|
76
|
-
# result.stderr.each_line { |l| Chef::Log.fatal(l.chomp) }
|
77
|
-
# exit(1)
|
78
|
-
# end
|
79
|
-
#
|
80
|
-
|
81
19
|
require 'spec_helper'
|
82
20
|
require "chef/cookbook/syntax_check"
|
83
21
|
|
84
22
|
describe Chef::Cookbook::SyntaxCheck do
|
23
|
+
|
24
|
+
let(:cookbook_path) { File.join(CHEF_SPEC_DATA, 'cookbooks', 'openldap') }
|
25
|
+
let(:syntax_check) { Chef::Cookbook::SyntaxCheck.new(cookbook_path) }
|
26
|
+
|
85
27
|
before do
|
86
28
|
Chef::Log.logger = Logger.new(StringIO.new)
|
29
|
+
Chef::Log.level = :warn # suppress "Syntax OK" messages
|
87
30
|
|
88
|
-
@cookbook_path = File.join(CHEF_SPEC_DATA, 'cookbooks', 'openldap')
|
89
31
|
|
90
|
-
@attr_files = %w{default.rb smokey.rb}.map { |f| File.join(
|
91
|
-
@defn_files = %w{client.rb server.rb}.map { |f| File.join(
|
92
|
-
@recipes = %w{default.rb gigantor.rb one.rb}.map { |f| File.join(
|
32
|
+
@attr_files = %w{default.rb smokey.rb}.map { |f| File.join(cookbook_path, 'attributes', f) }
|
33
|
+
@defn_files = %w{client.rb server.rb}.map { |f| File.join(cookbook_path, 'definitions', f)}
|
34
|
+
@recipes = %w{default.rb gigantor.rb one.rb}.map { |f| File.join(cookbook_path, 'recipes', f) }
|
93
35
|
@ruby_files = @attr_files + @defn_files + @recipes
|
94
36
|
|
95
|
-
@template_files = %w{openldap_stuff.conf.erb openldap_variable_stuff.conf.erb test.erb}.map { |f| File.join(
|
37
|
+
@template_files = %w{openldap_stuff.conf.erb openldap_variable_stuff.conf.erb test.erb}.map { |f| File.join(cookbook_path, 'templates', 'default', f)}
|
96
38
|
|
97
|
-
@syntax_check = Chef::Cookbook::SyntaxCheck.new(@cookbook_path)
|
98
39
|
end
|
99
40
|
|
100
41
|
it "creates a syntax checker given the cookbook name when Chef::Config.cookbook_path is set" do
|
101
|
-
Chef::Config[:cookbook_path] = File.dirname(
|
42
|
+
Chef::Config[:cookbook_path] = File.dirname(cookbook_path)
|
102
43
|
syntax_check = Chef::Cookbook::SyntaxCheck.for_cookbook(:openldap)
|
103
|
-
syntax_check.cookbook_path.should ==
|
44
|
+
syntax_check.cookbook_path.should == cookbook_path
|
104
45
|
end
|
105
46
|
|
106
47
|
describe "when first created" do
|
107
48
|
it "has the path to the cookbook to syntax check" do
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
it "has access to the checksum cache" do
|
112
|
-
@syntax_check.cache.should equal(Chef::ChecksumCache.instance)
|
49
|
+
syntax_check.cookbook_path.should == cookbook_path
|
113
50
|
end
|
114
51
|
|
115
52
|
it "lists the ruby files in the cookbook" do
|
116
|
-
|
53
|
+
syntax_check.ruby_files.sort.should == @ruby_files.sort
|
117
54
|
end
|
118
55
|
|
119
56
|
it "lists the erb templates in the cookbook" do
|
120
|
-
|
57
|
+
syntax_check.template_files.sort.should == @template_files.sort
|
121
58
|
end
|
122
59
|
|
123
60
|
end
|
124
61
|
|
125
62
|
describe "when validating cookbooks" do
|
63
|
+
let(:cache_path) { Dir.mktmpdir }
|
64
|
+
|
126
65
|
before do
|
127
|
-
Chef::Config[:
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
66
|
+
Chef::Config[:syntax_check_cache_path] = cache_path
|
67
|
+
end
|
68
|
+
|
69
|
+
after do
|
70
|
+
FileUtils.rm_rf(cache_path) if File.exist?(cache_path)
|
71
|
+
Chef::Config[:syntax_check_cache_path] = nil
|
133
72
|
end
|
134
73
|
|
135
74
|
describe "and the files have not been syntax checked previously" do
|
136
75
|
it "shows that all ruby files require a syntax check" do
|
137
|
-
|
76
|
+
syntax_check.untested_ruby_files.sort.should == @ruby_files.sort
|
138
77
|
end
|
139
78
|
|
140
79
|
it "shows that all template files require a syntax check" do
|
141
|
-
|
80
|
+
syntax_check.untested_template_files.sort.should == @template_files.sort
|
142
81
|
end
|
143
82
|
|
144
83
|
it "removes a ruby file from the list of untested files after it is marked as validated" do
|
145
|
-
recipe = File.join(
|
146
|
-
|
147
|
-
|
84
|
+
recipe = File.join(cookbook_path, 'recipes', 'default.rb')
|
85
|
+
syntax_check.validated(recipe)
|
86
|
+
syntax_check.untested_ruby_files.should_not include(recipe)
|
148
87
|
end
|
149
88
|
|
150
89
|
it "removes a template file from the list of untested files after it is marked as validated" do
|
151
|
-
template = File.join(
|
152
|
-
|
153
|
-
|
90
|
+
template = File.join(cookbook_path, 'templates', 'default', 'test.erb')
|
91
|
+
syntax_check.validated(template)
|
92
|
+
syntax_check.untested_template_files.should_not include(template)
|
154
93
|
end
|
155
94
|
|
156
95
|
it "validates all ruby files" do
|
157
|
-
|
158
|
-
|
96
|
+
syntax_check.validate_ruby_files.should be_true
|
97
|
+
syntax_check.untested_ruby_files.should be_empty
|
159
98
|
end
|
160
99
|
|
161
100
|
it "validates all templates" do
|
162
|
-
|
163
|
-
|
101
|
+
syntax_check.validate_templates.should be_true
|
102
|
+
syntax_check.untested_template_files.should be_empty
|
164
103
|
end
|
165
104
|
|
166
105
|
describe "and a file has a syntax error" do
|
167
106
|
before do
|
168
|
-
|
169
|
-
|
107
|
+
cookbook_path = File.join(CHEF_SPEC_DATA, 'cookbooks', 'borken')
|
108
|
+
syntax_check.cookbook_path.replace(cookbook_path)
|
170
109
|
end
|
171
110
|
|
172
111
|
it "it indicates that a ruby file has a syntax error" do
|
173
|
-
|
112
|
+
syntax_check.validate_ruby_files.should be_false
|
174
113
|
end
|
175
114
|
|
176
115
|
it "does not remove the invalid file from the list of untested files" do
|
177
|
-
|
178
|
-
lambda {
|
116
|
+
syntax_check.untested_ruby_files.should include(File.join(cookbook_path, 'recipes', 'default.rb'))
|
117
|
+
lambda { syntax_check.validate_ruby_files }.should_not change(syntax_check, :untested_ruby_files)
|
179
118
|
end
|
180
119
|
|
181
120
|
it "indicates that a template file has a syntax error" do
|
182
|
-
|
121
|
+
syntax_check.validate_templates.should be_false
|
183
122
|
end
|
184
123
|
|
185
124
|
it "does not remove the invalid template from the list of untested templates" do
|
186
|
-
|
187
|
-
lambda {
|
125
|
+
syntax_check.untested_template_files.should include(File.join(cookbook_path, 'templates', 'default', 'borken.erb'))
|
126
|
+
lambda {syntax_check.validate_templates}.should_not change(syntax_check, :untested_template_files)
|
188
127
|
end
|
189
128
|
|
190
129
|
end
|
@@ -193,18 +132,18 @@ describe Chef::Cookbook::SyntaxCheck do
|
|
193
132
|
|
194
133
|
describe "and the files have been syntax checked previously" do
|
195
134
|
before do
|
196
|
-
|
197
|
-
|
135
|
+
syntax_check.untested_ruby_files.each { |f| syntax_check.validated(f) }
|
136
|
+
syntax_check.untested_template_files.each { |f| syntax_check.validated(f) }
|
198
137
|
end
|
199
138
|
|
200
139
|
it "does not syntax check ruby files" do
|
201
|
-
|
202
|
-
|
140
|
+
syntax_check.should_not_receive(:shell_out)
|
141
|
+
syntax_check.validate_ruby_files.should be_true
|
203
142
|
end
|
204
143
|
|
205
144
|
it "does not syntax check templates" do
|
206
|
-
|
207
|
-
|
145
|
+
syntax_check.should_not_receive(:shell_out)
|
146
|
+
syntax_check.validate_templates.should be_true
|
208
147
|
end
|
209
148
|
end
|
210
149
|
end
|
@@ -25,121 +25,183 @@ describe Chef::CookbookLoader do
|
|
25
25
|
@cookbook_loader = Chef::CookbookLoader.new(@repo_paths)
|
26
26
|
end
|
27
27
|
|
28
|
-
describe "
|
29
|
-
|
30
|
-
@cookbook_loader
|
28
|
+
describe "loading all cookbooks" do
|
29
|
+
before(:each) do
|
30
|
+
@cookbook_loader.load_cookbooks
|
31
31
|
end
|
32
32
|
|
33
|
+
describe "[]" do
|
34
|
+
it "should return cookbook objects with []" do
|
35
|
+
@cookbook_loader[:openldap].should be_a_kind_of(Chef::CookbookVersion)
|
36
|
+
end
|
33
37
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
it "should allow you to look up available cookbooks with [] and a symbol" do
|
39
|
-
@cookbook_loader[:openldap].name.should eql(:openldap)
|
40
|
-
end
|
38
|
+
it "should raise an exception if it cannot find a cookbook with []" do
|
39
|
+
lambda { @cookbook_loader[:monkeypoop] }.should raise_error(Chef::Exceptions::CookbookNotFoundInRepo)
|
40
|
+
end
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
42
|
+
it "should allow you to look up available cookbooks with [] and a symbol" do
|
43
|
+
@cookbook_loader[:openldap].name.should eql(:openldap)
|
44
|
+
end
|
46
45
|
|
47
|
-
|
48
|
-
|
49
|
-
seen = Hash.new
|
50
|
-
@cookbook_loader.each do |cookbook_name, cookbook|
|
51
|
-
seen[cookbook_name] = true
|
46
|
+
it "should allow you to look up available cookbooks with [] and a string" do
|
47
|
+
@cookbook_loader["openldap"].name.should eql(:openldap)
|
52
48
|
end
|
53
|
-
seen.should have_key("openldap")
|
54
|
-
seen.should have_key("apache2")
|
55
49
|
end
|
56
50
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
51
|
+
describe "each" do
|
52
|
+
it "should allow you to iterate over cookbooks with each" do
|
53
|
+
seen = Hash.new
|
54
|
+
@cookbook_loader.each do |cookbook_name, cookbook|
|
55
|
+
seen[cookbook_name] = true
|
56
|
+
end
|
57
|
+
seen.should have_key("openldap")
|
58
|
+
seen.should have_key("apache2")
|
61
59
|
end
|
62
|
-
seen[0].should == "angrybash"
|
63
|
-
seen[1].should == "apache2"
|
64
|
-
seen[2].should == "borken"
|
65
|
-
seen[3].should == "java"
|
66
|
-
seen[4].should == "openldap"
|
67
|
-
end
|
68
|
-
end
|
69
60
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
61
|
+
it "should iterate in alphabetical order" do
|
62
|
+
seen = Array.new
|
63
|
+
@cookbook_loader.each do |cookbook_name, cookbook|
|
64
|
+
seen << cookbook_name
|
65
|
+
end
|
66
|
+
seen[0].should == "angrybash"
|
67
|
+
seen[1].should == "apache2"
|
68
|
+
seen[2].should == "borken"
|
69
|
+
seen[3].should == "java"
|
70
|
+
seen[4].should == "openldap"
|
71
|
+
end
|
76
72
|
end
|
73
|
+
|
74
|
+
describe "load_cookbooks" do
|
75
|
+
it "should find all the cookbooks in the cookbook path" do
|
76
|
+
Chef::Config.cookbook_path << File.expand_path(File.join(CHEF_SPEC_DATA, "hidden-cookbooks"))
|
77
|
+
@cookbook_loader.load_cookbooks
|
78
|
+
@cookbook_loader.should have_key(:openldap)
|
79
|
+
@cookbook_loader.should have_key(:apache2)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should allow you to override an attribute file via cookbook_path" do
|
83
|
+
@cookbook_loader[:openldap].attribute_filenames.detect { |f|
|
84
|
+
f =~ /cookbooks\/openldap\/attributes\/default.rb/
|
85
|
+
}.should_not eql(nil)
|
86
|
+
@cookbook_loader[:openldap].attribute_filenames.detect { |f|
|
87
|
+
f =~ /kitchen\/openldap\/attributes\/default.rb/
|
88
|
+
}.should eql(nil)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should load different attribute files from deeper paths" do
|
92
|
+
@cookbook_loader[:openldap].attribute_filenames.detect { |f|
|
93
|
+
f =~ /kitchen\/openldap\/attributes\/robinson.rb/
|
94
|
+
}.should_not eql(nil)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should allow you to override a definition file via cookbook_path" do
|
98
|
+
@cookbook_loader[:openldap].definition_filenames.detect { |f|
|
99
|
+
f =~ /cookbooks\/openldap\/definitions\/client.rb/
|
100
|
+
}.should_not eql(nil)
|
101
|
+
@cookbook_loader[:openldap].definition_filenames.detect { |f|
|
102
|
+
f =~ /kitchen\/openldap\/definitions\/client.rb/
|
103
|
+
}.should eql(nil)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should load definition files from deeper paths" do
|
107
|
+
@cookbook_loader[:openldap].definition_filenames.detect { |f|
|
108
|
+
f =~ /kitchen\/openldap\/definitions\/drewbarrymore.rb/
|
109
|
+
}.should_not eql(nil)
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should allow you to override a recipe file via cookbook_path" do
|
113
|
+
@cookbook_loader[:openldap].recipe_filenames.detect { |f|
|
114
|
+
f =~ /cookbooks\/openldap\/recipes\/gigantor.rb/
|
115
|
+
}.should_not eql(nil)
|
116
|
+
@cookbook_loader[:openldap].recipe_filenames.detect { |f|
|
117
|
+
f =~ /kitchen\/openldap\/recipes\/gigantor.rb/
|
118
|
+
}.should eql(nil)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should load recipe files from deeper paths" do
|
122
|
+
@cookbook_loader[:openldap].recipe_filenames.detect { |f|
|
123
|
+
f =~ /kitchen\/openldap\/recipes\/woot.rb/
|
124
|
+
}.should_not eql(nil)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should allow you to have an 'ignore' file, which skips loading files in later cookbooks" do
|
128
|
+
@cookbook_loader[:openldap].recipe_filenames.detect { |f|
|
129
|
+
f =~ /kitchen\/openldap\/recipes\/ignoreme.rb/
|
130
|
+
}.should eql(nil)
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should find files that start with a ." do
|
134
|
+
@cookbook_loader[:openldap].file_filenames.detect { |f|
|
135
|
+
f =~ /\.dotfile$/
|
136
|
+
}.should =~ /\.dotfile$/
|
137
|
+
@cookbook_loader[:openldap].file_filenames.detect { |f|
|
138
|
+
f =~ /\.ssh\/id_rsa$/
|
139
|
+
}.should =~ /\.ssh\/id_rsa$/
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should load the metadata for the cookbook" do
|
143
|
+
@cookbook_loader.metadata[:openldap].name.should == :openldap
|
144
|
+
@cookbook_loader.metadata[:openldap].should be_a_kind_of(Chef::Cookbook::Metadata)
|
145
|
+
end
|
77
146
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
147
|
+
it "should check each cookbook directory only once (CHEF-3487)" do
|
148
|
+
cookbooks = []
|
149
|
+
@repo_paths.each do |repo_path|
|
150
|
+
cookbooks |= Dir[File.join(repo_path, "*")]
|
151
|
+
end
|
152
|
+
cookbooks.each do |cookbook|
|
153
|
+
File.should_receive(:directory?).with(cookbook).once;
|
154
|
+
end
|
155
|
+
@cookbook_loader.load_cookbooks
|
156
|
+
end
|
157
|
+
end # load_cookbooks
|
86
158
|
|
87
|
-
|
88
|
-
@cookbook_loader[:openldap].attribute_filenames.detect { |f|
|
89
|
-
f =~ /kitchen\/openldap\/attributes\/robinson.rb/
|
90
|
-
}.should_not eql(nil)
|
91
|
-
end
|
159
|
+
end # loading all cookbooks
|
92
160
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
@cookbook_loader[:openldap].definition_filenames.detect { |f|
|
98
|
-
f =~ /kitchen\/openldap\/definitions\/client.rb/
|
99
|
-
}.should eql(nil)
|
161
|
+
describe "loading only one cookbook" do
|
162
|
+
before(:each) do
|
163
|
+
@cookbook_loader = Chef::CookbookLoader.new(@repo_paths)
|
164
|
+
@cookbook_loader.load_cookbook("openldap")
|
100
165
|
end
|
101
166
|
|
102
|
-
it "should
|
103
|
-
|
104
|
-
|
105
|
-
|
167
|
+
it "should have loaded the correct cookbook" do
|
168
|
+
seen = Hash.new
|
169
|
+
@cookbook_loader.each do |cookbook_name, cookbook|
|
170
|
+
seen[cookbook_name] = true
|
171
|
+
end
|
172
|
+
seen.should have_key("openldap")
|
106
173
|
end
|
107
174
|
|
108
|
-
it "should
|
109
|
-
@cookbook_loader
|
110
|
-
|
111
|
-
}.should_not eql(nil)
|
112
|
-
@cookbook_loader[:openldap].recipe_filenames.detect { |f|
|
113
|
-
f =~ /kitchen\/openldap\/recipes\/gigantor.rb/
|
114
|
-
}.should eql(nil)
|
175
|
+
it "should not load the cookbook again when accessed" do
|
176
|
+
@cookbook_loader.should_not_receive('load_cookbook')
|
177
|
+
@cookbook_loader["openldap"]
|
115
178
|
end
|
116
179
|
|
117
|
-
it "should load
|
118
|
-
|
119
|
-
|
120
|
-
|
180
|
+
it "should not load the other cookbooks" do
|
181
|
+
seen = Hash.new
|
182
|
+
@cookbook_loader.each do |cookbook_name, cookbook|
|
183
|
+
seen[cookbook_name] = true
|
184
|
+
end
|
185
|
+
seen.should_not have_key("apache2")
|
121
186
|
end
|
122
187
|
|
123
|
-
it "should
|
124
|
-
@cookbook_loader[
|
125
|
-
f =~ /kitchen\/openldap\/recipes\/ignoreme.rb/
|
126
|
-
}.should eql(nil)
|
188
|
+
it "should load another cookbook lazily with []" do
|
189
|
+
@cookbook_loader["apache2"].should be_a_kind_of(Chef::CookbookVersion)
|
127
190
|
end
|
128
191
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
@cookbook_loader[:openldap].file_filenames.detect { |f|
|
134
|
-
f =~ /\.ssh\/id_rsa$/
|
135
|
-
}.should =~ /\.ssh\/id_rsa$/
|
136
|
-
end
|
192
|
+
describe "loading all cookbooks after loading only one cookbook" do
|
193
|
+
before(:each) do
|
194
|
+
@cookbook_loader.load_cookbooks
|
195
|
+
end
|
137
196
|
|
138
|
-
|
139
|
-
|
140
|
-
|
197
|
+
it "should load all cookbooks" do
|
198
|
+
seen = Hash.new
|
199
|
+
@cookbook_loader.each do |cookbook_name, cookbook|
|
200
|
+
seen[cookbook_name] = true
|
201
|
+
end
|
202
|
+
seen.should have_key("openldap")
|
203
|
+
seen.should have_key("apache2")
|
204
|
+
end
|
141
205
|
end
|
142
|
-
|
143
|
-
end
|
144
|
-
|
206
|
+
end # loading only one cookbook
|
145
207
|
end
|