chef 12.0.0.alpha.0 → 12.0.0.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +3 -5
- data/lib/chef/api_client.rb +1 -1
- data/lib/chef/application.rb +16 -8
- data/lib/chef/chef_fs/chef_fs_data_store.rb +1 -1
- data/lib/chef/chef_fs/command_line.rb +1 -1
- data/lib/chef/chef_fs/file_system.rb +1 -1
- data/lib/chef/chef_fs/file_system/acl_entry.rb +1 -1
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +3 -3
- data/lib/chef/chef_fs/file_system/cookbook_file.rb +2 -2
- data/lib/chef/chef_fs/file_system/rest_list_dir.rb +2 -2
- data/lib/chef/chef_fs/file_system/rest_list_entry.rb +4 -4
- data/lib/chef/config.rb +6 -5
- data/lib/chef/config_fetcher.rb +1 -1
- data/lib/chef/cookbook/cookbook_version_loader.rb +126 -43
- data/lib/chef/cookbook/metadata.rb +102 -53
- data/lib/chef/cookbook/syntax_check.rb +1 -1
- data/lib/chef/cookbook_loader.rb +62 -14
- data/lib/chef/cookbook_site_streaming_uploader.rb +12 -1
- data/lib/chef/cookbook_version.rb +13 -4
- data/lib/chef/data_bag.rb +28 -15
- data/lib/chef/data_bag_item.rb +5 -7
- data/lib/chef/digester.rb +5 -9
- data/lib/chef/dsl/recipe.rb +14 -0
- data/lib/chef/encrypted_data_bag_item.rb +1 -0
- data/lib/chef/encrypted_data_bag_item/assertions.rb +57 -0
- data/lib/chef/encrypted_data_bag_item/decryptor.rb +52 -28
- data/lib/chef/encrypted_data_bag_item/encrypted_data_bag_item_assertions.rb +37 -0
- data/lib/chef/encrypted_data_bag_item/encryption_failure.rb +22 -0
- data/lib/chef/encrypted_data_bag_item/encryptor.rb +79 -8
- data/lib/chef/environment.rb +1 -3
- data/lib/chef/exceptions.rb +18 -3
- data/lib/chef/formatters/base.rb +7 -0
- data/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb +1 -1
- data/lib/chef/handler/json_file.rb +0 -1
- data/lib/chef/http/json_output.rb +1 -1
- data/lib/chef/json_compat.rb +24 -6
- data/lib/chef/knife/bootstrap.rb +2 -2
- data/lib/chef/knife/client_delete.rb +1 -1
- data/lib/chef/knife/cookbook_site_download.rb +1 -1
- data/lib/chef/knife/cookbook_site_list.rb +1 -1
- data/lib/chef/knife/cookbook_site_search.rb +1 -1
- data/lib/chef/knife/cookbook_site_share.rb +2 -2
- data/lib/chef/knife/cookbook_site_show.rb +3 -3
- data/lib/chef/knife/cookbook_site_unshare.rb +1 -1
- data/lib/chef/knife/core/node_editor.rb +2 -3
- data/lib/chef/knife/core/ui.rb +2 -2
- data/lib/chef/knife/deps.rb +2 -3
- data/lib/chef/mixin/shell_out.rb +1 -1
- data/lib/chef/mixin/windows_architecture_helper.rb +1 -0
- data/lib/chef/node.rb +1 -2
- data/lib/chef/platform/provider_mapping.rb +33 -6
- data/lib/chef/provider.rb +0 -2
- data/lib/chef/provider/cookbook_file/content.rb +1 -1
- data/lib/chef/provider/cron.rb +11 -0
- data/lib/chef/provider/deploy.rb +3 -2
- data/lib/chef/provider/deploy/revision.rb +2 -2
- data/lib/chef/provider/env.rb +1 -1
- data/lib/chef/provider/env/windows.rb +5 -9
- data/lib/chef/provider/file.rb +84 -33
- data/lib/chef/provider/git.rb +2 -1
- data/lib/chef/provider/group/aix.rb +17 -2
- data/lib/chef/provider/group/dscl.rb +27 -9
- data/lib/chef/provider/group/pw.rb +8 -1
- data/lib/chef/provider/http_request.rb +4 -4
- data/lib/chef/provider/log.rb +4 -14
- data/lib/chef/provider/mount/mount.rb +2 -2
- data/lib/chef/provider/package/ips.rb +17 -23
- data/lib/chef/provider/package/paludis.rb +2 -2
- data/lib/chef/provider/package/rpm.rb +2 -2
- data/lib/chef/provider/package/rubygems.rb +2 -0
- data/lib/chef/provider/package/yum.rb +2 -0
- data/lib/chef/provider/package/zypper.rb +1 -1
- data/lib/chef/provider/remote_file/cache_control_data.rb +2 -2
- data/lib/chef/provider/service/windows.rb +87 -21
- data/lib/chef/provider/user/aix.rb +95 -0
- data/lib/chef/provider/user/dscl.rb +544 -156
- data/lib/chef/provider/user/useradd.rb +1 -0
- data/lib/chef/providers.rb +1 -0
- data/lib/chef/resource.rb +4 -3
- data/lib/chef/resource/freebsd_package.rb +10 -2
- data/lib/chef/resource/paludis_package.rb +1 -0
- data/lib/chef/resource/scm.rb +10 -0
- data/lib/chef/resource/user.rb +27 -0
- data/lib/chef/resource/windows_service.rb +53 -0
- data/lib/chef/resource_collection.rb +23 -12
- data/lib/chef/resource_reporter.rb +10 -10
- data/lib/chef/resources.rb +1 -0
- data/lib/chef/role.rb +3 -3
- data/lib/chef/run_list.rb +6 -3
- data/lib/chef/user.rb +1 -1
- data/lib/chef/util/diff.rb +1 -2
- data/lib/chef/version.rb +1 -1
- data/lib/chef/version_constraint.rb +4 -4
- data/spec/data/cookbooks/angrybash/metadata.rb +2 -0
- data/spec/data/cookbooks/apache2/metadata.rb +2 -0
- data/spec/data/cookbooks/borken/metadata.rb +2 -0
- data/spec/data/cookbooks/ignorken/metadata.rb +2 -0
- data/spec/data/cookbooks/java/metadata.rb +2 -0
- data/spec/data/cookbooks/name-mismatch-versionnumber/README.md +4 -0
- data/spec/data/cookbooks/name-mismatch-versionnumber/metadata.rb +8 -0
- data/spec/data/cookbooks/name-mismatch-versionnumber/recipes/default.rb +8 -0
- data/spec/data/cookbooks/openldap/files/default/remotedir/not_a_template.erb +2 -0
- data/spec/data/cookbooks/preseed/metadata.rb +2 -0
- data/spec/data/incomplete-metadata-chef-repo/incomplete-metadata/README.md +4 -0
- data/spec/data/incomplete-metadata-chef-repo/incomplete-metadata/metadata.rb +13 -0
- data/spec/data/incomplete-metadata-chef-repo/incomplete-metadata/recipes/default.rb +8 -0
- data/spec/data/invalid-metadata-chef-repo/invalid-metadata/README.md +4 -0
- data/spec/data/invalid-metadata-chef-repo/invalid-metadata/metadata.rb +10 -0
- data/spec/data/invalid-metadata-chef-repo/invalid-metadata/recipes/default.rb +8 -0
- data/spec/data/mac_users/10.7-8.plist.xml +559 -0
- data/spec/data/mac_users/10.7-8.shadow.xml +11 -0
- data/spec/data/mac_users/10.7.plist.xml +559 -0
- data/spec/data/mac_users/10.7.shadow.xml +11 -0
- data/spec/data/mac_users/10.8.plist.xml +559 -0
- data/spec/data/mac_users/10.8.shadow.xml +21 -0
- data/spec/data/mac_users/10.9.plist.xml +560 -0
- data/spec/data/mac_users/10.9.shadow.xml +21 -0
- data/spec/data/object_loader/environments/test.json +2 -0
- data/spec/data/object_loader/environments/test_json_class.json +2 -0
- data/spec/data/object_loader/nodes/test.json +2 -0
- data/spec/data/object_loader/nodes/test_json_class.json +2 -0
- data/spec/data/object_loader/roles/test.json +2 -0
- data/spec/data/object_loader/roles/test_json_class.json +2 -0
- data/spec/functional/resource/bff_spec.rb +1 -1
- data/spec/functional/resource/cron_spec.rb +20 -1
- data/spec/functional/resource/env_spec.rb +137 -0
- data/spec/functional/resource/group_spec.rb +7 -5
- data/spec/functional/resource/remote_file_spec.rb +12 -1
- data/spec/functional/resource/user/dscl_spec.rb +198 -0
- data/spec/functional/resource/{user_spec.rb → user/useradd_spec.rb} +175 -37
- data/spec/integration/client/client_spec.rb +6 -4
- data/spec/integration/client/ipv6_spec.rb +16 -14
- data/spec/integration/knife/chef_fs_data_store_spec.rb +57 -46
- data/spec/integration/knife/chef_repo_path_spec.rb +105 -78
- data/spec/integration/knife/chef_repository_file_system_spec.rb +100 -84
- data/spec/integration/knife/chefignore_spec.rb +76 -46
- data/spec/integration/knife/common_options_spec.rb +16 -21
- data/spec/integration/knife/cookbook_api_ipv6_spec.rb +3 -3
- data/spec/integration/knife/delete_spec.rb +66 -46
- data/spec/integration/knife/deps_spec.rb +145 -94
- data/spec/integration/knife/diff_spec.rb +176 -110
- data/spec/integration/knife/download_spec.rb +229 -133
- data/spec/integration/knife/list_spec.rb +62 -54
- data/spec/integration/knife/raw_spec.rb +24 -9
- data/spec/integration/knife/redirection_spec.rb +2 -2
- data/spec/integration/knife/serve_spec.rb +2 -2
- data/spec/integration/knife/show_spec.rb +32 -26
- data/spec/integration/knife/upload_spec.rb +308 -165
- data/spec/integration/recipes/lwrp_inline_resources_spec.rb +10 -8
- data/spec/integration/solo/solo_spec.rb +22 -11
- data/spec/spec_helper.rb +3 -0
- data/spec/support/lib/chef/resource/zen_follower.rb +46 -0
- data/spec/support/platform_helpers.rb +12 -0
- data/spec/support/shared/functional/file_resource.rb +10 -0
- data/spec/support/shared/integration/chef_zero_support.rb +130 -0
- data/spec/support/shared/integration/integration_helper.rb +100 -98
- data/spec/support/shared/integration/knife_support.rb +0 -1
- data/spec/support/shared/unit/provider/file.rb +6 -4
- data/spec/support/shared/unit/provider/useradd_based_user_provider.rb +10 -1
- data/spec/unit/api_client/registration_spec.rb +83 -74
- data/spec/unit/application_spec.rb +32 -9
- data/spec/unit/cookbook/cookbook_version_loader_spec.rb +179 -0
- data/spec/unit/cookbook/metadata_spec.rb +190 -150
- data/spec/unit/cookbook/syntax_check_spec.rb +3 -2
- data/spec/unit/cookbook_loader_spec.rb +114 -53
- data/spec/unit/{cookbook_site_streaming_uploader.rb → cookbook_site_streaming_uploader_spec.rb} +21 -1
- data/spec/unit/data_bag_spec.rb +88 -13
- data/spec/unit/deprecation_spec.rb +1 -2
- data/spec/unit/encrypted_data_bag_item_spec.rb +145 -9
- data/spec/unit/environment_spec.rb +1 -1
- data/spec/unit/formatters/base_spec.rb +48 -0
- data/spec/unit/json_compat_spec.rb +48 -17
- data/spec/unit/knife/client_delete_spec.rb +4 -4
- data/spec/unit/knife/client_show_spec.rb +15 -5
- data/spec/unit/knife/cookbook_site_download_spec.rb +1 -1
- data/spec/unit/knife/cookbook_site_share_spec.rb +3 -3
- data/spec/unit/knife/data_bag_from_file_spec.rb +0 -2
- data/spec/unit/knife/data_bag_show_spec.rb +23 -14
- data/spec/unit/knife/node_show_spec.rb +32 -15
- data/spec/unit/knife/role_show_spec.rb +59 -0
- data/spec/unit/platform_spec.rb +10 -0
- data/spec/unit/provider/deploy_spec.rb +4 -0
- data/spec/unit/provider/env_spec.rb +19 -0
- data/spec/unit/provider/git_spec.rb +22 -2
- data/spec/unit/provider/group/dscl_spec.rb +38 -1
- data/spec/unit/provider/group/pw_spec.rb +2 -2
- data/spec/unit/provider/http_request_spec.rb +8 -8
- data/spec/unit/provider/log_spec.rb +33 -53
- data/spec/unit/provider/mount/mount_spec.rb +12 -3
- data/spec/unit/provider/package/ips_spec.rb +96 -63
- data/spec/unit/provider/package/paludis_spec.rb +5 -5
- data/spec/unit/provider/package/rpm_spec.rb +12 -0
- data/spec/unit/provider/package/zypper_spec.rb +28 -16
- data/spec/unit/provider/service/windows_spec.rb +77 -17
- data/spec/unit/provider/user/dscl_spec.rb +659 -264
- data/spec/unit/provider/user/useradd_spec.rb +1 -0
- data/spec/unit/recipe_spec.rb +41 -0
- data/spec/unit/resource/scm_spec.rb +11 -0
- data/spec/unit/resource/user_spec.rb +4 -0
- data/spec/unit/resource/windows_service_spec.rb +46 -0
- data/spec/unit/resource_collection_spec.rb +33 -0
- data/spec/unit/resource_reporter_spec.rb +48 -0
- data/spec/unit/resource_spec.rb +9 -2
- data/spec/unit/role_spec.rb +6 -0
- data/spec/unit/version_constraint_spec.rb +28 -0
- metadata +61 -4
@@ -26,7 +26,7 @@ describe Chef::Knife::CookbookSiteDownload do
|
|
26
26
|
@knife.name_args = ['apache2']
|
27
27
|
@noauth_rest = double('no auth rest')
|
28
28
|
@stderr = StringIO.new
|
29
|
-
@cookbook_api_url = '
|
29
|
+
@cookbook_api_url = 'https://supermarket.getchef.com/api/v1/cookbooks'
|
30
30
|
@version = '1.0.2'
|
31
31
|
@version_us = @version.gsub '.', '_'
|
32
32
|
@current_data = { 'deprecated' => false,
|
@@ -108,11 +108,11 @@ describe Chef::Knife::CookbookSiteShare do
|
|
108
108
|
File.stub(:open).and_return(true)
|
109
109
|
end
|
110
110
|
|
111
|
-
it 'should post the cookbook to "
|
112
|
-
response_text = {:uri => '
|
111
|
+
it 'should post the cookbook to "https://supermarket.getchef.com"' do
|
112
|
+
response_text = {:uri => 'https://supermarket.getchef.com/cookbooks/cookbook_name'}.to_json
|
113
113
|
@upload_response.stub(:body).and_return(response_text)
|
114
114
|
@upload_response.stub(:code).and_return(201)
|
115
|
-
Chef::CookbookSiteStreamingUploader.should_receive(:post).with(/
|
115
|
+
Chef::CookbookSiteStreamingUploader.should_receive(:post).with(/supermarket\.getchef\.com/, anything(), anything(), anything())
|
116
116
|
@knife.run
|
117
117
|
end
|
118
118
|
|
@@ -21,7 +21,6 @@ require 'spec_helper'
|
|
21
21
|
require 'chef/data_bag_item'
|
22
22
|
require 'chef/encrypted_data_bag_item'
|
23
23
|
require 'tempfile'
|
24
|
-
require 'json'
|
25
24
|
|
26
25
|
Chef::Knife::DataBagFromFile.load_deps
|
27
26
|
|
@@ -86,7 +85,6 @@ describe Chef::Knife::DataBagFromFile do
|
|
86
85
|
end
|
87
86
|
|
88
87
|
it "loads all from a folder and saves" do
|
89
|
-
dir = File.dirname(@db_file.path)
|
90
88
|
@knife.name_args = [ 'bag_name', @db_folder ]
|
91
89
|
@knife.loader.should_receive(:load_from).with("data_bags", 'bag_name', @db_file.path).and_return(@plain_data)
|
92
90
|
@knife.loader.should_receive(:load_from).with("data_bags", 'bag_name', @db_file2.path).and_return(@plain_data)
|
@@ -30,9 +30,9 @@ describe Chef::Knife::DataBagShow do
|
|
30
30
|
@knife = Chef::Knife::DataBagShow.new
|
31
31
|
@knife.config[:format] = 'json'
|
32
32
|
@rest = double("Chef::REST")
|
33
|
-
@knife.
|
33
|
+
allow(@knife).to receive(:rest).and_return(@rest)
|
34
34
|
@stdout = StringIO.new
|
35
|
-
@knife.ui.
|
35
|
+
allow(@knife.ui).to receive(:stdout).and_return(@stdout)
|
36
36
|
end
|
37
37
|
|
38
38
|
|
@@ -40,24 +40,33 @@ describe Chef::Knife::DataBagShow do
|
|
40
40
|
@knife.instance_variable_set(:@name_args, ['bag_o_data'])
|
41
41
|
data_bag_contents = { "baz"=>"http://localhost:4000/data/bag_o_data/baz",
|
42
42
|
"qux"=>"http://localhost:4000/data/bag_o_data/qux"}
|
43
|
-
Chef::DataBag.
|
43
|
+
expect(Chef::DataBag).to receive(:load).and_return(data_bag_contents)
|
44
44
|
expected = %q|[
|
45
45
|
"baz",
|
46
46
|
"qux"
|
47
47
|
]|
|
48
48
|
@knife.run
|
49
|
-
@stdout.string.strip.
|
49
|
+
expect(@stdout.string.strip).to eq(expected)
|
50
50
|
end
|
51
51
|
|
52
52
|
it "prints the contents of the data bag item when given a bag and item name" do
|
53
53
|
@knife.instance_variable_set(:@name_args, ['bag_o_data', 'an_item'])
|
54
54
|
data_item = Chef::DataBagItem.new.tap {|item| item.raw_data = {"id" => "an_item", "zsh" => "victory_through_tabbing"}}
|
55
55
|
|
56
|
-
Chef::DataBagItem.
|
56
|
+
expect(Chef::DataBagItem).to receive(:load).with('bag_o_data', 'an_item').and_return(data_item)
|
57
57
|
|
58
58
|
@knife.run
|
59
|
-
Chef::JSONCompat.from_json(@stdout.string).
|
59
|
+
expect(Chef::JSONCompat.from_json(@stdout.string)).to eq(data_item.raw_data)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should pretty print the data bag contents" do
|
63
|
+
@knife.instance_variable_set(:@name_args, ['bag_o_data', 'an_item'])
|
64
|
+
data_item = Chef::DataBagItem.new.tap {|item| item.raw_data = {"id" => "an_item", "zsh" => "victory_through_tabbing"}}
|
65
|
+
|
66
|
+
expect(Chef::DataBagItem).to receive(:load).with('bag_o_data', 'an_item').and_return(data_item)
|
60
67
|
|
68
|
+
@knife.run
|
69
|
+
expect(@stdout.string).to eql("{\n \"id\": \"an_item\",\n \"zsh\": \"victory_through_tabbing\"\n}\n")
|
61
70
|
end
|
62
71
|
|
63
72
|
describe "encrypted data bag items" do
|
@@ -83,29 +92,29 @@ describe Chef::Knife::DataBagShow do
|
|
83
92
|
end
|
84
93
|
|
85
94
|
it "prints the decrypted contents of an item when given --secret" do
|
86
|
-
@knife.
|
87
|
-
Chef::EncryptedDataBagItem.
|
95
|
+
allow(@knife).to receive(:config).and_return({:secret => @secret})
|
96
|
+
expect(Chef::EncryptedDataBagItem).to receive(:load).
|
88
97
|
with('bag_name', 'item_name', @secret).
|
89
98
|
and_return(Chef::EncryptedDataBagItem.new(@enc_data, @secret))
|
90
99
|
@knife.run
|
91
|
-
Chef::JSONCompat.from_json(@stdout.string).
|
100
|
+
expect(Chef::JSONCompat.from_json(@stdout.string)).to eq(@plain_data)
|
92
101
|
end
|
93
102
|
|
94
103
|
it "prints the decrypted contents of an item when given --secret_file" do
|
95
|
-
@knife.
|
96
|
-
Chef::EncryptedDataBagItem.
|
104
|
+
allow(@knife).to receive(:config).and_return({:secret_file => @secret_file.path})
|
105
|
+
expect(Chef::EncryptedDataBagItem).to receive(:load).
|
97
106
|
with('bag_name', 'item_name', @secret).
|
98
107
|
and_return(Chef::EncryptedDataBagItem.new(@enc_data, @secret))
|
99
108
|
@knife.run
|
100
|
-
Chef::JSONCompat.from_json(@stdout.string).
|
109
|
+
expect(Chef::JSONCompat.from_json(@stdout.string)).to eq(@plain_data)
|
101
110
|
end
|
102
111
|
end
|
103
112
|
|
104
113
|
describe "command line parsing" do
|
105
114
|
it "prints help if given no arguments" do
|
106
115
|
@knife.instance_variable_set(:@name_args, [])
|
107
|
-
|
108
|
-
@stdout.string.
|
116
|
+
expect { @knife.run }.to raise_error(SystemExit)
|
117
|
+
expect(@stdout.string).to match(/^knife data bag show BAG \[ITEM\] \(options\)/)
|
109
118
|
end
|
110
119
|
end
|
111
120
|
|
@@ -19,30 +19,47 @@
|
|
19
19
|
require 'spec_helper'
|
20
20
|
|
21
21
|
describe Chef::Knife::NodeShow do
|
22
|
+
|
23
|
+
let(:node) do
|
24
|
+
node = Chef::Node.new()
|
25
|
+
node.name("adam")
|
26
|
+
node.run_list = ['role[base]']
|
27
|
+
node
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:knife) do
|
31
|
+
knife = Chef::Knife::NodeShow.new
|
32
|
+
knife.name_args = [ "adam" ]
|
33
|
+
knife
|
34
|
+
end
|
35
|
+
|
22
36
|
before(:each) do
|
23
37
|
Chef::Config[:node_name] = "webmonkey.example.com"
|
24
|
-
@knife = Chef::Knife::NodeShow.new
|
25
|
-
@knife.config = {
|
26
|
-
:attribute => nil,
|
27
|
-
:run_list => nil,
|
28
|
-
:environment => nil
|
29
|
-
}
|
30
|
-
@knife.name_args = [ "adam" ]
|
31
|
-
@knife.stub(:output).and_return(true)
|
32
|
-
@node = Chef::Node.new()
|
33
|
-
Chef::Node.stub(:load).and_return(@node)
|
34
38
|
end
|
35
39
|
|
36
40
|
describe "run" do
|
37
41
|
it "should load the node" do
|
38
|
-
Chef::Node.
|
39
|
-
|
42
|
+
expect(Chef::Node).to receive(:load).with("adam").and_return(node)
|
43
|
+
allow(knife).to receive(:output).and_return(true)
|
44
|
+
knife.run
|
40
45
|
end
|
41
46
|
|
42
47
|
it "should pretty print the node, formatted for display" do
|
43
|
-
|
44
|
-
|
45
|
-
|
48
|
+
knife.config[:format] = nil
|
49
|
+
stdout = StringIO.new
|
50
|
+
allow(knife.ui).to receive(:stdout).and_return(stdout)
|
51
|
+
allow(Chef::Node).to receive(:load).and_return(node)
|
52
|
+
knife.run
|
53
|
+
expect(stdout.string).to eql("Node Name: adam\nEnvironment: _default\nFQDN: \nIP: \nRun List: \nRoles: \nRecipes: \nPlatform: \nTags: \n")
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should pretty print json" do
|
57
|
+
knife.config[:format] = 'json'
|
58
|
+
stdout = StringIO.new
|
59
|
+
allow(knife.ui).to receive(:stdout).and_return(stdout)
|
60
|
+
expect(Chef::Node).to receive(:load).with('adam').and_return(node)
|
61
|
+
knife.run
|
62
|
+
expect(stdout.string).to eql("{\n \"name\": \"adam\",\n \"chef_environment\": \"_default\",\n \"run_list\": [\n\n]\n,\n \"normal\": {\n\n }\n}\n")
|
46
63
|
end
|
47
64
|
end
|
48
65
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Lamont Granquist (<lamont@getchef.com>)
|
3
|
+
# Copyright:: Copyright (c) 2014 Lamont Granquist
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'spec_helper'
|
20
|
+
|
21
|
+
describe Chef::Knife::RoleShow do
|
22
|
+
let(:role) { 'base' }
|
23
|
+
|
24
|
+
let(:knife) do
|
25
|
+
knife = Chef::Knife::RoleShow.new
|
26
|
+
knife.name_args = [ role ]
|
27
|
+
knife
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:role_mock) { double('role_mock') }
|
31
|
+
|
32
|
+
describe 'run' do
|
33
|
+
it 'should list the role' do
|
34
|
+
expect(Chef::Role).to receive(:load).with('base').and_return(role_mock)
|
35
|
+
expect(knife).to receive(:format_for_display).with(role_mock)
|
36
|
+
knife.run
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should pretty print json' do
|
40
|
+
knife.config[:format] = 'json'
|
41
|
+
stdout = StringIO.new
|
42
|
+
allow(knife.ui).to receive(:stdout).and_return(stdout)
|
43
|
+
fake_role_contents = {"foo"=>"bar", "baz"=>"qux"}
|
44
|
+
expect(Chef::Role).to receive(:load).with('base').and_return(fake_role_contents)
|
45
|
+
knife.run
|
46
|
+
expect(stdout.string).to eql("{\n \"foo\": \"bar\",\n \"baz\": \"qux\"\n}\n")
|
47
|
+
end
|
48
|
+
|
49
|
+
context "without a role name" do
|
50
|
+
let(:role) { }
|
51
|
+
|
52
|
+
it 'should print usage and exit when a role name is not provided' do
|
53
|
+
expect(knife).to receive(:show_usage)
|
54
|
+
expect(knife.ui).to receive(:fatal)
|
55
|
+
expect { knife.run }.to raise_error(SystemExit)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/spec/unit/platform_spec.rb
CHANGED
@@ -254,6 +254,16 @@ describe Chef::Platform do
|
|
254
254
|
|
255
255
|
end
|
256
256
|
|
257
|
+
it "does not overwrite the platform map when using :default platform" do
|
258
|
+
Chef::Platform.set(
|
259
|
+
:resource => :file,
|
260
|
+
:platform => :default,
|
261
|
+
:provider => "new school"
|
262
|
+
)
|
263
|
+
Chef::Platform.platforms[:default][:file].should eql("new school")
|
264
|
+
Chef::Platform.platforms[:default][:cat].should eql("nice")
|
265
|
+
end
|
266
|
+
|
257
267
|
end
|
258
268
|
|
259
269
|
context "while testing the configured platform data" do
|
@@ -192,6 +192,7 @@ describe Chef::Provider::Deploy do
|
|
192
192
|
FileUtils.should_receive(:rm_rf).with("/my/deploy/dir/releases/5")
|
193
193
|
@provider.run_action(:rollback)
|
194
194
|
@provider.release_path.should eql("/my/deploy/dir/releases/3")
|
195
|
+
@provider.shared_path.should eql("/my/deploy/dir/shared")
|
195
196
|
end
|
196
197
|
|
197
198
|
it "sets the release path to the specified release, symlinks, and rm's any newer releases on rollback" do
|
@@ -203,6 +204,7 @@ describe Chef::Provider::Deploy do
|
|
203
204
|
FileUtils.should_receive(:rm_rf).with("/my/deploy/dir/releases/20040815162342")
|
204
205
|
@provider.run_action(:rollback)
|
205
206
|
@provider.release_path.should eql("/my/deploy/dir/releases/20040700000000")
|
207
|
+
@provider.shared_path.should eql("/my/deploy/dir/shared")
|
206
208
|
end
|
207
209
|
|
208
210
|
it "sets the release path to the penultimate release, symlinks, and rm's the last release on rollback" do
|
@@ -216,6 +218,7 @@ describe Chef::Provider::Deploy do
|
|
216
218
|
FileUtils.should_receive(:rm_rf).with("/my/deploy/dir/releases/20040815162342")
|
217
219
|
@provider.run_action(:rollback)
|
218
220
|
@provider.release_path.should eql("/my/deploy/dir/releases/20040700000000")
|
221
|
+
@provider.shared_path.should eql("/my/deploy/dir/shared")
|
219
222
|
end
|
220
223
|
|
221
224
|
describe "if there are no releases to fallback to" do
|
@@ -255,6 +258,7 @@ describe Chef::Provider::Deploy do
|
|
255
258
|
FileUtils.should_receive(:rm_rf).with("/my/deploy/dir/releases/20040815162342")
|
256
259
|
@provider.run_action(:rollback)
|
257
260
|
@provider.release_path.should eql("/my/deploy/dir/releases/20040700000000")
|
261
|
+
@provider.shared_path.should eql("/my/deploy/dir/shared")
|
258
262
|
end
|
259
263
|
end
|
260
264
|
|
@@ -229,4 +229,23 @@ describe Chef::Provider::Env do
|
|
229
229
|
@provider.compare_value.should be_true
|
230
230
|
end
|
231
231
|
end
|
232
|
+
|
233
|
+
describe "modify_env" do
|
234
|
+
before(:each) do
|
235
|
+
@provider.stub(:create_env).and_return(true)
|
236
|
+
@new_resource.delim ";"
|
237
|
+
|
238
|
+
@current_resource = Chef::Resource::Env.new("FOO")
|
239
|
+
@current_resource.value "C:/foo/bin"
|
240
|
+
@provider.current_resource = @current_resource
|
241
|
+
end
|
242
|
+
|
243
|
+
it "should not modify the variable passed to the resource" do
|
244
|
+
new_value = "C:/bar/bin"
|
245
|
+
passed_value = new_value.dup
|
246
|
+
@new_resource.value(passed_value)
|
247
|
+
@provider.modify_env
|
248
|
+
passed_value.should == new_value
|
249
|
+
end
|
250
|
+
end
|
232
251
|
end
|
@@ -195,6 +195,26 @@ SHAS
|
|
195
195
|
@provider.clone
|
196
196
|
end
|
197
197
|
end
|
198
|
+
context "with a specific home" do
|
199
|
+
let (:override_home) do
|
200
|
+
{"HOME" => "/home/masterNinja"}
|
201
|
+
end
|
202
|
+
let(:overrided_options) do
|
203
|
+
{
|
204
|
+
:user => deploy_user,
|
205
|
+
:environment => { "GIT_SSH" => wrapper, "HOME" => "/home/masterNinja" },
|
206
|
+
:log_tag => "git[web2.0 app]"
|
207
|
+
}
|
208
|
+
end
|
209
|
+
before do
|
210
|
+
@resource.environment(override_home)
|
211
|
+
end
|
212
|
+
before { @resource.environment(override_home) }
|
213
|
+
it "clones a repo with amended git options with specific home" do
|
214
|
+
@provider.should_receive(:shell_out!).with(expected_cmd, overrided_options)
|
215
|
+
@provider.clone
|
216
|
+
end
|
217
|
+
end
|
198
218
|
end
|
199
219
|
|
200
220
|
it "runs a clone command with escaped destination" do
|
@@ -224,8 +244,8 @@ SHAS
|
|
224
244
|
@provider.clone
|
225
245
|
end
|
226
246
|
|
227
|
-
it "runs a checkout command with default options" do
|
228
|
-
expected_cmd = 'git checkout -
|
247
|
+
it "runs a checkout command with default options and uses -B to reset branches if necessary" do
|
248
|
+
expected_cmd = 'git checkout -B deploy d35af14d41ae22b19da05d7d03a0bafc321b244c'
|
229
249
|
@provider.should_receive(:shell_out!).with(expected_cmd, :cwd => "/my/deploy/dir",
|
230
250
|
:log_tag => "git[web2.0 app]")
|
231
251
|
@provider.checkout
|
@@ -240,6 +240,7 @@ describe Chef::Provider::Group::Dscl do
|
|
240
240
|
@provider.load_current_resource
|
241
241
|
@provider.define_resource_requirements
|
242
242
|
end
|
243
|
+
|
243
244
|
it "raises an error if the required binary /usr/bin/dscl doesn't exist" do
|
244
245
|
File.should_receive(:exists?).with("/usr/bin/dscl").and_return(false)
|
245
246
|
|
@@ -251,7 +252,7 @@ describe Chef::Provider::Group::Dscl do
|
|
251
252
|
lambda { @provider.process_resource_requirements }.should_not raise_error
|
252
253
|
end
|
253
254
|
end
|
254
|
-
|
255
|
+
|
255
256
|
describe "when creating the group" do
|
256
257
|
it "creates the group, password field, gid, and sets group membership" do
|
257
258
|
@provider.should_receive(:set_gid).and_return(true)
|
@@ -294,3 +295,39 @@ describe Chef::Provider::Group::Dscl do
|
|
294
295
|
end
|
295
296
|
end
|
296
297
|
end
|
298
|
+
|
299
|
+
describe 'Test DSCL loading' do
|
300
|
+
before do
|
301
|
+
@node = Chef::Node.new
|
302
|
+
@events = Chef::EventDispatch::Dispatcher.new
|
303
|
+
@run_context = Chef::RunContext.new(@node, {}, @events)
|
304
|
+
@new_resource = Chef::Resource::Group.new("aj")
|
305
|
+
@provider = Chef::Provider::Group::Dscl.new(@new_resource, @run_context)
|
306
|
+
@output = <<-EOF
|
307
|
+
AppleMetaNodeLocation: /Local/Default
|
308
|
+
Comment:
|
309
|
+
Test Group
|
310
|
+
GeneratedUID: AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA
|
311
|
+
NestedGroups: AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAB
|
312
|
+
Password: *
|
313
|
+
PrimaryGroupID: 999
|
314
|
+
RealName:
|
315
|
+
TestGroup
|
316
|
+
RecordName: com.apple.aj
|
317
|
+
RecordType: dsRecTypeStandard:Groups
|
318
|
+
GroupMembership: waka bar
|
319
|
+
EOF
|
320
|
+
@provider.stub(:safe_dscl).with("read /Groups/aj").and_return(@output)
|
321
|
+
@current_resource = @provider.load_current_resource
|
322
|
+
|
323
|
+
end
|
324
|
+
|
325
|
+
it 'should parse gid properly' do
|
326
|
+
File.stub(:exists?).and_return(true)
|
327
|
+
@current_resource.gid.should eq("999")
|
328
|
+
end
|
329
|
+
it 'should parse members properly' do
|
330
|
+
File.stub(:exists?).and_return(true)
|
331
|
+
@current_resource.members.should eq(['waka', 'bar'])
|
332
|
+
end
|
333
|
+
end
|
@@ -49,7 +49,7 @@ describe Chef::Provider::Group::Pw do
|
|
49
49
|
describe "when creating a group" do
|
50
50
|
it "should run pw groupadd with the return of set_options and set_members_option" do
|
51
51
|
@new_resource.gid(23)
|
52
|
-
@provider.should_receive(:run_command).with({ :command => "pw groupadd wheel -g '23'" }).and_return(true)
|
52
|
+
@provider.should_receive(:run_command).with({ :command => "pw groupadd wheel -g '23' -M root,aj" }).and_return(true)
|
53
53
|
@provider.create_group
|
54
54
|
end
|
55
55
|
end
|
@@ -113,7 +113,7 @@ describe Chef::Provider::Group::Pw do
|
|
113
113
|
@provider.set_members_options
|
114
114
|
end
|
115
115
|
|
116
|
-
it "should set the -
|
116
|
+
it "should set the -m option with the members joined by ','" do
|
117
117
|
@provider.set_members_options.should eql([ " -m all,your,base" ])
|
118
118
|
end
|
119
119
|
end
|
@@ -53,13 +53,13 @@ describe Chef::Provider::HttpRequest do
|
|
53
53
|
|
54
54
|
it "should inflate a message block at runtime" do
|
55
55
|
@new_resource.message { "return" }
|
56
|
-
@http.should_receive(:get).with("http://www.opscode.com
|
56
|
+
@http.should_receive(:get).with("http://www.opscode.com/", {})
|
57
57
|
@provider.run_action(:get)
|
58
58
|
@new_resource.should be_updated
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should run a GET request" do
|
62
|
-
@http.should_receive(:get).with("http://www.opscode.com
|
62
|
+
@http.should_receive(:get).with("http://www.opscode.com/", {})
|
63
63
|
@provider.run_action(:get)
|
64
64
|
@new_resource.should be_updated
|
65
65
|
end
|
@@ -112,25 +112,25 @@ describe Chef::Provider::HttpRequest do
|
|
112
112
|
|
113
113
|
it "should inflate a message block at runtime" do
|
114
114
|
@new_resource.message { "return" }
|
115
|
-
@http.should_receive(:head).with("http://www.opscode.com
|
115
|
+
@http.should_receive(:head).with("http://www.opscode.com/", {}).and_return(nil)
|
116
116
|
@provider.run_action(:head)
|
117
117
|
@new_resource.should be_updated
|
118
118
|
end
|
119
119
|
|
120
120
|
it "should run a HEAD request" do
|
121
|
-
@http.should_receive(:head).with("http://www.opscode.com
|
121
|
+
@http.should_receive(:head).with("http://www.opscode.com/", {}).and_return(nil)
|
122
122
|
@provider.run_action(:head)
|
123
123
|
@new_resource.should be_updated
|
124
124
|
end
|
125
125
|
|
126
126
|
it "should update a HEAD request with empty string response body (CHEF-4762)" do
|
127
|
-
@http.should_receive(:head).with("http://www.opscode.com
|
127
|
+
@http.should_receive(:head).with("http://www.opscode.com/", {}).and_return("")
|
128
128
|
@provider.run_action(:head)
|
129
129
|
@new_resource.should be_updated
|
130
130
|
end
|
131
131
|
|
132
132
|
it "should update a HEAD request with nil response body (CHEF-4762)" do
|
133
|
-
@http.should_receive(:head).with("http://www.opscode.com
|
133
|
+
@http.should_receive(:head).with("http://www.opscode.com/", {}).and_return(nil)
|
134
134
|
@provider.run_action(:head)
|
135
135
|
@new_resource.should be_updated
|
136
136
|
end
|
@@ -138,14 +138,14 @@ describe Chef::Provider::HttpRequest do
|
|
138
138
|
it "should not update a HEAD request if a not modified response (CHEF-4762)" do
|
139
139
|
if_modified_since = File.mtime(__FILE__).httpdate
|
140
140
|
@new_resource.headers "If-Modified-Since" => if_modified_since
|
141
|
-
@http.should_receive(:head).with("http://www.opscode.com
|
141
|
+
@http.should_receive(:head).with("http://www.opscode.com/", {"If-Modified-Since" => if_modified_since}).and_return(false)
|
142
142
|
@provider.run_action(:head)
|
143
143
|
@new_resource.should_not be_updated
|
144
144
|
end
|
145
145
|
|
146
146
|
it "should run a HEAD request with If-Modified-Since header" do
|
147
147
|
@new_resource.headers "If-Modified-Since" => File.mtime(__FILE__).httpdate
|
148
|
-
@http.should_receive(:head).with("http://www.opscode.com
|
148
|
+
@http.should_receive(:head).with("http://www.opscode.com/", @new_resource.headers)
|
149
149
|
@provider.run_action(:head)
|
150
150
|
end
|
151
151
|
|