diff options
Diffstat (limited to 'spec/integration')
62 files changed, 0 insertions, 12710 deletions
diff --git a/spec/integration/knife/chef_fs_data_store_spec.rb b/spec/integration/knife/chef_fs_data_store_spec.rb deleted file mode 100644 index fda06164a4..0000000000 --- a/spec/integration/knife/chef_fs_data_store_spec.rb +++ /dev/null @@ -1,557 +0,0 @@ -# -# Author:: John Keiser (<jkeiser@chef.io>) -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "chef/knife/list" -require "chef/knife/delete" -require "chef/knife/show" -require "chef/knife/raw" -require "chef/knife/cookbook_upload" - -describe "ChefFSDataStore tests", :workstation do - include IntegrationSupport - include KnifeSupport - - let(:cookbook_x_100_metadata_rb) { cb_metadata("x", "1.0.0") } - let(:cookbook_z_100_metadata_rb) { cb_metadata("z", "1.0.0") } - - describe "with repo mode 'hosted_everything' (default)" do - before do - Chef::Config.chef_zero.osc_compat = false - end - - when_the_repository "has one of each thing" do - before do - file "clients/x.json", {} - file "cookbook_artifacts/x-111/metadata.rb", cookbook_x_100_metadata_rb - file "cookbooks/x/metadata.rb", cookbook_x_100_metadata_rb - file "data_bags/x/y.json", {} - file "environments/x.json", {} - file "nodes/x.json", {} - file "roles/x.json", {} - # file "users/x.json", {} - file "containers/x.json", {} - file "groups/x.json", {} - file "containers/x.json", {} - file "groups/x.json", {} - file "policies/x-111.json", {} - file "policy_groups/x.json", {} - end - - context "GET /TYPE" do - it "knife list -z -R returns everything" do - knife("list -z -Rfp /").should_succeed <<~EOM - /acls/ - /acls/clients/ - /acls/clients/x.json - /acls/containers/ - /acls/containers/x.json - /acls/cookbook_artifacts/ - /acls/cookbook_artifacts/x.json - /acls/cookbooks/ - /acls/cookbooks/x.json - /acls/data_bags/ - /acls/data_bags/x.json - /acls/environments/ - /acls/environments/x.json - /acls/groups/ - /acls/groups/x.json - /acls/nodes/ - /acls/nodes/x.json - /acls/organization.json - /acls/policies/ - /acls/policies/x.json - /acls/policy_groups/ - /acls/policy_groups/x.json - /acls/roles/ - /acls/roles/x.json - /clients/ - /clients/x.json - /containers/ - /containers/x.json - /cookbook_artifacts/ - /cookbook_artifacts/x-111/ - /cookbook_artifacts/x-111/metadata.rb - /cookbooks/ - /cookbooks/x/ - /cookbooks/x/metadata.rb - /data_bags/ - /data_bags/x/ - /data_bags/x/y.json - /environments/ - /environments/x.json - /groups/ - /groups/x.json - /invitations.json - /members.json - /nodes/ - /nodes/x.json - /org.json - /policies/ - /policies/x-111.json - /policy_groups/ - /policy_groups/x.json - /roles/ - /roles/x.json - EOM - end - end - - context "DELETE /TYPE/NAME" do - it "knife delete -z /clients/x.json works" do - knife("delete -z /clients/x.json").should_succeed "Deleted /clients/x.json\n" - knife("list -z -Rfp /clients").should_succeed "" - end - - it "knife delete -z -r /cookbooks/x works" do - knife("delete -z -r /cookbooks/x").should_succeed "Deleted /cookbooks/x\n" - knife("list -z -Rfp /cookbooks").should_succeed "" - end - - it "knife delete -z -r /data_bags/x works" do - knife("delete -z -r /data_bags/x").should_succeed "Deleted /data_bags/x\n" - knife("list -z -Rfp /data_bags").should_succeed "" - end - - it "knife delete -z /data_bags/x/y.json works" do - knife("delete -z /data_bags/x/y.json").should_succeed "Deleted /data_bags/x/y.json\n" - knife("list -z -Rfp /data_bags").should_succeed "/data_bags/x/\n" - end - - it "knife delete -z /environments/x.json works" do - knife("delete -z /environments/x.json").should_succeed "Deleted /environments/x.json\n" - knife("list -z -Rfp /environments").should_succeed "" - end - - it "knife delete -z /nodes/x.json works" do - knife("delete -z /nodes/x.json").should_succeed "Deleted /nodes/x.json\n" - knife("list -z -Rfp /nodes").should_succeed "" - end - - it "knife delete -z /roles/x.json works" do - knife("delete -z /roles/x.json").should_succeed "Deleted /roles/x.json\n" - knife("list -z -Rfp /roles").should_succeed "" - end - - end - - context "GET /TYPE/NAME" do - it "knife show -z /clients/x.json works" do - knife("show -z /clients/x.json").should_succeed( /"x"/ ) - end - - it "knife show -z /cookbooks/x/metadata.rb works" do - knife("show -z /cookbooks/x/metadata.rb").should_succeed "/cookbooks/x/metadata.rb:\n#{cookbook_x_100_metadata_rb}\n" - end - - it "knife show -z /data_bags/x/y.json works" do - knife("show -z /data_bags/x/y.json").should_succeed( /"y"/ ) - end - - it "knife show -z /environments/x.json works" do - knife("show -z /environments/x.json").should_succeed( /"x"/ ) - end - - it "knife show -z /nodes/x.json works" do - knife("show -z /nodes/x.json").should_succeed( /"x"/ ) - end - - it "knife show -z /roles/x.json works" do - knife("show -z /roles/x.json").should_succeed( /"x"/ ) - end - - end - - context "PUT /TYPE/NAME" do - before do - file "empty.json", {} - file "dummynode.json", { "name" => "x", "chef_environment" => "rspec" , "json_class" => "Chef::Node", "normal" => { "foo" => "bar" } } - file "rolestuff.json", '{"description":"hi there","name":"x"}' - file "cookbooks_to_upload/x/metadata.rb", cookbook_x_100_metadata_rb - end - - it "knife raw -z -i empty.json -m PUT /clients/x" do - knife("raw -z -i #{path_to("empty.json")} -m PUT /clients/x").should_succeed( /"x"/ ) - knife("list --local /clients").should_succeed "/clients/x.json\n" - end - - it "knife cookbook upload works" do - knife("cookbook upload -z --cookbook-path #{path_to("cookbooks_to_upload")} x").should_succeed stderr: <<~EOM - Uploading x [1.0.0] - Uploaded 1 cookbook. - EOM - knife("list --local -Rfp /cookbooks").should_succeed "/cookbooks/x/\n/cookbooks/x/metadata.json\n/cookbooks/x/metadata.rb\n" - end - - it "knife raw -z -i empty.json -m PUT /data/x/y" do - knife("raw -z -i #{path_to("empty.json")} -m PUT /data/x/y").should_succeed( /"y"/ ) - knife("list --local -Rfp /data_bags").should_succeed "/data_bags/x/\n/data_bags/x/y.json\n" - end - - it "knife raw -z -i empty.json -m PUT /environments/x" do - knife("raw -z -i #{path_to("empty.json")} -m PUT /environments/x").should_succeed( /"x"/ ) - knife("list --local /environments").should_succeed "/environments/x.json\n" - end - - it "knife raw -z -i dummynode.json -m PUT /nodes/x" do - knife("raw -z -i #{path_to("dummynode.json")} -m PUT /nodes/x").should_succeed( /"x"/ ) - knife("list --local /nodes").should_succeed "/nodes/x.json\n" - knife("show -z /nodes/x.json --verbose").should_succeed(/"bar"/) - end - - it "knife raw -z -i empty.json -m PUT /roles/x" do - knife("raw -z -i #{path_to("empty.json")} -m PUT /roles/x").should_succeed( /"x"/ ) - knife("list --local /roles").should_succeed "/roles/x.json\n" - end - - it "After knife raw -z -i rolestuff.json -m PUT /roles/x, the output is pretty" do - knife("raw -z -i #{path_to("rolestuff.json")} -m PUT /roles/x").should_succeed( /"x"/ ) - expect(IO.read(path_to("roles/x.json"))).to eq <<~EOM.strip - { - "name": "x", - "description": "hi there" - } - EOM - end - end - end - - when_the_repository "is empty" do - context "POST /TYPE/NAME" do - before do - file "empty.json", { "name" => "z" } - file "dummynode.json", { "name" => "z", "chef_environment" => "rspec" , "json_class" => "Chef::Node", "normal" => { "foo" => "bar" } } - file "empty_x.json", { "name" => "x" } - file "empty_id.json", { "id" => "z" } - file "rolestuff.json", '{"description":"hi there","name":"x"}' - file "cookbooks_to_upload/z/metadata.rb", cookbook_z_100_metadata_rb - end - - it "knife raw -z -i empty.json -m POST /clients" do - knife("raw -z -i #{path_to("empty.json")} -m POST /clients").should_succeed( /uri/ ) - knife("list --local /clients").should_succeed "/clients/z.json\n" - end - - it "knife cookbook upload works" do - knife("cookbook upload -z --cookbook-path #{path_to("cookbooks_to_upload")} z").should_succeed stderr: <<~EOM - Uploading z [1.0.0] - Uploaded 1 cookbook. - EOM - knife("list --local -Rfp /cookbooks").should_succeed "/cookbooks/z/\n/cookbooks/z/metadata.json\n/cookbooks/z/metadata.rb\n" - end - - it "knife raw -z -i empty.json -m POST /data" do - knife("raw -z -i #{path_to("empty.json")} -m POST /data").should_succeed( /uri/ ) - knife("list --local -Rfp /data_bags").should_succeed "/data_bags/z/\n" - end - - it "knife raw -z -i empty.json -m POST /data/x" do - knife("raw -z -i #{path_to("empty_x.json")} -m POST /data").should_succeed( /uri/ ) - knife("raw -z -i #{path_to("empty_id.json")} -m POST /data/x").should_succeed( /"z"/ ) - knife("list --local -Rfp /data_bags").should_succeed "/data_bags/x/\n/data_bags/x/z.json\n" - end - - it "knife raw -z -i empty.json -m POST /environments" do - knife("raw -z -i #{path_to("empty.json")} -m POST /environments").should_succeed( /uri/ ) - knife("list --local /environments").should_succeed "/environments/z.json\n" - end - - it "knife raw -z -i dummynode.json -m POST /nodes" do - knife("raw -z -i #{path_to("dummynode.json")} -m POST /nodes").should_succeed( /uri/ ) - knife("list --local /nodes").should_succeed "/nodes/z.json\n" - knife("show -z /nodes/z.json").should_succeed(/"bar"/) - end - - it "knife raw -z -i empty.json -m POST /roles" do - knife("raw -z -i #{path_to("empty.json")} -m POST /roles").should_succeed( /uri/ ) - knife("list --local /roles").should_succeed "/roles/z.json\n" - end - - it "After knife raw -z -i rolestuff.json -m POST /roles, the output is pretty" do - knife("raw -z -i #{path_to("rolestuff.json")} -m POST /roles").should_succeed( /uri/ ) - expect(IO.read(path_to("roles/x.json"))).to eq <<~EOM.strip - { - "name": "x", - "description": "hi there" - } - EOM - end - end - - it "knife list -z -R returns nothing" do - knife("list -z -Rfp /").should_succeed <<~EOM - /acls/ - /acls/clients/ - /acls/containers/ - /acls/cookbook_artifacts/ - /acls/cookbooks/ - /acls/data_bags/ - /acls/environments/ - /acls/groups/ - /acls/nodes/ - /acls/organization.json - /acls/policies/ - /acls/policy_groups/ - /acls/roles/ - /clients/ - /containers/ - /cookbook_artifacts/ - /cookbooks/ - /data_bags/ - /environments/ - /groups/ - /invitations.json - /members.json - /nodes/ - /org.json - /policies/ - /policy_groups/ - /roles/ - EOM - end - - context "DELETE /TYPE/NAME" do - it "knife delete -z /clients/x.json fails with an error" do - knife("delete -z /clients/x.json").should_fail "ERROR: /clients/x.json: No such file or directory\n" - end - - it "knife delete -z -r /cookbooks/x fails with an error" do - knife("delete -z -r /cookbooks/x").should_fail "ERROR: /cookbooks/x: No such file or directory\n" - end - - it "knife delete -z -r /data_bags/x fails with an error" do - knife("delete -z -r /data_bags/x").should_fail "ERROR: /data_bags/x: No such file or directory\n" - end - - it "knife delete -z /data_bags/x/y.json fails with an error" do - knife("delete -z /data_bags/x/y.json").should_fail "ERROR: /data_bags/x/y.json: No such file or directory\n" - end - - it "knife delete -z /environments/x.json fails with an error" do - knife("delete -z /environments/x.json").should_fail "ERROR: /environments/x.json: No such file or directory\n" - end - - it "knife delete -z /nodes/x.json fails with an error" do - knife("delete -z /nodes/x.json").should_fail "ERROR: /nodes/x.json: No such file or directory\n" - end - - it "knife delete -z /roles/x.json fails with an error" do - knife("delete -z /roles/x.json").should_fail "ERROR: /roles/x.json: No such file or directory\n" - end - - end - - context "GET /TYPE/NAME" do - it "knife show -z /clients/x.json fails with an error" do - knife("show -z /clients/x.json").should_fail "ERROR: /clients/x.json: No such file or directory\n" - end - - it "knife show -z /cookbooks/x/metadata.rb fails with an error" do - knife("show -z /cookbooks/x/metadata.rb").should_fail "ERROR: /cookbooks/x/metadata.rb: No such file or directory\n" - end - - it "knife show -z /data_bags/x/y.json fails with an error" do - knife("show -z /data_bags/x/y.json").should_fail "ERROR: /data_bags/x/y.json: No such file or directory\n" - end - - it "knife show -z /environments/x.json fails with an error" do - knife("show -z /environments/x.json").should_fail "ERROR: /environments/x.json: No such file or directory\n" - end - - it "knife show -z /nodes/x.json fails with an error" do - knife("show -z /nodes/x.json").should_fail "ERROR: /nodes/x.json: No such file or directory\n" - end - - it "knife show -z /roles/x.json fails with an error" do - knife("show -z /roles/x.json").should_fail "ERROR: /roles/x.json: No such file or directory\n" - end - - end - - context "PUT /TYPE/NAME" do - before do - file "empty.json", {} - end - - it "knife raw -z -i empty.json -m PUT /clients/x fails with 404" do - knife("raw -z -i #{path_to("empty.json")} -m PUT /clients/x").should_fail( /404/ ) - end - - it "knife raw -z -i empty.json -m PUT /data/x/y fails with 404" do - knife("raw -z -i #{path_to("empty.json")} -m PUT /data/x/y").should_fail( /404/ ) - end - - it "knife raw -z -i empty.json -m PUT /environments/x fails with 404" do - knife("raw -z -i #{path_to("empty.json")} -m PUT /environments/x").should_fail( /404/ ) - end - - it "knife raw -z -i empty.json -m PUT /nodes/x fails with 404" do - knife("raw -z -i #{path_to("empty.json")} -m PUT /nodes/x").should_fail( /404/ ) - end - - it "knife raw -z -i empty.json -m PUT /roles/x fails with 404" do - knife("raw -z -i #{path_to("empty.json")} -m PUT /roles/x").should_fail( /404/ ) - end - - end - end - end - - # We have to configure Zero for Chef 11 mode in order to test users because: - # 1. local mode overrides your `chef_server_url` to something like "http://localhost:PORT" - # 2. single org mode maps requests like "https://localhost:PORT/users" so - # they're functionally equivalent to "https://localhost:PORT/organizations/DEFAULT/users" - # 3. Users are global objects in Chef 12, and should be accessed at URLs like - # "https://localhost:PORT/users" (there is an org-specific users endpoint, - # but it's for listing users in an org, not for managing users). - # 4. Therefore you can't hit the _real_ users endpoint in local mode when - # configured for Chef Server 12 mode. - # - # Because of this, we have to configure Zero for Chef 11 OSC mode in order to - # test the users part of the data store with local mode. - describe "with repo mode 'everything'" do - before do - Chef::Config.repo_mode = "everything" - Chef::Config.chef_zero.osc_compat = true - end - - when_the_repository "has one of each thing" do - before do - file "clients/x.json", {} - file "cookbooks/x/metadata.rb", cookbook_x_100_metadata_rb - file "data_bags/x/y.json", {} - file "environments/x.json", {} - file "nodes/x.json", {} - file "roles/x.json", {} - file "users/x.json", {} - end - - context "GET /TYPE" do - it "knife list -z -R returns everything" do - knife("list -z -Rfp /").should_succeed <<~EOM - /clients/ - /clients/x.json - /cookbooks/ - /cookbooks/x/ - /cookbooks/x/metadata.rb - /data_bags/ - /data_bags/x/ - /data_bags/x/y.json - /environments/ - /environments/x.json - /nodes/ - /nodes/x.json - /roles/ - /roles/x.json - /users/ - /users/x.json - EOM - end - end - - context "DELETE /TYPE/NAME" do - it "knife delete -z /users/x.json works" do - knife("delete -z /users/x.json").should_succeed "Deleted /users/x.json\n" - knife("list -z -Rfp /users").should_succeed "" - end - end - - context "GET /TYPE/NAME" do - it "knife show -z /users/x.json works" do - knife("show -z /users/x.json").should_succeed( /"x"/ ) - end - end - - context "PUT /TYPE/NAME" do - before do - file "empty.json", {} - file "dummynode.json", { "name" => "x", "chef_environment" => "rspec" , "json_class" => "Chef::Node", "normal" => { "foo" => "bar" } } - file "rolestuff.json", '{"description":"hi there","name":"x"}' - file "cookbooks_to_upload/x/metadata.rb", cookbook_x_100_metadata_rb - end - - it "knife raw -z -i empty.json -m PUT /users/x" do - knife("raw -z -i #{path_to("empty.json")} -m PUT /users/x").should_succeed( /"x"/ ) - knife("list --local /users").should_succeed "/users/x.json\n" - end - - it "After knife raw -z -i rolestuff.json -m PUT /roles/x, the output is pretty" do - knife("raw -z -i #{path_to("rolestuff.json")} -m PUT /roles/x").should_succeed( /"x"/ ) - expect(IO.read(path_to("roles/x.json"))).to eq <<~EOM.strip - { - "name": "x", - "description": "hi there" - } - EOM - end - end - end - - when_the_repository "is empty" do - context "POST /TYPE/NAME" do - before do - file "empty.json", { "name" => "z" } - file "dummynode.json", { "name" => "z", "chef_environment" => "rspec" , "json_class" => "Chef::Node", "normal" => { "foo" => "bar" } } - file "empty_x.json", { "name" => "x" } - file "empty_id.json", { "id" => "z" } - file "rolestuff.json", '{"description":"hi there","name":"x"}' - file "cookbooks_to_upload/z/metadata.rb", cookbook_z_100_metadata_rb - end - - it "knife raw -z -i empty.json -m POST /users" do - knife("raw -z -i #{path_to("empty.json")} -m POST /users").should_succeed( /uri/ ) - knife("list --local /users").should_succeed "/users/z.json\n" - end - end - - it "knife list -z -R returns nothing" do - knife("list -z -Rfp /").should_succeed <<~EOM - /clients/ - /cookbooks/ - /data_bags/ - /environments/ - /nodes/ - /roles/ - /users/ - EOM - end - - context "DELETE /TYPE/NAME" do - it "knife delete -z /users/x.json fails with an error" do - knife("delete -z /users/x.json").should_fail "ERROR: /users/x.json: No such file or directory\n" - end - end - - context "GET /TYPE/NAME" do - it "knife show -z /users/x.json fails with an error" do - knife("show -z /users/x.json").should_fail "ERROR: /users/x.json: No such file or directory\n" - end - end - - context "PUT /TYPE/NAME" do - before do - file "empty.json", {} - end - - it "knife raw -z -i empty.json -m PUT /users/x fails with 404" do - knife("raw -z -i #{path_to("empty.json")} -m PUT /users/x").should_fail( /404/ ) - end - end - end - end -end diff --git a/spec/integration/knife/chef_repo_path_spec.rb b/spec/integration/knife/chef_repo_path_spec.rb deleted file mode 100644 index 27b45ac428..0000000000 --- a/spec/integration/knife/chef_repo_path_spec.rb +++ /dev/null @@ -1,962 +0,0 @@ -# -# Author:: John Keiser (<jkeiser@chef.io>) -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" -require "chef/knife/list" -require "chef/knife/show" - -describe "chef_repo_path tests", :workstation do - include IntegrationSupport - include KnifeSupport - - let(:error_rel_path_outside_repo) { /^ERROR: Attempt to use relative path '' when current directory is outside the repository path/ } - - # TODO alternate repo_path / *_path - context "alternate *_path" do - when_the_repository "has clients and clients2, cookbooks and cookbooks2, etc." do - before do - file "clients/client1.json", {} - file "cookbooks/cookbook1/metadata.rb", "" - file "data_bags/bag/item.json", {} - file "environments/env1.json", {} - file "nodes/node1.json", {} - file "roles/role1.json", {} - file "users/user1.json", {} - - file "clients2/client2.json", {} - file "cookbooks2/cookbook2/metadata.rb", "" - file "data_bags2/bag2/item2.json", {} - file "environments2/env2.json", {} - file "nodes2/node2.json", {} - file "roles2/role2.json", {} - file "users2/user2.json", {} - - directory "chef_repo2" do - file "clients/client3.json", {} - file "cookbooks/cookbook3/metadata.rb", "name 'cookbook3'" - file "data_bags/bag3/item3.json", {} - file "environments/env3.json", {} - file "nodes/node3.json", {} - file "roles/role3.json", {} - file "users/user3.json", {} - end - end - - it "knife list --local -Rfp --chef-repo-path chef_repo2 / grabs chef_repo2 stuff" do - Chef::Config.delete(:chef_repo_path) - knife("list --local -Rfp --chef-repo-path #{path_to("chef_repo2")} /").should_succeed <<~EOM - /clients/ - /clients/client3.json - /cookbooks/ - /cookbooks/cookbook3/ - /cookbooks/cookbook3/metadata.rb - /data_bags/ - /data_bags/bag3/ - /data_bags/bag3/item3.json - /environments/ - /environments/env3.json - /nodes/ - /nodes/node3.json - /roles/ - /roles/role3.json - /users/ - /users/user3.json - EOM - end - - # "Skipping for BK... As Windows 2019 has 8dot3name disabled by default" - it "knife list --local -Rfp --chef-repo-path chef_r~1 / grabs chef_repo2 stuff", :windows_only, :skip_buildkite do - Chef::Config.delete(:chef_repo_path) - knife("list --local -Rfp --chef-repo-path #{path_to("chef_r~1")} /").should_succeed <<~EOM - /clients/ - /clients/client3.json - /cookbooks/ - /cookbooks/cookbook3/ - /cookbooks/cookbook3/metadata.rb - /data_bags/ - /data_bags/bag3/ - /data_bags/bag3/item3.json - /environments/ - /environments/env3.json - /nodes/ - /nodes/node3.json - /roles/ - /roles/role3.json - /users/ - /users/user3.json - EOM - end - - # "Skipping for BK... As Windows 2019 has 8dot3name disabled by default" - it "knife list --local -Rfp --chef-repo-path chef_r~1 / grabs chef_repo2 stuff", :windows_only, :skip_buildkite do - Chef::Config.delete(:chef_repo_path) - knife("list -z -Rfp --chef-repo-path #{path_to("chef_r~1")} /").should_succeed <<~EOM - /acls/ - /acls/clients/ - /acls/clients/client3.json - /acls/containers/ - /acls/cookbook_artifacts/ - /acls/cookbooks/ - /acls/cookbooks/cookbook3.json - /acls/data_bags/ - /acls/data_bags/bag3.json - /acls/environments/ - /acls/environments/env3.json - /acls/groups/ - /acls/nodes/ - /acls/nodes/node3.json - /acls/organization.json - /acls/policies/ - /acls/policy_groups/ - /acls/roles/ - /acls/roles/role3.json - /clients/ - /clients/client3.json - /containers/ - /cookbook_artifacts/ - /cookbooks/ - /cookbooks/cookbook3/ - /cookbooks/cookbook3/metadata.rb - /data_bags/ - /data_bags/bag3/ - /data_bags/bag3/item3.json - /environments/ - /environments/env3.json - /groups/ - /invitations.json - /members.json - /nodes/ - /nodes/node3.json - /org.json - /policies/ - /policy_groups/ - /roles/ - /roles/role3.json - EOM - end - - context "when all _paths are set to alternates" do - before :each do - %w{client cookbook data_bag environment node role user}.each do |object_name| - Chef::Config["#{object_name}_path".to_sym] = File.join(Chef::Config.chef_repo_path, "#{object_name}s2") - end - Chef::Config.chef_repo_path = File.join(Chef::Config.chef_repo_path, "chef_repo2") - end - - it "knife list --local -Rfp --chef-repo-path chef_repo2 / grabs chef_repo2 stuff" do - knife("list --local -Rfp --chef-repo-path #{path_to("chef_repo2")} /").should_succeed <<~EOM - /clients/ - /clients/client3.json - /cookbooks/ - /cookbooks/cookbook3/ - /cookbooks/cookbook3/metadata.rb - /data_bags/ - /data_bags/bag3/ - /data_bags/bag3/item3.json - /environments/ - /environments/env3.json - /nodes/ - /nodes/node3.json - /roles/ - /roles/role3.json - /users/ - /users/user3.json - EOM - end - - context "when cwd is at the top level" do - before { cwd "." } - it "knife list --local -Rfp fails" do - knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) - end - end - - context "when cwd is inside the data_bags directory" do - before { cwd "data_bags" } - it "knife list --local -Rfp fails" do - knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) - end - end - - context "when cwd is inside chef_repo2" do - before { cwd "chef_repo2" } - it "knife list --local -Rfp lists everything" do - knife("list --local -Rfp").should_succeed <<~EOM - clients/ - clients/client2.json - cookbooks/ - cookbooks/cookbook2/ - cookbooks/cookbook2/metadata.rb - data_bags/ - data_bags/bag2/ - data_bags/bag2/item2.json - environments/ - environments/env2.json - nodes/ - nodes/node2.json - roles/ - roles/role2.json - users/ - users/user2.json - EOM - end - end - - context "when cwd is inside data_bags2" do - before { cwd "data_bags2" } - it "knife list --local -Rfp lists data bags" do - knife("list --local -Rfp").should_succeed <<~EOM - bag2/ - bag2/item2.json - EOM - end - it "knife list --local -Rfp ../roles lists roles" do - knife("list --local -Rfp ../roles").should_succeed "/roles/role2.json\n" - end - end - end - - context "when all _paths except chef_repo_path are set to alternates" do - before :each do - %w{client cookbook data_bag environment node role user}.each do |object_name| - Chef::Config["#{object_name}_path".to_sym] = File.join(Chef::Config.chef_repo_path, "#{object_name}s2") - end - end - - context "when cwd is at the top level" do - before { cwd "." } - it "knife list --local -Rfp lists everything" do - knife("list --local -Rfp").should_succeed <<~EOM - clients/ - clients/client2.json - cookbooks/ - cookbooks/cookbook2/ - cookbooks/cookbook2/metadata.rb - data_bags/ - data_bags/bag2/ - data_bags/bag2/item2.json - environments/ - environments/env2.json - nodes/ - nodes/node2.json - roles/ - roles/role2.json - users/ - users/user2.json - EOM - end - end - - context "when cwd is inside the data_bags directory" do - before { cwd "data_bags" } - it "knife list --local -Rfp fails" do - knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) - end - end - - context "when cwd is inside chef_repo2" do - before { cwd "chef_repo2" } - it "knife list -Rfp fails" do - knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) - end - end - - context "when cwd is inside data_bags2" do - before { cwd "data_bags2" } - it "knife list --local -Rfp lists data bags" do - knife("list --local -Rfp").should_succeed <<~EOM - bag2/ - bag2/item2.json - EOM - end - end - end - - context "when only chef_repo_path is set to its alternate" do - before :each do - %w{client cookbook data_bag environment node role user}.each do |object_name| - Chef::Config.delete("#{object_name}_path".to_sym) - end - Chef::Config.chef_repo_path = File.join(Chef::Config.chef_repo_path, "chef_repo2") - end - - context "when cwd is at the top level" do - before { cwd "." } - it "knife list --local -Rfp fails" do - knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) - end - end - - context "when cwd is inside the data_bags directory" do - before { cwd "data_bags" } - it "knife list --local -Rfp fails" do - knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) - end - end - - context "when cwd is inside chef_repo2" do - before { cwd "chef_repo2" } - it "knife list --local -Rfp lists everything" do - knife("list --local -Rfp").should_succeed <<~EOM - clients/ - clients/client3.json - cookbooks/ - cookbooks/cookbook3/ - cookbooks/cookbook3/metadata.rb - data_bags/ - data_bags/bag3/ - data_bags/bag3/item3.json - environments/ - environments/env3.json - nodes/ - nodes/node3.json - roles/ - roles/role3.json - users/ - users/user3.json - EOM - end - end - - context "when cwd is inside chef_repo2/data_bags" do - before { cwd "chef_repo2/data_bags" } - it "knife list --local -Rfp lists data bags" do - knife("list --local -Rfp").should_succeed <<~EOM - bag3/ - bag3/item3.json - EOM - end - end - end - - context "when paths are set to point to both versions of each" do - before :each do - %w{client cookbook data_bag environment node role user}.each do |object_name| - Chef::Config["#{object_name}_path".to_sym] = [ - File.join(Chef::Config.chef_repo_path, "#{object_name}s"), - File.join(Chef::Config.chef_repo_path, "#{object_name}s2"), - ] - end - Chef::Config.chef_repo_path = File.join(Chef::Config.chef_repo_path, "chef_repo2") - end - - context "when there is a directory in clients1 and file in clients2 with the same name" do - before do - directory "clients/blah.json" - file "clients2/blah.json", {} - end - it "knife show /clients/blah.json succeeds" do - knife("show --local /clients/blah.json").should_succeed <<~EOM - /clients/blah.json: - { - - } - EOM - end - end - - context "when there is a file in cookbooks1 and directory in cookbooks2 with the same name" do - before do - file "cookbooks/blah", "" - file "cookbooks2/blah/metadata.rb", "" - end - it "knife list -Rfp cookbooks shows files in blah" do - knife("list --local -Rfp /cookbooks").should_succeed <<~EOM - /cookbooks/blah/ - /cookbooks/blah/metadata.rb - /cookbooks/cookbook1/ - /cookbooks/cookbook1/metadata.rb - /cookbooks/cookbook2/ - /cookbooks/cookbook2/metadata.rb - EOM - end - end - - context "when there is an empty directory in cookbooks1 and a real cookbook in cookbooks2 with the same name" do - before do - directory "cookbooks/blah" - file "cookbooks2/blah/metadata.rb", "" - end - it "knife list -Rfp cookbooks shows files in blah" do - knife("list --local -Rfp /cookbooks").should_succeed(<<~EOM, stderr: "WARN: Cookbook 'blah' is empty or entirely chefignored at #{Chef::Config.cookbook_path[0]}/blah\n") - /cookbooks/blah/ - /cookbooks/blah/metadata.rb - /cookbooks/cookbook1/ - /cookbooks/cookbook1/metadata.rb - /cookbooks/cookbook2/ - /cookbooks/cookbook2/metadata.rb - EOM - end - end - - context "when there is a cookbook in cookbooks1 and a cookbook in cookbooks2 with the same name" do - before do - file "cookbooks/blah/metadata.json", {} - file "cookbooks2/blah/metadata.rb", "" - end - it "knife list -Rfp cookbooks shows files in the first cookbook and not the second" do - knife("list --local -Rfp /cookbooks").should_succeed(<<~EOM, stderr: "WARN: Child with name 'blah' found in multiple directories: #{Chef::Config.cookbook_path[0]}/blah and #{Chef::Config.cookbook_path[1]}/blah\n") - /cookbooks/blah/ - /cookbooks/blah/metadata.json - /cookbooks/cookbook1/ - /cookbooks/cookbook1/metadata.rb - /cookbooks/cookbook2/ - /cookbooks/cookbook2/metadata.rb - EOM - end - end - - context "when there is a file in data_bags1 and a directory in data_bags2 with the same name" do - before do - file "data_bags/blah", "" - file "data_bags2/blah/item.json", "" - end - it "knife list -Rfp data_bags shows files in blah" do - knife("list --local -Rfp /data_bags").should_succeed <<~EOM - /data_bags/bag/ - /data_bags/bag/item.json - /data_bags/bag2/ - /data_bags/bag2/item2.json - /data_bags/blah/ - /data_bags/blah/item.json - EOM - end - end - - context "when there is a data bag in data_bags1 and a data bag in data_bags2 with the same name" do - before do - file "data_bags/blah/item1.json", "" - file "data_bags2/blah/item2.json", "" - end - it "knife list -Rfp data_bags shows only items in data_bags1" do - knife("list --local -Rfp /data_bags").should_succeed(<<~EOM, stderr: "WARN: Child with name 'blah' found in multiple directories: #{Chef::Config.data_bag_path[0]}/blah and #{Chef::Config.data_bag_path[1]}/blah\n") - /data_bags/bag/ - /data_bags/bag/item.json - /data_bags/bag2/ - /data_bags/bag2/item2.json - /data_bags/blah/ - /data_bags/blah/item1.json - EOM - end - end - - context "when there is a directory in environments1 and file in environments2 with the same name" do - before do - directory "environments/blah.json" - file "environments2/blah.json", {} - end - it "knife show /environments/blah.json succeeds" do - knife("show --local /environments/blah.json").should_succeed <<~EOM - /environments/blah.json: - { - - } - EOM - end - end - - context "when there is a directory in nodes1 and file in nodes2 with the same name" do - before do - directory "nodes/blah.json" - file "nodes2/blah.json", {} - end - it "knife show /nodes/blah.json succeeds" do - knife("show --local /nodes/blah.json").should_succeed <<~EOM - /nodes/blah.json: - { - - } - EOM - end - end - - context "when there is a directory in roles1 and file in roles2 with the same name" do - before do - directory "roles/blah.json" - file "roles2/blah.json", {} - end - it "knife show /roles/blah.json succeeds" do - knife("show --local /roles/blah.json").should_succeed <<~EOM - /roles/blah.json: - { - - } - EOM - end - end - - context "when there is a directory in users1 and file in users2 with the same name" do - before do - directory "users/blah.json" - file "users2/blah.json", {} - end - it "knife show /users/blah.json succeeds" do - knife("show --local /users/blah.json").should_succeed <<~EOM - /users/blah.json: - { - - } - EOM - end - end - - context "when cwd is at the top level" do - before { cwd "." } - it "knife list --local -Rfp fails" do - knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) - end - end - - context "when cwd is inside the data_bags directory" do - before { cwd "data_bags" } - it "knife list --local -Rfp lists data bags" do - knife("list --local -Rfp").should_succeed <<~EOM - bag/ - bag/item.json - bag2/ - bag2/item2.json - EOM - end - end - - context "when cwd is inside chef_repo2" do - before { cwd "chef_repo2" } - it "knife list --local -Rfp lists everything" do - knife("list --local -Rfp").should_succeed <<~EOM - clients/ - clients/client1.json - clients/client2.json - cookbooks/ - cookbooks/cookbook1/ - cookbooks/cookbook1/metadata.rb - cookbooks/cookbook2/ - cookbooks/cookbook2/metadata.rb - data_bags/ - data_bags/bag/ - data_bags/bag/item.json - data_bags/bag2/ - data_bags/bag2/item2.json - environments/ - environments/env1.json - environments/env2.json - nodes/ - nodes/node1.json - nodes/node2.json - roles/ - roles/role1.json - roles/role2.json - users/ - users/user1.json - users/user2.json - EOM - end - end - - context "when cwd is inside data_bags2" do - before { cwd "data_bags2" } - it "knife list --local -Rfp lists data bags" do - knife("list --local -Rfp").should_succeed <<~EOM - bag/ - bag/item.json - bag2/ - bag2/item2.json - EOM - end - end - end - - context "when when chef_repo_path is set to both places and no other _path is set" do - before :each do - %w{client cookbook data_bag environment node role user}.each do |object_name| - Chef::Config.delete("#{object_name}_path".to_sym) - end - Chef::Config.chef_repo_path = [ - Chef::Config.chef_repo_path, - File.join(Chef::Config.chef_repo_path, "chef_repo2"), - ] - end - - context "when cwd is at the top level" do - before { cwd "." } - it "knife list --local -Rfp lists everything" do - knife("list --local -Rfp").should_succeed <<~EOM - clients/ - clients/client1.json - clients/client3.json - cookbooks/ - cookbooks/cookbook1/ - cookbooks/cookbook1/metadata.rb - cookbooks/cookbook3/ - cookbooks/cookbook3/metadata.rb - data_bags/ - data_bags/bag/ - data_bags/bag/item.json - data_bags/bag3/ - data_bags/bag3/item3.json - environments/ - environments/env1.json - environments/env3.json - nodes/ - nodes/node1.json - nodes/node3.json - roles/ - roles/role1.json - roles/role3.json - users/ - users/user1.json - users/user3.json - EOM - end - end - - context "when cwd is inside the data_bags directory" do - before { cwd "data_bags" } - it "knife list --local -Rfp lists data bags" do - knife("list --local -Rfp").should_succeed <<~EOM - bag/ - bag/item.json - bag3/ - bag3/item3.json - EOM - end - end - - context "when cwd is inside chef_repo2" do - before { cwd "chef_repo2" } - it "knife list --local -Rfp lists everything" do - knife("list --local -Rfp").should_succeed <<~EOM - clients/ - clients/client1.json - clients/client3.json - cookbooks/ - cookbooks/cookbook1/ - cookbooks/cookbook1/metadata.rb - cookbooks/cookbook3/ - cookbooks/cookbook3/metadata.rb - data_bags/ - data_bags/bag/ - data_bags/bag/item.json - data_bags/bag3/ - data_bags/bag3/item3.json - environments/ - environments/env1.json - environments/env3.json - nodes/ - nodes/node1.json - nodes/node3.json - roles/ - roles/role1.json - roles/role3.json - users/ - users/user1.json - users/user3.json - EOM - end - end - - context "when cwd is inside chef_repo2/data_bags" do - before { cwd "chef_repo2/data_bags" } - it "knife list --local -Rfp lists data bags" do - knife("list --local -Rfp").should_succeed <<~EOM - bag/ - bag/item.json - bag3/ - bag3/item3.json - EOM - end - end - end - - context "when cookbook_path is set and nothing else" do - before :each do - %w{client data_bag environment node role user}.each do |object_name| - Chef::Config.delete("#{object_name}_path".to_sym) - end - Chef::Config.delete(:chef_repo_path) - Chef::Config.cookbook_path = File.join(@repository_dir, "chef_repo2", "cookbooks") - end - - context "when cwd is at the top level" do - before { cwd "." } - it "knife list --local -Rfp fails" do - knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) - end - end - - context "when cwd is inside the data_bags directory" do - before { cwd "data_bags" } - it "knife list --local -Rfp fails" do - knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) - end - end - - context "when cwd is inside chef_repo2" do - before { cwd "chef_repo2" } - it "knife list --local -Rfp lists everything" do - knife("list --local -Rfp").should_succeed <<~EOM - clients/ - clients/client3.json - cookbooks/ - cookbooks/cookbook3/ - cookbooks/cookbook3/metadata.rb - data_bags/ - data_bags/bag3/ - data_bags/bag3/item3.json - environments/ - environments/env3.json - nodes/ - nodes/node3.json - roles/ - roles/role3.json - users/ - users/user3.json - EOM - end - end - - context "when cwd is inside chef_repo2/data_bags" do - before { cwd "chef_repo2/data_bags" } - it "knife list --local -Rfp lists data bags" do - knife("list --local -Rfp").should_succeed <<~EOM - bag3/ - bag3/item3.json - EOM - end - end - end - - context "when cookbook_path is set to multiple places and nothing else is set" do - before :each do - %w{client data_bag environment node role user}.each do |object_name| - Chef::Config.delete("#{object_name}_path".to_sym) - end - Chef::Config.delete(:chef_repo_path) - Chef::Config.cookbook_path = [ - File.join(@repository_dir, "cookbooks"), - File.join(@repository_dir, "chef_repo2", "cookbooks"), - ] - end - - context "when cwd is at the top level" do - before { cwd "." } - it "knife list --local -Rfp lists everything" do - knife("list --local -Rfp").should_succeed <<~EOM - clients/ - clients/client1.json - clients/client3.json - cookbooks/ - cookbooks/cookbook1/ - cookbooks/cookbook1/metadata.rb - cookbooks/cookbook3/ - cookbooks/cookbook3/metadata.rb - data_bags/ - data_bags/bag/ - data_bags/bag/item.json - data_bags/bag3/ - data_bags/bag3/item3.json - environments/ - environments/env1.json - environments/env3.json - nodes/ - nodes/node1.json - nodes/node3.json - roles/ - roles/role1.json - roles/role3.json - users/ - users/user1.json - users/user3.json - EOM - end - end - - context "when cwd is inside the data_bags directory" do - before { cwd "data_bags" } - it "knife list --local -Rfp lists data bags" do - knife("list --local -Rfp").should_succeed <<~EOM - bag/ - bag/item.json - bag3/ - bag3/item3.json - EOM - end - end - - context "when cwd is inside chef_repo2" do - before { cwd "chef_repo2" } - it "knife list --local -Rfp lists everything" do - knife("list --local -Rfp").should_succeed <<~EOM - clients/ - clients/client1.json - clients/client3.json - cookbooks/ - cookbooks/cookbook1/ - cookbooks/cookbook1/metadata.rb - cookbooks/cookbook3/ - cookbooks/cookbook3/metadata.rb - data_bags/ - data_bags/bag/ - data_bags/bag/item.json - data_bags/bag3/ - data_bags/bag3/item3.json - environments/ - environments/env1.json - environments/env3.json - nodes/ - nodes/node1.json - nodes/node3.json - roles/ - roles/role1.json - roles/role3.json - users/ - users/user1.json - users/user3.json - EOM - end - end - - context "when cwd is inside chef_repo2/data_bags" do - before { cwd "chef_repo2/data_bags" } - it "knife list --local -Rfp lists data bags" do - knife("list --local -Rfp").should_succeed <<~EOM - bag/ - bag/item.json - bag3/ - bag3/item3.json - EOM - end - end - end - - context "when data_bag_path and chef_repo_path are set, and nothing else" do - before :each do - %w{client cookbook environment node role user}.each do |object_name| - Chef::Config.delete("#{object_name}_path".to_sym) - end - Chef::Config.data_bag_path = File.join(Chef::Config.chef_repo_path, "data_bags") - Chef::Config.chef_repo_path = File.join(Chef::Config.chef_repo_path, "chef_repo2") - end - - context "when cwd is at the top level" do - before { cwd "." } - it "knife list --local -Rfp fails" do - knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) - end - end - - context "when cwd is inside the data_bags directory" do - before { cwd "data_bags" } - it "knife list --local -Rfp lists data bags" do - knife("list --local -Rfp").should_succeed <<~EOM - bag/ - bag/item.json - EOM - end - end - - context "when cwd is inside chef_repo2" do - before { cwd "chef_repo2" } - it "knife list --local -Rfp lists everything" do - knife("list --local -Rfp").should_succeed <<~EOM - clients/ - clients/client3.json - cookbooks/ - cookbooks/cookbook3/ - cookbooks/cookbook3/metadata.rb - data_bags/ - data_bags/bag/ - data_bags/bag/item.json - environments/ - environments/env3.json - nodes/ - nodes/node3.json - roles/ - roles/role3.json - users/ - users/user3.json - EOM - end - end - - context "when cwd is inside chef_repo2/data_bags" do - before { cwd "chef_repo2/data_bags" } - it "knife list --local -Rfp fails" do - knife("list --local -Rfp").should_fail(error_rel_path_outside_repo) - end - end - end - - context "when data_bag_path is set and nothing else" do - include_context "default config options" - - before :each do - %w{client cookbook environment node role user}.each do |object_name| - Chef::Config.delete("#{object_name}_path".to_sym) - end - Chef::Config.delete(:chef_repo_path) - Chef::Config.data_bag_path = File.join(@repository_dir, "data_bags") - end - - it "knife list --local -Rfp / lists data bags" do - knife("list --local -Rfp /").should_succeed <<~EOM - /data_bags/ - /data_bags/bag/ - /data_bags/bag/item.json - EOM - end - - it "knife list --local -Rfp /data_bags lists data bags" do - knife("list --local -Rfp /data_bags").should_succeed <<~EOM - /data_bags/bag/ - /data_bags/bag/item.json - EOM - end - - context "when cwd is inside the data_bags directory" do - before { cwd "data_bags" } - it "knife list --local -Rfp lists data bags" do - knife("list --local -Rfp").should_succeed <<~EOM - bag/ - bag/item.json - EOM - end - end - end - end - - when_the_repository "is empty" do - context "when the repository _paths point to places that do not exist" do - before :each do - %w{client cookbook data_bag environment node role user}.each do |object_name| - Chef::Config["#{object_name}_path".to_sym] = File.join(Chef::Config.chef_repo_path, "nowhere", object_name) - end - Chef::Config.chef_repo_path = File.join(Chef::Config.chef_repo_path, "nowhere") - end - - it "knife list --local -Rfp / fails" do - knife("list --local -Rfp /").should_succeed "" - end - - it "knife list --local -Rfp /data_bags fails" do - knife("list --local -Rfp /data_bags").should_fail("ERROR: /data_bags: No such file or directory\n") - end - end - end - end -end diff --git a/spec/integration/knife/chef_repository_file_system_spec.rb b/spec/integration/knife/chef_repository_file_system_spec.rb deleted file mode 100644 index 9a129dcb98..0000000000 --- a/spec/integration/knife/chef_repository_file_system_spec.rb +++ /dev/null @@ -1,200 +0,0 @@ -# -# Author:: John Keiser (<jkeiser@chef.io>) -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "chef/knife/list" -require "chef/knife/show" - -describe "General chef_repo file system checks", :workstation do - include IntegrationSupport - include KnifeSupport - - context "directories and files that should/should not be ignored" do - when_the_repository "has empty roles, environments and data bag item directories" do - before do - directory "roles" - directory "environments" - directory "data_bags/bag1" - end - - it "knife list --local -Rfp / returns them" do - knife("list --local -Rfp /").should_succeed <<~EOM - /data_bags/ - /data_bags/bag1/ - /environments/ - /roles/ - EOM - end - end - - when_the_repository "has an empty data_bags directory" do - before { directory "data_bags" } - - it "knife list --local / returns it" do - knife("list --local /").should_succeed "/data_bags\n" - end - end - - when_the_repository "has an empty cookbook directory" do - before { directory "cookbooks/cookbook1" } - - it "knife list --local -Rfp / does not return it" do - knife("list --local -Rfp /").should_succeed(<<~EOM, stderr: "WARN: Cookbook 'cookbook1' is empty or entirely chefignored at #{Chef::Config.chef_repo_path}/cookbooks/cookbook1\n") - /cookbooks/ - EOM - end - end - - when_the_repository "has only empty cookbook subdirectories" do - before { directory "cookbooks/cookbook1/recipes" } - - it "knife list --local -Rfp / does not return it" do - knife("list --local -Rfp /").should_succeed(<<~EOM, stderr: "WARN: Cookbook 'cookbook1' is empty or entirely chefignored at #{Chef::Config.chef_repo_path}/cookbooks/cookbook1\n") - /cookbooks/ - EOM - end - end - - when_the_repository "has empty and non-empty cookbook subdirectories" do - before do - directory "cookbooks/cookbook1/recipes" - file "cookbooks/cookbook1/templates/default/x.txt", "" - end - - it "knife list --local -Rfp / does not return the empty ones" do - knife("list --local -Rfp /").should_succeed <<~EOM - /cookbooks/ - /cookbooks/cookbook1/ - /cookbooks/cookbook1/templates/ - /cookbooks/cookbook1/templates/default/ - /cookbooks/cookbook1/templates/default/x.txt - EOM - end - end - - when_the_repository "has only empty cookbook sub-sub-directories" do - before { directory "cookbooks/cookbook1/templates/default" } - - it "knife list --local -Rfp / does not return it" do - knife("list --local -Rfp /").should_succeed(<<~EOM, stderr: "WARN: Cookbook 'cookbook1' is empty or entirely chefignored at #{Chef::Config.chef_repo_path}/cookbooks/cookbook1\n") - /cookbooks/ - EOM - end - end - - when_the_repository "has empty cookbook sub-sub-directories alongside non-empty ones" do - before do - file "cookbooks/cookbook1/templates/default/x.txt", "" - directory "cookbooks/cookbook1/templates/rhel" - directory "cookbooks/cookbook1/files/default" - end - - it "knife list --local -Rfp / does not return the empty ones" do - knife("list --local -Rfp /").should_succeed <<~EOM - /cookbooks/ - /cookbooks/cookbook1/ - /cookbooks/cookbook1/templates/ - /cookbooks/cookbook1/templates/default/ - /cookbooks/cookbook1/templates/default/x.txt - EOM - end - end - - when_the_repository "has an extra schmenvironments directory" do - before do - directory "schmenvironments" do - file "_default.json", {} - end - end - - it "knife list --local -Rfp / should NOT return it" do - knife("list --local -Rfp /").should_succeed "" - end - end - - when_the_repository "has extra subdirectories and files under data bag items, roles, and environments" do - before do - directory "data_bags/bag1" do - file "item1.json", {} - file "item2.xml", "" - file "another_subdir/item.json", {} - end - directory "roles" do - file "role1.json", {} - file "role2.xml", "" - file "subdir/role.json", {} - end - directory "environments" do - file "environment1.json", {} - file "environment2.xml", "" - file "subdir/environment.json", {} - end - end - - it "knife list --local -Rfp / should NOT return them" do - knife("list --local -Rfp /").should_succeed <<~EOM - /data_bags/ - /data_bags/bag1/ - /data_bags/bag1/item1.json - /environments/ - /environments/environment1.json - /roles/ - /roles/role1.json - EOM - end - end - - when_the_repository "has a file in cookbooks/" do - before { file "cookbooks/file", "" } - it "does not show up in list -Rfp" do - knife("list --local -Rfp /").should_succeed <<~EOM - /cookbooks/ - EOM - end - end - - when_the_repository "has a file in data_bags/" do - before { file "data_bags/file", "" } - it "does not show up in list -Rfp" do - knife("list --local -Rfp /").should_succeed <<~EOM - /data_bags/ - EOM - end - end - end - - when_the_repository "has a cookbook starting with ." do - before do - file "cookbooks/.svn/metadata.rb", "" - file "cookbooks/a.b/metadata.rb", "" - end - it "knife list does not show it" do - knife("list --local -fp /cookbooks").should_succeed "/cookbooks/a.b/\n" - end - end - - when_the_repository "has a data bag starting with ." do - before do - file "data_bags/.svn/x.json", {} - file "data_bags/a.b/x.json", {} - end - it "knife list does not show it" do - knife("list --local -fp /data_bags").should_succeed "/data_bags/a.b/\n" - end - end -end diff --git a/spec/integration/knife/chefignore_spec.rb b/spec/integration/knife/chefignore_spec.rb deleted file mode 100644 index f111cd56e1..0000000000 --- a/spec/integration/knife/chefignore_spec.rb +++ /dev/null @@ -1,301 +0,0 @@ -# -# Author:: John Keiser (<jkeiser@chef.io>) -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "chef/knife/list" -require "chef/knife/show" - -describe "chefignore tests", :workstation do - include IntegrationSupport - include KnifeSupport - - when_the_repository "has lots of stuff in it" do - before do - file "roles/x.json", {} - file "environments/x.json", {} - file "data_bags/bag1/x.json", {} - file "cookbooks/cookbook1/x.json", {} - end - - context "and has a chefignore everywhere except cookbooks" do - before do - chefignore = "x.json\nroles/x.json\nenvironments/x.json\ndata_bags/bag1/x.json\nbag1/x.json\ncookbooks/cookbook1/x.json\ncookbook1/x.json\n" - file "chefignore", chefignore - file "roles/chefignore", chefignore - file "environments/chefignore", chefignore - file "data_bags/chefignore", chefignore - file "data_bags/bag1/chefignore", chefignore - file "cookbooks/cookbook1/chefignore", chefignore - end - - it "matching files and directories get ignored" do - # NOTE: many of the "chefignore" files should probably not show up - # themselves, but we have other tests that talk about that - knife("list --local -Rfp /").should_succeed <<~EOM - /cookbooks/ - /cookbooks/cookbook1/ - /cookbooks/cookbook1/chefignore - /data_bags/ - /data_bags/bag1/ - /data_bags/bag1/x.json - /environments/ - /environments/x.json - /roles/ - /roles/x.json - EOM - end - end - end - - when_the_repository "has a cookbook with only chefignored files" do - before do - file "cookbooks/cookbook1/templates/default/x.rb", "" - file "cookbooks/cookbook1/libraries/x.rb", "" - file "cookbooks/chefignore", "libraries/x.rb\ntemplates/default/x.rb\n" - end - - it "the cookbook is not listed" do - knife("list --local -Rfp /").should_succeed(<<~EOM, stderr: "WARN: Cookbook 'cookbook1' is empty or entirely chefignored at #{Chef::Config.chef_repo_path}/cookbooks/cookbook1\n") - /cookbooks/ - EOM - end - end - - when_the_repository "has multiple cookbooks" do - before do - file "cookbooks/cookbook1/x.json", {} - file "cookbooks/cookbook1/y.json", {} - file "cookbooks/cookbook2/x.json", {} - file "cookbooks/cookbook2/y.json", {} - end - - context "and has a chefignore with filenames" do - before { file "cookbooks/chefignore", "x.json\n" } - - it "matching files and directories get ignored in all cookbooks" do - knife("list --local -Rfp /").should_succeed <<~EOM - /cookbooks/ - /cookbooks/cookbook1/ - /cookbooks/cookbook1/y.json - /cookbooks/cookbook2/ - /cookbooks/cookbook2/y.json - EOM - end - end - - context "and has a chefignore with wildcards" do - before do - file "cookbooks/chefignore", "x.*\n" - file "cookbooks/cookbook1/x.rb", "" - end - - it "matching files and directories get ignored in all cookbooks" do - knife("list --local -Rfp /").should_succeed <<~EOM - /cookbooks/ - /cookbooks/cookbook1/ - /cookbooks/cookbook1/y.json - /cookbooks/cookbook2/ - /cookbooks/cookbook2/y.json - EOM - end - end - - context "and has a chefignore with relative paths" do - before do - file "cookbooks/cookbook1/recipes/x.rb", "" - file "cookbooks/cookbook2/recipes/y.rb", "" - file "cookbooks/chefignore", "recipes/x.rb\n" - end - - it "matching directories get ignored" do - knife("list --local -Rfp /").should_succeed <<~EOM - /cookbooks/ - /cookbooks/cookbook1/ - /cookbooks/cookbook1/x.json - /cookbooks/cookbook1/y.json - /cookbooks/cookbook2/ - /cookbooks/cookbook2/recipes/ - /cookbooks/cookbook2/recipes/y.rb - /cookbooks/cookbook2/x.json - /cookbooks/cookbook2/y.json - EOM - end - end - - context "and has a chefignore with subdirectories" do - before do - file "cookbooks/cookbook1/recipes/y.rb", "" - file "cookbooks/chefignore", "recipes\nrecipes/\n" - end - - it "matching directories do NOT get ignored" do - knife("list --local -Rfp /").should_succeed <<~EOM - /cookbooks/ - /cookbooks/cookbook1/ - /cookbooks/cookbook1/recipes/ - /cookbooks/cookbook1/recipes/y.rb - /cookbooks/cookbook1/x.json - /cookbooks/cookbook1/y.json - /cookbooks/cookbook2/ - /cookbooks/cookbook2/x.json - /cookbooks/cookbook2/y.json - EOM - end - end - - context "and has a chefignore that ignores all files in a subdirectory" do - before do - file "cookbooks/cookbook1/templates/default/x.rb", "" - file "cookbooks/cookbook1/libraries/x.rb", "" - file "cookbooks/chefignore", "libraries/x.rb\ntemplates/default/x.rb\n" - end - - it "ignores the subdirectory entirely" do - knife("list --local -Rfp /").should_succeed <<~EOM - /cookbooks/ - /cookbooks/cookbook1/ - /cookbooks/cookbook1/x.json - /cookbooks/cookbook1/y.json - /cookbooks/cookbook2/ - /cookbooks/cookbook2/x.json - /cookbooks/cookbook2/y.json - EOM - end - end - - context "and has an empty chefignore" do - before do - file "cookbooks/chefignore", "\n" - end - - it "nothing is ignored" do - knife("list --local -Rfp /").should_succeed <<~EOM - /cookbooks/ - /cookbooks/cookbook1/ - /cookbooks/cookbook1/x.json - /cookbooks/cookbook1/y.json - /cookbooks/cookbook2/ - /cookbooks/cookbook2/x.json - /cookbooks/cookbook2/y.json - EOM - end - end - - context "and has a chefignore with comments and empty lines" do - before do - file "cookbooks/chefignore", "\n\n # blah\n#\nx.json\n\n" - end - - it "matching files and directories get ignored in all cookbooks" do - knife("list --local -Rfp /").should_succeed <<~EOM - /cookbooks/ - /cookbooks/cookbook1/ - /cookbooks/cookbook1/y.json - /cookbooks/cookbook2/ - /cookbooks/cookbook2/y.json - EOM - end - end - end - - when_the_repository "has multiple cookbook paths" do - before :each do - Chef::Config.cookbook_path = [ - File.join(Chef::Config.chef_repo_path, "cookbooks1"), - File.join(Chef::Config.chef_repo_path, "cookbooks2"), - ] - end - - before do - file "cookbooks1/mycookbook/metadata.rb", "" - file "cookbooks1/mycookbook/x.json", {} - file "cookbooks2/yourcookbook/metadata.rb", "" - file "cookbooks2/yourcookbook/x.json", "" - end - - context "and multiple chefignores" do - before do - file "cookbooks1/chefignore", "metadata.rb\n" - file "cookbooks2/chefignore", "x.json\n" - end - it "chefignores apply only to the directories they are in" do - knife("list --local -Rfp /").should_succeed <<~EOM - /cookbooks/ - /cookbooks/mycookbook/ - /cookbooks/mycookbook/x.json - /cookbooks/yourcookbook/ - /cookbooks/yourcookbook/metadata.rb - EOM - end - - context "and conflicting cookbooks" do - before do - file "cookbooks1/yourcookbook/metadata.rb", "" - file "cookbooks1/yourcookbook/x.json", "" - file "cookbooks1/yourcookbook/onlyincookbooks1.rb", "" - file "cookbooks2/yourcookbook/onlyincookbooks2.rb", "" - end - - it "chefignores apply only to the winning cookbook" do - knife("list --local -Rfp /").should_succeed(<<~EOM, stderr: "WARN: Child with name 'yourcookbook' found in multiple directories: #{Chef::Config.chef_repo_path}/cookbooks1/yourcookbook and #{Chef::Config.chef_repo_path}/cookbooks2/yourcookbook\n") - /cookbooks/ - /cookbooks/mycookbook/ - /cookbooks/mycookbook/x.json - /cookbooks/yourcookbook/ - /cookbooks/yourcookbook/onlyincookbooks1.rb - /cookbooks/yourcookbook/x.json - EOM - end - end - end - end - - when_the_repository "has a cookbook named chefignore" do - before do - file "cookbooks/chefignore/metadata.rb", {} - end - it "knife list -Rfp /cookbooks shows it" do - knife("list --local -Rfp /cookbooks").should_succeed <<~EOM - /cookbooks/chefignore/ - /cookbooks/chefignore/metadata.rb - EOM - end - end - - when_the_repository "has multiple cookbook paths, one with a chefignore file and the other with a cookbook named chefignore" do - before do - file "cookbooks1/chefignore", "" - file "cookbooks1/blah/metadata.rb", "" - file "cookbooks2/chefignore/metadata.rb", "" - end - before :each do - Chef::Config.cookbook_path = [ - File.join(Chef::Config.chef_repo_path, "cookbooks1"), - File.join(Chef::Config.chef_repo_path, "cookbooks2"), - ] - end - it "knife list -Rfp /cookbooks shows the chefignore cookbook" do - knife("list --local -Rfp /cookbooks").should_succeed <<~EOM - /cookbooks/blah/ - /cookbooks/blah/metadata.rb - /cookbooks/chefignore/ - /cookbooks/chefignore/metadata.rb - EOM - end - end -end diff --git a/spec/integration/knife/client_bulk_delete_spec.rb b/spec/integration/knife/client_bulk_delete_spec.rb deleted file mode 100644 index b7733f638d..0000000000 --- a/spec/integration/knife/client_bulk_delete_spec.rb +++ /dev/null @@ -1,131 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife client bulk delete", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has some clients" do - before do - client "concat", {} - client "cons", {} - client "car", {} - client "cdr", {} - client "cat", {} - end - - it "deletes all matching clients" do - knife("client bulk delete ^ca.*", input: "Y").should_succeed <<~EOM - The following clients will be deleted: - - car cat - - Are you sure you want to delete these clients? (Y/N) Deleted client car - Deleted client cat - EOM - - knife("client list").should_succeed <<~EOM - cdr - chef-validator - chef-webui - concat - cons - EOM - end - - it "deletes all matching clients when unanchored" do - knife("client bulk delete ca.*", input: "Y").should_succeed <<~EOM - The following clients will be deleted: - - car cat concat - - Are you sure you want to delete these clients? (Y/N) Deleted client car - Deleted client cat - Deleted client concat - EOM - - knife("client list").should_succeed <<~EOM - cdr - chef-validator - chef-webui - cons - EOM - end - end - - when_the_chef_server "has a validator client" do - before do - client "cons", {} - client "car", {} - client "car-validator", { validator: true } - client "cdr", {} - client "cat", {} - end - - it "refuses to delete a validator normally" do - knife("client bulk delete ^ca.*", input: "Y").should_succeed <<~EOM - The following clients are validators and will not be deleted: - - car-validator - - You must specify --delete-validators to delete the validator clients - The following clients will be deleted: - - car cat - - Are you sure you want to delete these clients? (Y/N) Deleted client car - Deleted client cat - EOM - - knife("client list").should_succeed <<~EOM - car-validator - cdr - chef-validator - chef-webui - cons - EOM - end - - it "deletes a validator when told to" do - knife("client bulk delete ^ca.* -D", input: "Y\nY").should_succeed <<~EOM - The following validators will be deleted: - - car-validator - - Are you sure you want to delete these validators? (Y/N) Deleted client car-validator - The following clients will be deleted: - - car cat - - Are you sure you want to delete these clients? (Y/N) Deleted client car - Deleted client cat - EOM - - knife("client list").should_succeed <<~EOM - cdr - chef-validator - chef-webui - cons - EOM - end - end -end diff --git a/spec/integration/knife/client_create_spec.rb b/spec/integration/knife/client_create_spec.rb deleted file mode 100644 index 3898ff9d24..0000000000 --- a/spec/integration/knife/client_create_spec.rb +++ /dev/null @@ -1,70 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" -require "openssl" - -describe "knife client create", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - let(:out) { "Created client[bah]\n" } - - when_the_chef_server "is empty" do - it "creates a new client" do - knife("client create -k bah").should_succeed stderr: out - end - - it "creates a new validator client" do - knife("client create -k --validator bah").should_succeed stderr: out - knife("client show bah").should_succeed <<~EOM - admin: false - chef_type: client - name: bah - validator: true - EOM - end - - it "refuses to add an existing client" do - pending "Knife client create must not blindly overwrite an existing client" - knife("client create -k bah").should_succeed stderr: out - expect { knife("client create -k bah") }.to raise_error(Net::HTTPClientException) - end - - it "saves the private key to a file" do - Dir.mktmpdir do |tgt| - knife("client create -f #{tgt}/bah.pem bah").should_succeed stderr: out - expect(File).to exist("#{tgt}/bah.pem") - end - end - - it "reads the public key from a file" do - Dir.mktmpdir do |tgt| - key = OpenSSL::PKey::RSA.generate(1024) - File.open("#{tgt}/public.pem", "w") { |pub| pub.write(key.public_key.to_pem) } - knife("client create -p #{tgt}/public.pem bah").should_succeed stderr: out - end - end - - it "refuses to run if conflicting options are passed" do - knife("client create -p public.pem --prevent-keygen blah").should_fail stderr: "FATAL: You cannot pass --public-key and --prevent-keygen\n", stdout: /^USAGE.*/ - end - end -end diff --git a/spec/integration/knife/client_delete_spec.rb b/spec/integration/knife/client_delete_spec.rb deleted file mode 100644 index 057561eaea..0000000000 --- a/spec/integration/knife/client_delete_spec.rb +++ /dev/null @@ -1,64 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife client delete", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has some clients" do - before do - client "cons", {} - client "car", {} - client "car-validator", { validator: true } - client "cdr", {} - client "cat", {} - end - - it "deletes a client" do - knife("client delete car", input: "Y").should_succeed <<~EOM - Do you really want to delete car? (Y/N) Deleted client[car] - EOM - - knife("client list").should_succeed <<~EOM - car-validator - cat - cdr - chef-validator - chef-webui - cons - EOM - end - - it "refuses to delete a validator normally" do - knife("client delete car-validator", input: "Y").should_fail exit_code: 2, stdout: "Do you really want to delete car-validator? (Y/N) ", stderr: <<~EOM - FATAL: You must specify --delete-validators to delete the validator client car-validator - EOM - end - - it "deletes a validator correctly" do - knife("client delete car-validator -D", input: "Y").should_succeed <<~EOM - Do you really want to delete car-validator? (Y/N) Deleted client[car-validator] - EOM - end - - end -end diff --git a/spec/integration/knife/client_key_create_spec.rb b/spec/integration/knife/client_key_create_spec.rb deleted file mode 100644 index 29b960111c..0000000000 --- a/spec/integration/knife/client_key_create_spec.rb +++ /dev/null @@ -1,66 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" -require "openssl" - -describe "knife client key create", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - let(:out) { "Created key: new" } - - when_the_chef_server "has a client" do - before do - client "bah", {} - end - - it "creates a new client key" do - knife("client key create -k new bah").should_succeed stderr: /^#{out}/, stdout: /.*BEGIN RSA PRIVATE KEY/ - end - - it "creates a new client key with an expiration date" do - date = "2017-12-31T23:59:59Z" - knife("client key create -k new -e #{date} bah").should_succeed stderr: /^#{out}/, stdout: /.*BEGIN RSA PRIVATE KEY/ - knife("client key show bah new").should_succeed(/expiration_date:.*#{date}/) - end - - it "refuses to add an already existing key" do - knife("client key create -k new bah") - expect { knife("client key create -k new bah") }.to raise_error(Net::HTTPClientException) - end - - it "saves the private key to a file" do - Dir.mktmpdir do |tgt| - knife("client key create -f #{tgt}/bah.pem -k new bah").should_succeed stderr: /^#{out}/ - expect(File).to exist("#{tgt}/bah.pem") - end - end - - it "reads the public key from a file" do - Dir.mktmpdir do |tgt| - key = OpenSSL::PKey::RSA.generate(1024) - File.open("#{tgt}/public.pem", "w") { |pub| pub.write(key.public_key.to_pem) } - knife("client key create -p #{tgt}/public.pem -k new bah").should_succeed stderr: /^#{out}/ - end - end - - end -end diff --git a/spec/integration/knife/client_key_delete_spec.rb b/spec/integration/knife/client_key_delete_spec.rb deleted file mode 100644 index 8c15377986..0000000000 --- a/spec/integration/knife/client_key_delete_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife client key delete", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has a client" do - before do - client "car", {} - end - - it "deletes a client" do - out = "Do you really want to delete the key named new for the client named car? (Y/N) " - knife("client key create -k new car") - knife("client key delete car new", input: "Y").should_succeed stdout: out, stderr: <<~EOM - Deleted key named new for the client named car - EOM - - knife("client key list car").should_succeed "" - end - - end -end diff --git a/spec/integration/knife/client_key_list_spec.rb b/spec/integration/knife/client_key_list_spec.rb deleted file mode 100644 index 01e5b78585..0000000000 --- a/spec/integration/knife/client_key_list_spec.rb +++ /dev/null @@ -1,61 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" -require "date" - -describe "knife client key list", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - let(:now) { DateTime.now } - let(:last_month) { (now << 1).strftime("%FT%TZ") } - let(:next_month) { (now >> 1).strftime("%FT%TZ") } - - when_the_chef_server "has a client" do - before do - client "cons", {} - knife("client key create cons -k new") - knife("client key create cons -k next_month -e #{next_month}") - knife("client key create cons -k expired -e #{last_month}") - end - - it "lists the keys for a client" do - knife("client key list cons").should_succeed "expired\nnew\nnext_month\n" - end - - it "shows detailed output" do - knife("client key list -w cons").should_succeed <<~EOM - expired: http://127.0.0.1:8900/clients/cons/keys/expired (expired) - new: http://127.0.0.1:8900/clients/cons/keys/new - next_month: http://127.0.0.1:8900/clients/cons/keys/next_month - EOM - end - - it "lists the expired keys for a client" do - knife("client key list -e cons").should_succeed "expired\n" - end - - it "lists the unexpired keys for a client" do - knife("client key list -n cons").should_succeed "new\nnext_month\n" - end - - end -end diff --git a/spec/integration/knife/client_key_show_spec.rb b/spec/integration/knife/client_key_show_spec.rb deleted file mode 100644 index 05024d40b2..0000000000 --- a/spec/integration/knife/client_key_show_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" -require "date" - -describe "knife client key show", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - let(:now) { DateTime.now } - let(:last_month) { (now << 1).strftime("%FT%TZ") } - let(:next_month) { (now >> 1).strftime("%FT%TZ") } - - when_the_chef_server "has a client" do - before do - client "cons", {} - knife("client key create cons -k new") - knife("client key create cons -k next_month -e #{next_month}") - knife("client key create cons -k expired -e #{last_month}") - end - - it "shows a key for a client" do - knife("client key show cons new").should_succeed stdout: /.*name:.*new/ - end - - end -end diff --git a/spec/integration/knife/client_list_spec.rb b/spec/integration/knife/client_list_spec.rb deleted file mode 100644 index 7668b9e455..0000000000 --- a/spec/integration/knife/client_list_spec.rb +++ /dev/null @@ -1,49 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife client list", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has some clients" do - before do - client "cons", {} - client "car", {} - client "car-validator", { validator: true } - client "cdr", {} - client "cat", {} - end - - it "lists the clients" do - knife("client list").should_succeed <<~EOM - car - car-validator - cat - cdr - chef-validator - chef-webui - cons - EOM - end - - end -end diff --git a/spec/integration/knife/client_show_spec.rb b/spec/integration/knife/client_show_spec.rb deleted file mode 100644 index 39a107e37f..0000000000 --- a/spec/integration/knife/client_show_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife client show", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has a client" do - before do - client "cons", {} - end - - it "shows a client" do - knife("client show cons").should_succeed stdout: /.*name:.*cons/ - end - - end -end diff --git a/spec/integration/knife/common_options_spec.rb b/spec/integration/knife/common_options_spec.rb deleted file mode 100644 index 7796bf9923..0000000000 --- a/spec/integration/knife/common_options_spec.rb +++ /dev/null @@ -1,174 +0,0 @@ -# -# Author:: John Keiser (<jkeiser@chef.io>) -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "chef/knife/raw" - -describe "knife common options", :workstation do - include IntegrationSupport - include KnifeSupport - - before do - # Allow this for testing the various port binding stuffs. Remove when - # we kill off --listen. - Chef::Config.treat_deprecation_warnings_as_errors(false) - end - - let(:local_listen_warning) { /\Awarn:.*local.*listen.*$/im } - - when_the_repository "has a node" do - before { file "nodes/x.json", {} } - - context "When chef_zero.enabled is true" do - before(:each) do - Chef::Config.chef_zero.enabled = true - end - - it "knife raw /nodes/x should retrieve the node in socketless mode" do - Chef::Config.treat_deprecation_warnings_as_errors(true) - knife("raw /nodes/x").should_succeed( /"name": "x"/ ) - end - - it "knife raw /nodes/x should retrieve the node" do - knife("raw --listen /nodes/x").should_succeed( /"name": "x"/, stderr: local_listen_warning ) - end - - context "And chef_zero.port is 9999" do - before(:each) { Chef::Config.chef_zero.port = 9999 } - - it "knife raw /nodes/x should retrieve the node" do - knife("raw --listen /nodes/x").should_succeed( /"name": "x"/, stderr: local_listen_warning ) - expect(Chef::Config.chef_server_url).to eq("chefzero://localhost:9999") - end - end - - # 0.0.0.0 is not a valid address to bind to on windows. - context "And chef_zero.host is 0.0.0.0", :unix_only do - before(:each) { Chef::Config.chef_zero.host = "0.0.0.0" } - - it "knife raw /nodes/x should retrieve the role" do - knife("raw --listen /nodes/x").should_succeed( /"name": "x"/, stderr: local_listen_warning ) - end - end - - context "and there is a private key" do - before do - file "mykey.pem", <<~EOM - -----BEGIN RSA PRIVATE KEY----- - MIIEogIBAAKCAQEApubutqtYYQ5UiA9QhWP7UvSmsfHsAoPKEVVPdVW/e8Svwpyf - 0Xef6OFWVmBE+W442ZjLOe2y6p2nSnaq4y7dg99NFz6X+16mcKiCbj0RCiGqCvCk - NftHhTgO9/RFvCbmKZ1RKNob1YzLrFpxBHaSh9po+DGWhApcd+I+op+ZzvDgXhNn - 0nauZu3rZmApI/r7EEAOjFedAXs7VPNXhhtZAiLSAVIrwU3ZajtSzgXOxbNzgj5O - AAAMmThK+71qPdffAdO4J198H6/MY04qgtFo7vumzCq0UCaGZfmeI1UNE4+xQWwP - HJ3pDAP61C6Ebx2snI2kAd9QMx9Y78nIedRHPwIDAQABAoIBAHssRtPM1GacWsom - 8zfeN6ZbI4KDlbetZz0vhnqDk9NVrpijWlcOP5dwZXVNitnB/HaqCqFvyPDY9JNB - zI/pEFW4QH59FVDP42mVEt0keCTP/1wfiDDGh1vLqVBYl/ZphscDcNgDTzNkuxMx - k+LFVxKnn3w7rGc59lALSkpeGvbbIDjp3LUMlUeCF8CIFyYZh9ZvXe4OCxYdyjxb - i8tnMLKvJ4Psbh5jMapsu3rHQkfPdqzztQUz8vs0NYwP5vWge46FUyk+WNm/IhbJ - G3YM22nwUS8Eu2bmTtADSJolATbCSkOwQ1D+Fybz/4obfYeGaCdOqB05ttubhenV - ShsAb7ECgYEA20ecRVxw2S7qA7sqJ4NuYOg9TpfGooptYNA1IP971eB6SaGAelEL - awYkGNuu2URmm5ElZpwJFFTDLGA7t2zB2xI1FeySPPIVPvJGSiZoFQOVlIg9WQzK - 7jTtFQ/tOMrF+bigEUJh5bP1/7HzqSpuOsPjEUb2aoCTp+tpiRGL7TUCgYEAwtns - g3ysrSEcTzpSv7fQRJRk1lkBhatgNd0oc+ikzf74DaVLhBg1jvSThDhiDCdB59mr - Jh41cnR1XqE8jmdQbCDRiFrI1Pq6TPaDZFcovDVE1gue9x86v3FOH2ukPG4d2/Xy - HevXjThtpMMsWFi0JYXuzXuV5HOvLZiP8sN3lSMCgYANpdxdGM7RRbE9ADY0dWK2 - V14ReTLcxP7fyrWz0xLzEeCqmomzkz3BsIUoouu0DCTSw+rvAwExqcDoDylIVlWO - fAifz7SeZHbcDxo+3TsXK7zwnLYsx7YNs2+aIv6hzUUbMNmNmXMcZ+IEwx+mRMTN - lYmZdrA5mr0V83oDFPt/jQKBgC74RVE03pMlZiObFZNtheDiPKSG9Bz6wMh7NWMr - c37MtZLkg52mEFMTlfPLe6ceV37CM8WOhqe+dwSGrYhOU06dYqUR7VOZ1Qr0aZvo - fsNPu/Y0+u7rMkgv0fs1AXQnvz7kvKaF0YITVirfeXMafuKEtJoH7owRbur42cpV - YCAtAoGAP1rHOc+w0RUcBK3sY7aErrih0OPh9U5bvJsrw1C0FIZhCEoDVA+fNIQL - syHLXYFNy0OxMtH/bBAXBGNHd9gf5uOnqh0pYcbe/uRAxumC7Rl0cL509eURiA2T - +vFmf54y9YdnLXaqv+FhJT6B6V7WX7IpU9BMqJY1cJYXHuHG2KA= - -----END RSA PRIVATE KEY----- - EOM - end - - it "knife raw /nodes/x should retrieve the node" do - knife("raw --listen /nodes/x").should_succeed( /"name": "x"/, stderr: local_listen_warning ) - end - end - end - - it "knife raw -z /nodes/x retrieves the node in socketless mode" do - Chef::Config.treat_deprecation_warnings_as_errors(true) - knife("raw -z /nodes/x").should_succeed( /"name": "x"/ ) - end - - it "knife raw -z /nodes/x retrieves the node" do - knife("raw -z --listen /nodes/x").should_succeed( /"name": "x"/, stderr: local_listen_warning ) - end - - it "knife raw --local-mode /nodes/x retrieves the node" do - knife("raw --local-mode --listen /nodes/x").should_succeed( /"name": "x"/, stderr: local_listen_warning ) - end - - it "knife raw -z --chef-zero-port=9999 /nodes/x retrieves the node" do - knife("raw -z --chef-zero-port=9999 --listen /nodes/x").should_succeed( /"name": "x"/, stderr: local_listen_warning ) - expect(Chef::Config.chef_server_url).to eq("chefzero://localhost:9999") - end - - context "when the default port (8889) is already bound" do - before :each do - - @server = ChefZero::Server.new(host: "localhost", port: 8889) - @server.start_background - rescue Errno::EADDRINUSE - # OK. Don't care who has it in use, as long as *someone* does. - - end - after :each do - @server.stop if @server - end - - it "knife raw -z /nodes/x retrieves the node" do - knife("raw -z --listen /nodes/x").should_succeed( /"name": "x"/, stderr: local_listen_warning ) - expect(URI(Chef::Config.chef_server_url).port).to be > 8889 - end - end - - context "when port 9999 is already bound" do - before :each do - - @server = ChefZero::Server.new(host: "localhost", port: 9999) - @server.start_background - rescue Errno::EADDRINUSE - # OK. Don't care who has it in use, as long as *someone* does. - - end - after :each do - @server.stop if @server - end - - it "knife raw -z --chef-zero-port=9999-20000 /nodes/x" do - knife("raw -z --chef-zero-port=9999-20000 --listen /nodes/x").should_succeed( /"name": "x"/, stderr: local_listen_warning ) - expect(URI(Chef::Config.chef_server_url).port).to be > 9999 - end - - it "knife raw -z --chef-zero-port=9999-9999,19423" do - knife("raw -z --chef-zero-port=9999-9999,19423 --listen /nodes/x").should_succeed( /"name": "x"/, stderr: local_listen_warning ) - expect(URI(Chef::Config.chef_server_url).port).to be == 19423 - end - end - - it "knife raw -z --chef-zero-port=9999 /nodes/x retrieves the node" do - knife("raw -z --chef-zero-port=9999 --listen /nodes/x").should_succeed( /"name": "x"/, stderr: local_listen_warning ) - expect(Chef::Config.chef_server_url).to eq("chefzero://localhost:9999") - end - end -end diff --git a/spec/integration/knife/config_list_spec.rb b/spec/integration/knife/config_list_spec.rb deleted file mode 100644 index 5193608f36..0000000000 --- a/spec/integration/knife/config_list_spec.rb +++ /dev/null @@ -1,220 +0,0 @@ -# -# Copyright 2018, Noah Kantrowitz -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife config list", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_repository("has a custom env") do - let(:cmd_args) { [] } - let(:knife_list) do - knife("config", "list", *cmd_args, instance_filter: lambda { |instance| - # Fake the failsafe check because this command doesn't actually process knife.rb. - $__KNIFE_INTEGRATION_FAILSAFE_CHECK << " ole" - allow(File).to receive(:file?).and_call_original - }) - end - subject { knife_list.stdout } - - around do |ex| - # Store and reset the value of some env vars. - old_home = ENV["HOME"] - old_wd = Dir.pwd - # Clear these out because they are cached permanently. - ChefConfig::PathHelper.class_exec { remove_class_variable(:@@home_dir) } - Chef::Knife::ConfigList.reset_config_loader! - begin - ex.run - ensure - ENV["HOME"] = old_home - Dir.chdir(old_wd) - ENV[ChefUtils.windows? ? "CD" : "PWD"] = Dir.pwd - end - end - - before do - # Always run from the temp folder. This can't be in the `around` block above - # because it has to run after the before set in the "with a chef repo" shared context. - directory("repo") - Dir.chdir(path_to("repo")) - ENV[ChefUtils.windows? ? "CD" : "PWD"] = Dir.pwd - ENV["HOME"] = path_to(".") - allow(TTY::Screen).to receive(:width).and_return(200) - end - - # NOTE: The funky formatting with # at the end of the line of some of the - # output examples are because of how the format strings are built, there is - # substantial trailing whitespace in most cases which many editors "helpfully" remove. - - context "with no credentials file" do - subject { knife_list.stderr } - it { is_expected.to eq "FATAL: No profiles found, #{path_to(".chef/credentials")} does not exist or is empty\n" } - end - - context "with an empty credentials file" do - before { file(".chef/credentials", "") } - subject { knife_list.stderr } - it { is_expected.to eq "FATAL: No profiles found, #{path_to(".chef/credentials")} does not exist or is empty\n" } - end - - context "with a simple default profile" do - before { file(".chef/credentials", <<~EOH) } - [default] - client_name = "testuser" - client_key = "testkey.pem" - chef_server_url = "https://example.com/organizations/testorg" - EOH - it { is_expected.to eq <<~EOH.delete("#") } - Profile Client Key Server # - --------------------------------------------------------------------------------# - *default testuser ~/.chef/testkey.pem https://example.com/organizations/testorg # - EOH - end - - context "with multiple profiles" do - before { file(".chef/credentials", <<~EOH) } - [default] - client_name = "testuser" - client_key = "testkey.pem" - chef_server_url = "https://example.com/organizations/testorg" - - [prod] - client_name = "testuser" - client_key = "testkey.pem" - chef_server_url = "https://example.com/organizations/prod" - - [qa] - client_name = "qauser" - client_key = "~/src/qauser.pem" - chef_server_url = "https://example.com/organizations/testorg" - EOH - it { is_expected.to eq <<~EOH.delete("#") } - Profile Client Key Server # - --------------------------------------------------------------------------------# - *default testuser ~/.chef/testkey.pem https://example.com/organizations/testorg # - prod testuser ~/.chef/testkey.pem https://example.com/organizations/prod # - qa qauser ~/src/qauser.pem https://example.com/organizations/testorg # - EOH - end - - context "with a non-default active profile" do - let(:cmd_args) { %w{--profile prod} } - before { file(".chef/credentials", <<~EOH) } - [default] - client_name = "testuser" - client_key = "testkey.pem" - chef_server_url = "https://example.com/organizations/testorg" - - [prod] - client_name = "testuser" - client_key = "testkey.pem" - chef_server_url = "https://example.com/organizations/prod" - - [qa] - client_name = "qauser" - client_key = "~/src/qauser.pem" - chef_server_url = "https://example.com/organizations/testorg" - EOH - it { is_expected.to eq <<~EOH.delete("#") } - Profile Client Key Server # - --------------------------------------------------------------------------------# - default testuser ~/.chef/testkey.pem https://example.com/organizations/testorg # - *prod testuser ~/.chef/testkey.pem https://example.com/organizations/prod # - qa qauser ~/src/qauser.pem https://example.com/organizations/testorg # - EOH - end - - context "with a bad profile as an active profile" do - let(:cmd_args) { %w{--profile production} } - before { file(".chef/credentials", <<~EOH) } - [default] - client_name = "testuser" - client_key = "testkey.pem" - chef_server_url = "https://example.com/organizations/testorg" - - [prod] - client_name = "testuser" - client_key = "testkey.pem" - chef_server_url = "https://example.com/organizations/prod" - - [qa] - client_name = "qauser" - client_key = "~/src/qauser.pem" - chef_server_url = "https://example.com/organizations/testorg" - EOH - it { is_expected.to eq <<~EOH.delete("#") } - Profile Client Key Server # - --------------------------------------------------------------------------------# - default testuser ~/.chef/testkey.pem https://example.com/organizations/testorg # - prod testuser ~/.chef/testkey.pem https://example.com/organizations/prod # - qa qauser ~/src/qauser.pem https://example.com/organizations/testorg # - EOH - end - - context "with a minimal profile" do - before { file(".chef/credentials", <<~EOH) } - [default] - chef_server_url = "https://example.com/organizations/testorg" - EOH - it { is_expected.to match %r{^*default .*? https://example.com/organizations/testorg} } - end - - context "with -i" do - let(:cmd_args) { %w{-i} } - before { file(".chef/credentials", <<~EOH) } - [default] - chef_server_url = "https://example.com/organizations/testorg" - EOH - it { is_expected.to eq <<~EOH.delete("#") } - Profile Client Key Server # - --------------------------------------------------------------# - *default https://example.com/organizations/testorg # - EOH - end - - context "with --format=json" do - let(:cmd_args) { %w{--format=json node_name} } - before { file(".chef/credentials", <<~EOH) } - [default] - client_name = "testuser" - client_key = "testkey.pem" - chef_server_url = "https://example.com/organizations/testorg" - - [prod] - client_name = "testuser" - client_key = "testkey.pem" - chef_server_url = "https://example.com/organizations/prod" - - [qa] - client_name = "qauser" - client_key = "~/src/qauser.pem" - chef_server_url = "https://example.com/organizations/testorg" - EOH - it { - expect(JSON.parse(subject)).to eq [ - { "profile" => "default", "active" => true, "client_name" => "testuser", "client_key" => path_to(".chef/testkey.pem"), "server_url" => "https://example.com/organizations/testorg" }, - { "profile" => "prod", "active" => false, "client_name" => "testuser", "client_key" => path_to(".chef/testkey.pem"), "server_url" => "https://example.com/organizations/prod" }, - { "profile" => "qa", "active" => false, "client_name" => "qauser", "client_key" => path_to("src/qauser.pem"), "server_url" => "https://example.com/organizations/testorg" }, - ] - } - end - end -end diff --git a/spec/integration/knife/config_show_spec.rb b/spec/integration/knife/config_show_spec.rb deleted file mode 100644 index e11d001df9..0000000000 --- a/spec/integration/knife/config_show_spec.rb +++ /dev/null @@ -1,192 +0,0 @@ -# -# Copyright 2018, Noah Kantrowitz -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife config show", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - let(:cmd_args) { [] } - - when_the_repository("has a custom env") do - subject do - cmd = knife("config", "show", *cmd_args, instance_filter: lambda { |instance| - # Clear the stub set up in KnifeSupport. - allow(File).to receive(:file?).and_call_original - # Lies, damn lies, and config files. We need to allow normal config loading - # behavior to be able to test stuff. - instance.config.delete(:config_file) - $__KNIFE_INTEGRATION_FAILSAFE_CHECK << " ole" - }) - cmd.stdout - end - - around do |ex| - # Store and reset the value of some env vars. - old_chef_home = ENV["CHEF_HOME"] - old_knife_home = ENV["KNIFE_HOME"] - old_home = ENV["HOME"] - old_wd = Dir.pwd - ChefConfig::PathHelper.per_tool_home_environment = "KNIFE_HOME" - # Clear these out because they are cached permanently. - ChefConfig::PathHelper.class_exec { remove_class_variable(:@@home_dir) } - Chef::Knife::ConfigShow.reset_config_loader! - begin - ex.run - ensure - ENV["CHEF_HOME"] = old_chef_home - ENV["KNIFE_HOME"] = old_knife_home - ENV["HOME"] = old_home - Dir.chdir(old_wd) - ENV[ChefUtils.windows? ? "CD" : "PWD"] = Dir.pwd - ChefConfig::PathHelper.per_tool_home_environment = nil - end - end - - before do - # Always run from the temp folder. This can't be in the `around` block above - # because it has to run after the before set in the "with a chef repo" shared context. - directory("repo") - Dir.chdir(path_to("repo")) - ENV[ChefUtils.windows? ? "CD" : "PWD"] = Dir.pwd - ENV["HOME"] = path_to(".") - end - - context "with a global knife.rb" do - before { file(".chef/knife.rb", "node_name 'one'\n") } - - it { is_expected.to match(%r{^Loading from configuration file .*/#{File.basename(path_to("."))}/.chef/knife.rb$}) } - it { is_expected.to match(/^node_name:\s+one$/) } - end - - context "with a repo knife.rb" do - before { file("repo/.chef/knife.rb", "node_name 'two'\n") } - - it { is_expected.to match(%r{^Loading from configuration file .*/#{File.basename(path_to("."))}/repo/.chef/knife.rb$}) } - it { is_expected.to match(/^node_name:\s+two$/) } - end - - context "with both knife.rb" do - before do - file(".chef/knife.rb", "node_name 'one'\n") - file("repo/.chef/knife.rb", "node_name 'two'\n") - end - - it { is_expected.to match(%r{^Loading from configuration file .*/#{File.basename(path_to("."))}/repo/.chef/knife.rb$}) } - it { is_expected.to match(/^node_name:\s+two$/) } - end - - context "with a credentials file" do - before { file(".chef/credentials", "[default]\nclient_name = \"three\"\n") } - - it { is_expected.to match(%r{^Loading from credentials file .*/#{File.basename(path_to("."))}/.chef/credentials$}) } - it { is_expected.to match(/^node_name:\s+three$/) } - end - - context "with a credentials file and knife.rb" do - before do - file(".chef/knife.rb", "node_name 'one'\n") - file(".chef/credentials", "[default]\nclient_name = \"three\"\n") - end - - it { is_expected.to match(%r{^Loading from configuration file .*/#{File.basename(path_to("."))}/.chef/knife.rb$}) } - it { is_expected.to match(%r{^Loading from credentials file .*/#{File.basename(path_to("."))}/.chef/credentials$}) } - it { is_expected.to match(/^node_name:\s+one$/) } - end - - context "with a config dot d files" do - before { file(".chef/config.d/abc.rb", "node_name 'one'\n") } - - it { is_expected.to match(%r{^Loading from .d/ configuration file .*/#{File.basename(path_to("."))}/.chef/config.d/abc.rb$}) } - it { is_expected.to match(/^node_name:\s+one$/) } - end - - context "with a credentials file and CHEF_HOME" do - before do - file(".chef/credentials", "[default]\nclient_name = \"three\"\n") - file("foo/.chef/credentials", "[default]\nclient_name = \"four\"\n") - ENV["CHEF_HOME"] = path_to("foo") - end - - it { is_expected.to match(%r{^Loading from credentials file .*/#{File.basename(path_to("."))}/foo/.chef/credentials$}) } - it { is_expected.to match(/^node_name:\s+four$/) } - end - - context "with a credentials file and KNIFE_HOME" do - before do - file(".chef/credentials", "[default]\nclient_name = \"three\"\n") - file("bar/.chef/credentials", "[default]\nclient_name = \"four\"\n") - ENV["KNIFE_HOME"] = path_to("bar") - end - - it { is_expected.to match(%r{^Loading from credentials file .*/#{File.basename(path_to("."))}/bar/.chef/credentials$}) } - it { is_expected.to match(/^node_name:\s+four$/) } - end - - context "with single argument" do - let(:cmd_args) { %w{node_name} } - before { file(".chef/credentials", "[default]\nclient_name = \"three\"\n") } - - it { is_expected.to match(/^node_name:\s+three\Z/) } - end - - context "with two arguments" do - let(:cmd_args) { %w{node_name client_key} } - before { file(".chef/credentials", "[default]\nclient_name = \"three\"\nclient_key = \"three.pem\"") } - - it { is_expected.to match(%r{^client_key:\s+\S*/.chef/three.pem\nnode_name:\s+three\Z}) } - end - - context "with a dotted argument" do - let(:cmd_args) { %w{knife.ssh_user} } - before { file(".chef/credentials", "[default]\nclient_name = \"three\"\n[default.knife]\nssh_user = \"foo\"\n") } - - it { is_expected.to match(/^knife.ssh_user:\s+foo\Z/) } - end - - context "with regex argument" do - let(:cmd_args) { %w{/name/} } - before { file(".chef/credentials", "[default]\nclient_name = \"three\"\n") } - - it { is_expected.to match(/^node_name:\s+three\Z/) } - end - - context "with --all" do - let(:cmd_args) { %w{-a /key_contents/} } - before { file(".chef/credentials", "[default]\nclient_name = \"three\"\n") } - - it { is_expected.to match(/^client_key_contents:\s+\nvalidation_key_contents:\s+\Z/) } - end - - context "with --raw" do - let(:cmd_args) { %w{-r node_name} } - before { file(".chef/credentials", "[default]\nclient_name = \"three\"\n") } - - it { is_expected.to eq("three\n") } - end - - context "with --format=json" do - let(:cmd_args) { %w{--format=json node_name} } - before { file(".chef/credentials", "[default]\nclient_name = \"three\"\n") } - - it { expect(JSON.parse(subject)).to eq({ "node_name" => "three" }) } - end - end -end diff --git a/spec/integration/knife/config_use_spec.rb b/spec/integration/knife/config_use_spec.rb deleted file mode 100644 index 4a982bc0bd..0000000000 --- a/spec/integration/knife/config_use_spec.rb +++ /dev/null @@ -1,198 +0,0 @@ -# -# Copyright 2018, Noah Kantrowitz -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife config use", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - let(:cmd_args) { [] } - - when_the_repository("has a custom env") do - let(:knife_use) do - knife("config", "use", *cmd_args, instance_filter: lambda { |instance| - # Fake the failsafe check because this command doesn't actually process knife.rb. - $__KNIFE_INTEGRATION_FAILSAFE_CHECK << " ole" - allow(File).to receive(:file?).and_call_original - }) - end - - subject { knife_use.stdout } - - around do |ex| - # Store and reset the value of some env vars. - old_chef_home = ENV["CHEF_HOME"] - old_knife_home = ENV["KNIFE_HOME"] - old_home = ENV["HOME"] - old_wd = Dir.pwd - ChefConfig::PathHelper.per_tool_home_environment = "KNIFE_HOME" - # Clear these out because they are cached permanently. - ChefConfig::PathHelper.class_exec { remove_class_variable(:@@home_dir) } - Chef::Knife::ConfigUse.reset_config_loader! - begin - ex.run - ensure - ENV["CHEF_HOME"] = old_chef_home - ENV["KNIFE_HOME"] = old_knife_home - ENV["HOME"] = old_home - Dir.chdir(old_wd) - ENV[ChefUtils.windows? ? "CD" : "PWD"] = Dir.pwd - ChefConfig::PathHelper.per_tool_home_environment = nil - end - end - - before do - # Always run from the temp folder. This can't be in the `around` block above - # because it has to run after the before set in the "with a chef repo" shared context. - directory("repo") - Dir.chdir(path_to("repo")) - ENV[ChefUtils.windows? ? "CD" : "PWD"] = Dir.pwd - ENV["HOME"] = path_to(".") - end - - context "with no argument" do - context "with no configuration" do - it { is_expected.to eq "default\n" } - end - - context "with --profile" do - let(:cmd_args) { %w{--profile production} } - it { is_expected.to eq "production\n" } - end - - context "with an environment variable" do - around do |ex| - old_chef_profile = ENV["CHEF_PROFILE"] - begin - ENV["CHEF_PROFILE"] = "staging" - ex.run - ensure - ENV["CHEF_PROFILE"] = old_chef_profile - end - end - - it { is_expected.to eq "staging\n" } - end - - context "with a context file" do - before { file(".chef/context", "development\n") } - it { is_expected.to eq "development\n" } - end - - context "with a context file under $CHEF_HOME" do - before do - file("chefhome/.chef/context", "other\n") - ENV["CHEF_HOME"] = path_to("chefhome") - end - - it { is_expected.to eq "other\n" } - end - - context "with a context file under $KNIFE_HOME" do - before do - file("knifehome/.chef/context", "other\n") - ENV["KNIFE_HOME"] = path_to("knifehome") - end - - it { is_expected.to eq "other\n" } - end - end - - context "with an argument" do - let(:cmd_args) { %w{production} } - before { file(".chef/credentials", <<~EOH) } - [production] - client_name = "testuser" - client_key = "testkey.pem" - chef_server_url = "https://example.com/organizations/testorg" - EOH - it do - is_expected.to eq "Set default profile to production\n" - expect(File.read(path_to(".chef/context"))).to eq "production\n" - end - end - - context "with no credentials file" do - let(:cmd_args) { %w{production} } - subject { knife_use.stderr } - it { is_expected.to eq "FATAL: No profiles found, #{path_to(".chef/credentials")} does not exist or is empty\n" } - end - - context "with an empty credentials file" do - let(:cmd_args) { %w{production} } - before { file(".chef/credentials", "") } - subject { knife_use.stderr } - it { is_expected.to eq "FATAL: No profiles found, #{path_to(".chef/credentials")} does not exist or is empty\n" } - end - - context "with an wrong argument" do - let(:cmd_args) { %w{staging} } - before { file(".chef/credentials", <<~EOH) } - [production] - client_name = "testuser" - client_key = "testkey.pem" - chef_server_url = "https://example.com/organizations/testorg" - EOH - subject { knife_use } - it { expect { subject }.to raise_error ChefConfig::ConfigurationError, "Profile staging doesn't exist. Please add it to #{path_to(".chef/credentials")} and if it is profile with DNS name check that you are not missing single quotes around it as per docs https://docs.chef.io/workstation/knife_setup/#knife-profiles." } - end - - context "with $CHEF_HOME" do - let(:cmd_args) { %w{staging} } - before do - ENV["CHEF_HOME"] = path_to("chefhome"); file("chefhome/tmp", "") - file("chefhome/.chef/credentials", <<~EOH - [staging] - client_name = "testuser" - client_key = "testkey.pem" - chef_server_url = "https://example.com/organizations/testorg" - EOH - ) - end - - it do - is_expected.to eq "Set default profile to staging\n" - expect(File.read(path_to("chefhome/.chef/context"))).to eq "staging\n" - expect(File.exist?(path_to(".chef/context"))).to be_falsey - end - end - - context "with $KNIFE_HOME" do - let(:cmd_args) { %w{development} } - - before do - ENV["KNIFE_HOME"] = path_to("knifehome"); file("knifehome/tmp", "") - file("knifehome/.chef/credentials", <<~EOH - [development] - client_name = "testuser" - client_key = "testkey.pem" - chef_server_url = "https://example.com/organizations/testorg" - EOH - ) - end - - it do - is_expected.to eq "Set default profile to development\n" - expect(File.read(path_to("knifehome/.chef/context"))).to eq "development\n" - expect(File.exist?(path_to(".chef/context"))).to be_falsey - end - end - end -end diff --git a/spec/integration/knife/cookbook_api_ipv6_spec.rb b/spec/integration/knife/cookbook_api_ipv6_spec.rb deleted file mode 100644 index 5d0ce0707f..0000000000 --- a/spec/integration/knife/cookbook_api_ipv6_spec.rb +++ /dev/null @@ -1,113 +0,0 @@ -# -# Author:: Daniel DeLeo (<dan@chef.io>) -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "chef/mixin/shell_out" - -describe "Knife cookbook API integration with IPv6", :workstation, :not_supported_on_gce do - include IntegrationSupport - include Chef::Mixin::ShellOut - - when_the_chef_server "is bound to IPv6" do - let(:chef_zero_opts) { { host: "::1" } } - - let(:client_key) do - <<~END_VALIDATION_PEM - -----BEGIN RSA PRIVATE KEY----- - MIIEogIBAAKCAQEApubutqtYYQ5UiA9QhWP7UvSmsfHsAoPKEVVPdVW/e8Svwpyf - 0Xef6OFWVmBE+W442ZjLOe2y6p2nSnaq4y7dg99NFz6X+16mcKiCbj0RCiGqCvCk - NftHhTgO9/RFvCbmKZ1RKNob1YzLrFpxBHaSh9po+DGWhApcd+I+op+ZzvDgXhNn - 0nauZu3rZmApI/r7EEAOjFedAXs7VPNXhhtZAiLSAVIrwU3ZajtSzgXOxbNzgj5O - AAAMmThK+71qPdffAdO4J198H6/MY04qgtFo7vumzCq0UCaGZfmeI1UNE4+xQWwP - HJ3pDAP61C6Ebx2snI2kAd9QMx9Y78nIedRHPwIDAQABAoIBAHssRtPM1GacWsom - 8zfeN6ZbI4KDlbetZz0vhnqDk9NVrpijWlcOP5dwZXVNitnB/HaqCqFvyPDY9JNB - zI/pEFW4QH59FVDP42mVEt0keCTP/1wfiDDGh1vLqVBYl/ZphscDcNgDTzNkuxMx - k+LFVxKnn3w7rGc59lALSkpeGvbbIDjp3LUMlUeCF8CIFyYZh9ZvXe4OCxYdyjxb - i8tnMLKvJ4Psbh5jMapsu3rHQkfPdqzztQUz8vs0NYwP5vWge46FUyk+WNm/IhbJ - G3YM22nwUS8Eu2bmTtADSJolATbCSkOwQ1D+Fybz/4obfYeGaCdOqB05ttubhenV - ShsAb7ECgYEA20ecRVxw2S7qA7sqJ4NuYOg9TpfGooptYNA1IP971eB6SaGAelEL - awYkGNuu2URmm5ElZpwJFFTDLGA7t2zB2xI1FeySPPIVPvJGSiZoFQOVlIg9WQzK - 7jTtFQ/tOMrF+bigEUJh5bP1/7HzqSpuOsPjEUb2aoCTp+tpiRGL7TUCgYEAwtns - g3ysrSEcTzpSv7fQRJRk1lkBhatgNd0oc+ikzf74DaVLhBg1jvSThDhiDCdB59mr - Jh41cnR1XqE8jmdQbCDRiFrI1Pq6TPaDZFcovDVE1gue9x86v3FOH2ukPG4d2/Xy - HevXjThtpMMsWFi0JYXuzXuV5HOvLZiP8sN3lSMCgYANpdxdGM7RRbE9ADY0dWK2 - V14ReTLcxP7fyrWz0xLzEeCqmomzkz3BsIUoouu0DCTSw+rvAwExqcDoDylIVlWO - fAifz7SeZHbcDxo+3TsXK7zwnLYsx7YNs2+aIv6hzUUbMNmNmXMcZ+IEwx+mRMTN - lYmZdrA5mr0V83oDFPt/jQKBgC74RVE03pMlZiObFZNtheDiPKSG9Bz6wMh7NWMr - c37MtZLkg52mEFMTlfPLe6ceV37CM8WOhqe+dwSGrYhOU06dYqUR7VOZ1Qr0aZvo - fsNPu/Y0+u7rMkgv0fs1AXQnvz7kvKaF0YITVirfeXMafuKEtJoH7owRbur42cpV - YCAtAoGAP1rHOc+w0RUcBK3sY7aErrih0OPh9U5bvJsrw1C0FIZhCEoDVA+fNIQL - syHLXYFNy0OxMtH/bBAXBGNHd9gf5uOnqh0pYcbe/uRAxumC7Rl0cL509eURiA2T - +vFmf54y9YdnLXaqv+FhJT6B6V7WX7IpU9BMqJY1cJYXHuHG2KA= - -----END RSA PRIVATE KEY----- - END_VALIDATION_PEM - end - - let(:cache_path) do - Dir.mktmpdir - end - - let(:chef_dir) { File.join(__dir__, "..", "..", "..", "knife", "bin") } - let(:knife) { "ruby '#{chef_dir}/knife'" } - - let(:knife_config_flag) { "-c '#{path_to("config/knife.rb")}'" } - - # Some Solaris test platforms are too old for IPv6. These tests should not - # otherwise be platform dependent, so exclude solaris - context "and the chef_server_url contains an IPv6 literal", :not_supported_on_solaris do - - # This provides helper functions we need such as #path_to() - when_the_repository "has the cookbook to be uploaded" do - - let(:knife_rb_content) do - <<~END_CLIENT_RB - chef_server_url "http://[::1]:8900" - syntax_check_cache_path '#{cache_path}' - client_key '#{path_to("config/knifeuser.pem")}' - node_name 'whoisthisis' - cookbook_path '#{CHEF_SPEC_DATA}/cookbooks' - END_CLIENT_RB - end - - before do - file "config/knife.rb", knife_rb_content - file "config/knifeuser.pem", client_key - end - - it "successfully uploads a cookbook" do - shell_out!("#{knife} cookbook upload apache2 #{knife_config_flag}", cwd: chef_dir) - versions_list_json = Chef::HTTP::Simple.new("http://[::1]:8900").get("/cookbooks/apache2", "accept" => "application/json") - versions_list = Chef::JSONCompat.from_json(versions_list_json) - expect(versions_list["apache2"]["versions"]).not_to be_empty - end - - context "and the cookbook has been uploaded to the server" do - before do - shell_out!("#{knife} cookbook upload apache2 #{knife_config_flag}", cwd: chef_dir) - end - - it "downloads the cookbook" do - shell_out!("#{knife} cookbook download apache2 #{knife_config_flag} -d #{cache_path}", cwd: chef_dir) - expect(Dir["#{cache_path}/*"].map { |entry| File.basename(entry) }).to include("apache2-0.0.1") - end - end - - end - end - end -end diff --git a/spec/integration/knife/cookbook_bulk_delete_spec.rb b/spec/integration/knife/cookbook_bulk_delete_spec.rb deleted file mode 100644 index 0e791f5a1e..0000000000 --- a/spec/integration/knife/cookbook_bulk_delete_spec.rb +++ /dev/null @@ -1,65 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" -require "chef/knife/cookbook_bulk_delete" - -describe "knife cookbook bulk delete", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has a cookbook" do - before do - cookbook "foo", "1.0.0" - cookbook "foo", "0.6.5" - cookbook "fox", "0.6.0" - cookbook "fox", "0.6.5" - cookbook "fax", "0.6.0" - cookbook "zfa", "0.6.5" - end - - # rubocop:disable Layout/TrailingWhitespace - it "knife cookbook bulk delete deletes all matching cookbooks" do - stdout = <<~EOM - All versions of the following cookbooks will be deleted: - - foo fox - - Do you really want to delete these cookbooks? (Y/N) - EOM - - stderr = <<~EOM - Deleted cookbook foo [1.0.0] - Deleted cookbook foo [0.6.5] - Deleted cookbook fox [0.6.5] - Deleted cookbook fox [0.6.0] - EOM - - knife("cookbook bulk delete ^fo.*", input: "Y").should_succeed(stderr: stderr, stdout: stdout) - - knife("cookbook list -a").should_succeed <<~EOM - fax 0.6.0 - zfa 0.6.5 - EOM - end - # rubocop:enable Layout/TrailingWhitespace - - end -end diff --git a/spec/integration/knife/cookbook_download_spec.rb b/spec/integration/knife/cookbook_download_spec.rb deleted file mode 100644 index 589417126c..0000000000 --- a/spec/integration/knife/cookbook_download_spec.rb +++ /dev/null @@ -1,72 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" -require "chef/knife/cookbook_download" -require "tmpdir" - -describe "knife cookbook download", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - let(:tmpdir) { Dir.mktmpdir } - - when_the_chef_server "has only one cookbook" do - before do - cookbook "x", "1.0.1" - end - - it "knife cookbook download downloads the latest version" do - knife("cookbook download -d #{tmpdir} x").should_succeed stderr: <<~EOM - Downloading x cookbook version 1.0.1 - Downloading root_files - Cookbook downloaded to #{tmpdir}/x-1.0.1 - EOM - end - - it "knife cookbook download with a version downloads the specified version" do - knife("cookbook download -d #{tmpdir} x 1.0.1").should_succeed stderr: <<~EOM - Downloading x cookbook version 1.0.1 - Downloading root_files - Cookbook downloaded to #{tmpdir}/x-1.0.1 - EOM - end - - it "knife cookbook download with an unknown version raises an error" do - expect { knife("cookbook download -d #{tmpdir} x 1.0.0") }.to raise_error(Net::HTTPClientException) - end - end - - when_the_chef_server "has multiple cookbook versions" do - before do - cookbook "x", "1.0.1" - cookbook "x", "1.0.0" - end - - it "knife cookbook download with no version prompts" do - knife("cookbook download -d #{tmpdir} x", input: "2\n").should_succeed(stderr: <<~EOM, stdout: "Which version do you want to download?\n1. x 1.0.0\n2. x 1.0.1\n\n" - Downloading x cookbook version 1.0.1 - Downloading root_files - Cookbook downloaded to #{tmpdir}/x-1.0.1 - EOM - ) - end - end -end diff --git a/spec/integration/knife/cookbook_list_spec.rb b/spec/integration/knife/cookbook_list_spec.rb deleted file mode 100644 index e712ae3235..0000000000 --- a/spec/integration/knife/cookbook_list_spec.rb +++ /dev/null @@ -1,55 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" -require "chef/knife/cookbook_list" - -describe "knife cookbook list", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has a cookbook" do - before do - cookbook "x", "1.0.0" - cookbook "x", "0.6.5" - cookbook "x", "0.6.0" - cookbook "y", "0.6.5" - cookbook "y", "0.6.0" - cookbook "z", "0.6.5" - end - - it "knife cookbook list shows all the cookbooks" do - knife("cookbook list").should_succeed <<~EOM - x 1.0.0 - y 0.6.5 - z 0.6.5 - EOM - end - - it "knife cookbook list -a shows all the versions of all the cookbooks" do - knife("cookbook list -a").should_succeed <<~EOM - x 1.0.0 0.6.5 0.6.0 - y 0.6.5 0.6.0 - z 0.6.5 - EOM - end - - end -end diff --git a/spec/integration/knife/cookbook_show_spec.rb b/spec/integration/knife/cookbook_show_spec.rb deleted file mode 100644 index d8c2e38f64..0000000000 --- a/spec/integration/knife/cookbook_show_spec.rb +++ /dev/null @@ -1,149 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" -require "chef/knife/cookbook_show" - -describe "knife cookbook show", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has a cookbook" do - before do - cookbook "x", "1.0.0", { "recipes" => { "default.rb" => "file 'n'", "x.rb" => "" } } - cookbook "x", "0.6.5" - end - - it "knife cookbook show x shows all the versions" do - knife("cookbook show x").should_succeed "x 1.0.0 0.6.5\n" - end - - # rubocop:disable Layout/TrailingWhitespace - it "knife cookbook show x 1.0.0 shows the correct version" do - knife("cookbook show x 1.0.0").should_succeed <<~EOM - cookbook_name: x - frozen?: false - metadata: - chef_versions: - dependencies: - description: - eager_load_libraries: true - gems: - issues_url: - license: All rights reserved - long_description: - maintainer: - maintainer_email: - name: x - ohai_versions: - platforms: - privacy: false - providing: - x: >= 0.0.0 - x::x: >= 0.0.0 - recipes: - x: - x::x: - source_url: - version: 1.0.0 - name: x-1.0.0 - recipes: - checksum: 4631b34cf58de10c5ef1304889941b2e - name: recipes/default.rb - path: recipes/default.rb - specificity: default - url: http://127.0.0.1:8900/file_store/checksums/4631b34cf58de10c5ef1304889941b2e - - checksum: d41d8cd98f00b204e9800998ecf8427e - name: recipes/x.rb - path: recipes/x.rb - specificity: default - url: http://127.0.0.1:8900/file_store/checksums/d41d8cd98f00b204e9800998ecf8427e - root_files: - checksum: 8226671f751ba102dea6a6b6bd32fa8d - name: metadata.rb - path: metadata.rb - specificity: default - url: http://127.0.0.1:8900/file_store/checksums/8226671f751ba102dea6a6b6bd32fa8d - version: 1.0.0 - EOM - end - - it "knife cookbook show x 1.0.0 metadata shows the metadata" do - knife("cookbook show x 1.0.0 metadata").should_succeed <<~EOM - chef_versions: - dependencies: - description: - eager_load_libraries: true - gems: - issues_url: - license: All rights reserved - long_description: - maintainer: - maintainer_email: - name: x - ohai_versions: - platforms: - privacy: false - providing: - x: >= 0.0.0 - x::x: >= 0.0.0 - recipes: - x: - x::x: - source_url: - version: 1.0.0 - EOM - end - - it "knife cookbook show x 1.0.0 recipes shows all the recipes" do - knife("cookbook show x 1.0.0 recipes").should_succeed <<~EOM - checksum: 4631b34cf58de10c5ef1304889941b2e - name: recipes/default.rb - path: recipes/default.rb - specificity: default - url: http://127.0.0.1:8900/file_store/checksums/4631b34cf58de10c5ef1304889941b2e - - checksum: d41d8cd98f00b204e9800998ecf8427e - name: recipes/x.rb - path: recipes/x.rb - specificity: default - url: http://127.0.0.1:8900/file_store/checksums/d41d8cd98f00b204e9800998ecf8427e - EOM - end - # rubocop:enable Layout/TrailingWhitespace - - it "knife cookbook show x 1.0.0 recipes default.rb shows the default recipe" do - knife("cookbook show x 1.0.0 recipes default.rb").should_succeed "file 'n'\n" - end - - it "knife cookbook show with a non-existent file displays an error" do - expect { knife("cookbook show x 1.0.0 recipes moose.rb") }.to raise_error(Chef::Exceptions::FileNotFound) - end - - it "knife cookbook show with a non-existent version displays an error" do - expect { knife("cookbook show x 1.0.1") }.to raise_error(Net::HTTPClientException) - end - - it "knife cookbook show with a non-existent cookbook displays an error" do - expect { knife("cookbook show y") }.to raise_error(Net::HTTPClientException) - end - end -end diff --git a/spec/integration/knife/cookbook_upload_spec.rb b/spec/integration/knife/cookbook_upload_spec.rb deleted file mode 100644 index f42683b2a3..0000000000 --- a/spec/integration/knife/cookbook_upload_spec.rb +++ /dev/null @@ -1,128 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" -require "chef/knife/cookbook_upload" - -describe "knife cookbook upload", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - let(:cb_dir) { "#{@repository_dir}/cookbooks" } - - when_the_chef_server "is empty" do - when_the_repository "has a cookbook" do - before do - file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0") - end - - it "knife cookbook upload uploads the cookbook" do - knife("cookbook upload x -o #{cb_dir}").should_succeed stderr: <<~EOM - Uploading x [1.0.0] - Uploaded 1 cookbook. - EOM - end - - it "knife cookbook upload --freeze uploads and freezes the cookbook" do - knife("cookbook upload x -o #{cb_dir} --freeze").should_succeed stderr: <<~EOM - Uploading x [1.0.0] - Uploaded 1 cookbook. - EOM - # Modify the file, attempt to reupload - file "cookbooks/x/metadata.rb", 'name "x"; version "1.0.0"#different' - knife("cookbook upload x -o #{cb_dir} --freeze").should_fail stderr: <<~EOM - Uploading x [1.0.0] - ERROR: Version 1.0.0 of cookbook x is frozen. Use --force to override. - WARNING: Not updating version constraints for x in the environment as the cookbook is frozen. - ERROR: Failed to upload 1 cookbook. - EOM - end - end - - when_the_repository "has a cookbook that depends on another cookbook" do - before do - file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0", "\ndepends 'y'") - file "cookbooks/y/metadata.rb", cb_metadata("y", "1.0.0") - end - - it "knife cookbook upload --include-dependencies uploads both cookbooks" do - knife("cookbook upload --include-dependencies x -o #{cb_dir}").should_succeed stderr: <<~EOM - Uploading x [1.0.0] - Uploading y [1.0.0] - Uploaded 2 cookbooks. - EOM - end - - it "knife cookbook upload fails due to missing dependencies" do - knife("cookbook upload x -o #{cb_dir}").should_fail stderr: <<~EOM - Uploading x [1.0.0] - ERROR: Cookbook x depends on cookbooks which are not currently - ERROR: being uploaded and cannot be found on the server. - ERROR: The missing cookbook(s) are: 'y' version '>= 0.0.0' - EOM - end - - it "knife cookbook upload -a uploads both cookbooks" do - knife("cookbook upload -a -o #{cb_dir}").should_succeed stderr: <<~EOM - Uploading x [1.0.0] - Uploading y [1.0.0] - Uploaded all cookbooks. - EOM - end - end - - when_the_repository "has cookbook metadata without name attribute in metadata file" do - before do - file "cookbooks/x/metadata.rb", cb_metadata(nil, "1.0.0") - end - - it "knife cookbook upload x " do - expect { knife("cookbook upload x -o #{cb_dir}") }.to raise_error(Chef::Exceptions::MetadataNotValid) - end - end - - when_the_repository "has cookbooks at multiple paths" do - - let(:cb_dir_first) do - File.join(@repository_dir, "cookbooks") - .gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR) - end - - let(:cb_dir_second) do - File.join(@repository_dir, "test_cookbooks") - .gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR) - end - - before(:each) do - file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0") - file "test_cookbooks/y/metadata.rb", cb_metadata("y", "1.0.0") - end - - it "knife cookbook upload with -o or --cookbook-path" do - knife("cookbook upload x y -o #{cb_dir_first}#{File::PATH_SEPARATOR}#{cb_dir_second}").should_succeed stderr: <<~EOM - Uploading x [1.0.0] - Uploading y [1.0.0] - Uploaded 2 cookbooks. - EOM - end - - end - end -end diff --git a/spec/integration/knife/data_bag_create_spec.rb b/spec/integration/knife/data_bag_create_spec.rb deleted file mode 100644 index 439d69507c..0000000000 --- a/spec/integration/knife/data_bag_create_spec.rb +++ /dev/null @@ -1,125 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" -require "chef/knife/data_bag_create" - -describe "knife data bag create", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - let(:err) { "Created data_bag[foo]\n" } - let(:out) { "Created data_bag_item[bar]\n" } - let(:exists) { "Data bag foo already exists\n" } - let(:secret) { "abc" } - - when_the_chef_server "is empty" do - context "with encryption key" do - it "creates a new data bag and item" do - pretty_json = Chef::JSONCompat.to_json_pretty({ id: "bar", test: "pass" }) - allow(Chef::JSONCompat).to receive(:to_json_pretty).and_return(pretty_json) - knife("data bag create foo bar --secret #{secret}").should_succeed stdout: out, stderr: err - expect(knife("data bag show foo bar --secret #{secret}").stderr).to eq("Encrypted data bag detected, decrypting with provided secret.\n") - expect(knife("data bag show foo bar --secret #{secret}").stdout).to eq("id: bar\ntest: pass\n") - end - - it "creates a new data bag and an empty item" do - knife("data bag create foo bar --secret #{secret}").should_succeed stdout: out, stderr: err - expect(knife("data bag show foo bar --secret #{secret}").stderr).to eq("WARNING: Unencrypted data bag detected, ignoring any provided secret options.\n") - expect(knife("data bag show foo bar --secret #{secret}").stdout).to eq("id: bar\n") - end - end - - context "without encryption key" do - it "creates a new data bag" do - knife("data bag create foo").should_succeed stderr: err - expect(knife("data bag show foo").stderr).to eq("") - end - - it "creates a new data bag and item" do - knife("data bag create foo bar").should_succeed stdout: out, stderr: err - expect(knife("data bag show foo").stdout).to eq("bar\n") - end - end - end - - when_the_chef_server "has some data bags" do - before do - data_bag "foo", {} - data_bag "bag", { "box" => {} } - end - - context "with encryption key" do - it "creates a new data bag and item" do - pretty_json = Chef::JSONCompat.to_json_pretty({ id: "bar", test: "pass" }) - allow(Chef::JSONCompat).to receive(:to_json_pretty).and_return(pretty_json) - knife("data bag create rocket bar --secret #{secret}").should_succeed stdout: out, stderr: <<~EOM - Created data_bag[rocket] - EOM - expect(knife("data bag show rocket bar --secret #{secret}").stderr).to eq("Encrypted data bag detected, decrypting with provided secret.\n") - expect(knife("data bag show rocket bar --secret #{secret}").stdout).to eq("id: bar\ntest: pass\n") - end - - it "creates a new data bag and an empty item" do - knife("data bag create rocket bar --secret #{secret}").should_succeed stdout: out, stderr: <<~EOM - Created data_bag[rocket] - EOM - expect(knife("data bag show rocket bar --secret #{secret}").stderr).to eq("WARNING: Unencrypted data bag detected, ignoring any provided secret options.\n") - expect(knife("data bag show rocket bar --secret #{secret}").stdout).to eq("id: bar\n") - end - - it "adds a new item to an existing bag" do - knife("data bag create foo bar --secret #{secret}").should_succeed stdout: out, stderr: exists - expect(knife("data bag show foo bar --secret #{secret}").stderr).to eq("WARNING: Unencrypted data bag detected, ignoring any provided secret options.\n") - expect(knife("data bag show foo bar --secret #{secret}").stdout).to eq("id: bar\n") - end - - it "fails to add an existing item" do - expect { knife("data bag create bag box --secret #{secret}") }.to raise_error(Net::HTTPClientException) - end - end - - context "without encryption key" do - it "creates a new data bag" do - knife("data bag create rocket").should_succeed stderr: <<~EOM - Created data_bag[rocket] - EOM - end - - it "creates a new data bag and item" do - knife("data bag create rocket bar").should_succeed stdout: out, stderr: <<~EOM - Created data_bag[rocket] - EOM - end - - it "adds a new item to an existing bag" do - knife("data bag create foo bar").should_succeed stdout: out, stderr: exists - end - - it "refuses to create an existing data bag" do - knife("data bag create foo").should_succeed stderr: exists - end - - it "fails to add an existing item" do - expect { knife("data bag create bag box") }.to raise_error(Net::HTTPClientException) - end - end - end -end diff --git a/spec/integration/knife/data_bag_delete_spec.rb b/spec/integration/knife/data_bag_delete_spec.rb deleted file mode 100644 index a7fac7e2ee..0000000000 --- a/spec/integration/knife/data_bag_delete_spec.rb +++ /dev/null @@ -1,59 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" -require "chef/knife/data_bag_delete" - -describe "knife data bag delete", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has some data bags" do - before do - data_bag "x", {} - data_bag "canteloupe", {} - data_bag "rocket", { "falcon9" => { heavy: "true" }, "atlas" => {}, "ariane" => {} } - end - - it "with an empty data bag" do - knife("data bag delete canteloupe", input: "y").should_succeed <<~EOM - Do you really want to delete canteloupe? (Y/N) Deleted data_bag[canteloupe] - EOM - end - - it "with a bag with some items" do - knife("data bag delete rocket", input: "y").should_succeed <<~EOM - Do you really want to delete rocket? (Y/N) Deleted data_bag[rocket] - EOM - end - - it "with a single item" do - knife("data bag delete rocket falcon9", input: "y").should_succeed <<~EOM - Do you really want to delete falcon9? (Y/N) Deleted data_bag_item[falcon9] - EOM - end - - it "choosing not to delete" do - knife("data bag delete rocket falcon9", input: "n").should_succeed <<~EOM, exit_code: 3 - Do you really want to delete falcon9? (Y/N) You said no, so I'm done here. - EOM - end - end -end diff --git a/spec/integration/knife/data_bag_edit_spec.rb b/spec/integration/knife/data_bag_edit_spec.rb deleted file mode 100644 index 1071df2a78..0000000000 --- a/spec/integration/knife/data_bag_edit_spec.rb +++ /dev/null @@ -1,105 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" -require "chef/knife/data_bag_edit" - -describe "knife data bag edit", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - let(:out) { "Saved data_bag_item[box]\n" } - let(:err) { "Saving data bag unencrypted. To encrypt it, provide an appropriate secret.\n" } - let(:secret) { "abc" } - let(:encrypt) { "Encrypted data bag detected, decrypting with provided secret.\n" } - - when_the_chef_server "is empty" do - context "with encryption key" do - it "fails to edit an item" do - expect { knife("data bag edit bag box --secret #{secret}") }.to raise_error(Net::HTTPClientException) - end - end - - context "without encryption key" do - it "fails to edit an item" do - expect { knife("data bag edit bag box") }.to raise_error(Net::HTTPClientException) - end - end - end - - when_the_chef_server "has some data bags" do - before do - data_bag "foo", {} - data_bag "bag", { "box" => {} } - data_bag "rocket", { "falcon9" => { heavy: "true" }, "atlas" => {}, "ariane" => {} } - data_bag "encrypt", { "box" => { id: "box", foo: { "encrypted_data": "J8N0pJ+LFDQF3XvhzWgkSBOuZZn8Og==\n", "iv": "4S1sb4zLnMt71SXV\n", "auth_tag": "4ChINhxz4WmqOizvZNoPPg==\n", "version": 3, "cipher": "aes-256-gcm" } } } - end - - context "with encryption key" do - it "fails to edit a non-existing item" do - expect { knife("data bag edit foo box --secret #{secret}") }.to raise_error(Net::HTTPClientException) - end - - it "edits an encrypted data bag item" do - pretty_json = Chef::JSONCompat.to_json_pretty({ id: "box", foo: "bar" }) - allow(Chef::JSONCompat).to receive(:to_json_pretty).and_return(pretty_json) - knife("data bag edit encrypt box --secret #{secret}") - knife("data bag show encrypt box --secret #{secret}").should_succeed stderr: encrypt, stdout: <<~EOM - foo: bar - id: box - EOM - end - - it "encrypts an unencrypted data bag item" do - knife("data bag edit rocket falcon9 --secret #{secret}") - knife("data bag show rocket falcon9 --secret #{secret}").should_succeed stderr: encrypt, stdout: <<~EOM - heavy: true - id: falcon9 - EOM - end - end - - context "without encryption key" do - it "fails to edit a non-existing item" do - expect { knife("data bag edit foo box") }.to raise_error(Net::HTTPClientException) - end - it "edits an empty data bag item" do - pretty_json = Chef::JSONCompat.to_json_pretty({ id: "box", ab: "abc" }) - allow(Chef::JSONCompat).to receive(:to_json_pretty).and_return(pretty_json) - knife("data bag edit bag box").should_succeed stderr: err, stdout: out - knife("data bag show bag box").should_succeed <<~EOM - ab: abc - id: box - EOM - end - it "edits a non-empty data bag item" do - pretty_json = Chef::JSONCompat.to_json_pretty({ id: "falcon9", heavy: false }) - allow(Chef::JSONCompat).to receive(:to_json_pretty).and_return(pretty_json) - knife("data bag edit rocket falcon9").should_succeed stderr: err, stdout: <<~EOM - Saved data_bag_item[falcon9] - EOM - knife("data bag show rocket falcon9").should_succeed <<~EOM - heavy: false - id: falcon9 - EOM - end - end - end -end diff --git a/spec/integration/knife/data_bag_from_file_spec.rb b/spec/integration/knife/data_bag_from_file_spec.rb deleted file mode 100644 index bb8bd192f0..0000000000 --- a/spec/integration/knife/data_bag_from_file_spec.rb +++ /dev/null @@ -1,116 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife data bag from file", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - let(:db_dir) { "#{@repository_dir}/data_bags" } - - when_the_chef_server "has an empty data bag" do - before do - data_bag "foo", {} - data_bag "bar", {} - end - - when_the_repository "has some data bag items" do - before do - file "data_bags/foo/bar.json", { "id" => "bar", "foo" => "bar " } - file "data_bags/foo/bzr.json", { "id" => "bzr", "foo" => "bar " } - file "data_bags/foo/cat.json", { "id" => "cat", "foo" => "bar " } - file "data_bags/foo/dog.json", { "id" => "dog", "foo" => "bar " } - file "data_bags/foo/encrypted.json", <<~EOM - { - "id": "encrypted", - "password": { - "encrypted_data": "H6ab5RY9a9JAkS8A0RCMspXtOJh0ai8cNeA4Q3gLO8s=\\n", - "iv": "uWKKKxrJgtELlGMCOLJdkA==\\n", - "version": 1, - "cipher": "aes-256-cbc" - } - } - EOM - file "data_bags/bar/round_trip.json", <<~EOM - { - "name": "data_bag_item_bar_round_trip", - "json_class": "Chef::DataBagItem", - "chef_type": "data_bag_item", - "data_bag": "bar", - "raw_data": { - "id": "round_trip", - "root_password": { - "encrypted_data": "noDOsTpsTAZlTU5sprhmYZzUDfr8du7hH/zRDOjRAmoTJHTZyfYoR221EOOW\\nXJ1D\\n", - "iv": "Bnqhfy6n0Hx1wCe9pxHLoA==\\n", - "version": 1, - "cipher": "aes-256-cbc" - }, - "admin_password": { - "encrypted_data": "TcC7dU1gx6OnE5Ab4i/k42UEf0Nnr7cAyuTHId/LNjNOwpNf7XZc27DQSjuy\\nHPlt\\n", - "iv": "+TAWJuPWCI2+WB8lGJAyvw==\\n", - "version": 1, - "cipher": "aes-256-cbc" - } - } - } - EOM - end - - it "uploads a single file" do - knife("data bag from file foo #{db_dir}/foo/bar.json").should_succeed stderr: <<~EOM - Updated data_bag_item[foo::bar] - EOM - end - - it "uploads a single encrypted file" do - knife("data bag from file foo #{db_dir}/foo/encrypted.json").should_succeed stderr: <<~EOM - Updated data_bag_item[foo::encrypted] - EOM - end - - it "uploads a file in chef's internal format" do - pending "chef/chef#4815" - knife("data bag from file bar #{db_dir}/bar/round_trip.json").should_succeed stderr: <<~EOM - Updated data_bag_item[bar::round_trip] - EOM - end - - it "uploads many files" do - knife("data bag from file foo #{db_dir}/foo/bar.json #{db_dir}/foo/bzr.json").should_succeed stderr: <<~EOM - Updated data_bag_item[foo::bar] - Updated data_bag_item[foo::bzr] - EOM - end - - it "uploads a whole directory" do - knife("data bag from file foo #{db_dir}/foo") - knife("data bag show foo").should_succeed <<~EOM - bar - bzr - cat - dog - encrypted - EOM - end - - end - end -end diff --git a/spec/integration/knife/data_bag_list_spec.rb b/spec/integration/knife/data_bag_list_spec.rb deleted file mode 100644 index 1e7734db64..0000000000 --- a/spec/integration/knife/data_bag_list_spec.rb +++ /dev/null @@ -1,44 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" -require "chef/knife/data_bag_list" - -describe "knife data bag list", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has some data bags" do - before do - data_bag "x", {} - data_bag "canteloupe", {} - data_bag "rocket", {} - end - - it "knife data bag list shows all the cookbooks" do - knife("data bag list").should_succeed <<~EOM - canteloupe - rocket - x - EOM - end - - end -end diff --git a/spec/integration/knife/data_bag_show_spec.rb b/spec/integration/knife/data_bag_show_spec.rb deleted file mode 100644 index 91ebf605f1..0000000000 --- a/spec/integration/knife/data_bag_show_spec.rb +++ /dev/null @@ -1,95 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" -require "chef/knife/data_bag_show" - -describe "knife data bag show", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "is empty" do - it "raises error if try to retrieve it" do - expect { knife("data bag show bag") }.to raise_error(Net::HTTPClientException) - end - end - - when_the_chef_server "contains data bags" do - let(:right_secret) { "abc" } - let(:wrong_secret) { "ab" } - let(:err) { "Encrypted data bag detected, decrypting with provided secret.\n" } - before do - data_bag "x", {} - data_bag "canteloupe", {} - data_bag "rocket", { "falcon9" => { heavy: "true" }, "atlas" => {}, "ariane" => {} } - data_bag "encrypt", { "box" => { id: "box", foo: { "encrypted_data": "J8N0pJ+LFDQF3XvhzWgkSBOuZZn8Og==\n", "iv": "4S1sb4zLnMt71SXV\n", "auth_tag": "4ChINhxz4WmqOizvZNoPPg==\n", "version": 3, "cipher": "aes-256-gcm" } } } - end - - context "with encrypted data" do - context "provided secret key" do - it "shows data if secret key is correct" do - knife("data bag show encrypt box --secret #{right_secret}").should_succeed stderr: err, stdout: <<~EOM - foo: bar - id: box - EOM - end - - it "raises error if secret key is incorrect" do - expect { knife("data bag show encrypt box --secret #{wrong_secret}") }.to raise_error(Chef::EncryptedDataBagItem::DecryptionFailure) - end - end - - context "not provided secret key" do - it "shows encrypted data with a warning" do - expect(knife("data bag show encrypt box").stderr).to eq("WARNING: Encrypted data bag detected, but no secret provided for decoding. Displaying encrypted data.\n") - end - end - end - - context "with unencrypted data" do - context "provided secret key" do - it "shows unencrypted data with a warning" do - expect(knife("data bag show rocket falcon9 --secret #{right_secret}").stderr).to eq("WARNING: Unencrypted data bag detected, ignoring any provided secret options.\n") - end - end - - context "not provided secret key" do - it "shows null with an empty data bag" do - knife("data bag show canteloupe").should_succeed "\n" - end - - it "show list of items in a bag" do - knife("data bag show rocket").should_succeed <<~EOM - ariane - atlas - falcon9 - EOM - end - - it "show data of the item" do - knife("data bag show rocket falcon9").should_succeed <<~EOM - heavy: true - id: falcon9 - EOM - end - end - end - end -end diff --git a/spec/integration/knife/delete_spec.rb b/spec/integration/knife/delete_spec.rb deleted file mode 100644 index e00949e7f4..0000000000 --- a/spec/integration/knife/delete_spec.rb +++ /dev/null @@ -1,1018 +0,0 @@ -# -# Author:: John Keiser (<jkeiser@chef.io>) -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "chef/knife/delete" -require "chef/knife/list" -require "chef/knife/raw" - -describe "knife delete", :workstation do - include IntegrationSupport - include KnifeSupport - - let :everything do - <<~EOM - /clients - /clients/x.json - /cookbooks - /cookbooks/x - /cookbooks/x/metadata.rb - /data_bags - /data_bags/x - /data_bags/x/y.json - /environments - /environments/_default.json - /environments/x.json - /nodes - /nodes/x.json - /roles - /roles/x.json - /users - /users/x.json - EOM - end - - let :server_everything do - <<~EOM - /clients - /clients/chef-validator.json - /clients/chef-webui.json - /clients/x.json - /cookbooks - /cookbooks/x - /cookbooks/x/metadata.rb - /data_bags - /data_bags/x - /data_bags/x/y.json - /environments - /environments/_default.json - /environments/x.json - /nodes - /nodes/x.json - /roles - /roles/x.json - /users - /users/admin.json - /users/x.json - EOM - end - let :server_nothing do - <<~EOM - /clients - /clients/chef-validator.json - /clients/chef-webui.json - /cookbooks - /data_bags - /environments - /environments/_default.json - /nodes - /roles - /users - /users/admin.json - EOM - end - - let :nothing do - <<~EOM - /clients - /cookbooks - /data_bags - /environments - /nodes - /roles - /users - EOM - end - - when_the_chef_server "has one of each thing" do - before do - client "x", "{}" - cookbook "x", "1.0.0" - data_bag "x", { "y" => "{}" } - environment "x", "{}" - node "x", "{}" - role "x", "{}" - user "x", "{}" - end - - when_the_repository "also has one of each thing" do - before do - file "clients/x.json", {} - file "cookbooks/x/metadata.rb", "" - file "data_bags/x/y.json", {} - file "environments/_default.json", {} - file "environments/x.json", {} - file "nodes/x.json", {} - file "roles/x.json", {} - file "users/x.json", {} - end - - it "knife delete --both /cookbooks/x fails" do - knife("delete --both /cookbooks/x").should_fail <<~EOM - ERROR: /cookbooks/x (remote) must be deleted recursively! Pass -r to knife delete. - ERROR: /cookbooks/x (local) must be deleted recursively! Pass -r to knife delete. - EOM - knife("list -Rf /").should_succeed server_everything - knife("list -Rf --local /").should_succeed everything - end - - it "knife delete --both -r /cookbooks/x deletes x" do - knife("delete --both -r /cookbooks/x").should_succeed "Deleted /cookbooks/x\n" - knife("list -Rf /").should_succeed <<~EOM - /clients - /clients/chef-validator.json - /clients/chef-webui.json - /clients/x.json - /cookbooks - /data_bags - /data_bags/x - /data_bags/x/y.json - /environments - /environments/_default.json - /environments/x.json - /nodes - /nodes/x.json - /roles - /roles/x.json - /users - /users/admin.json - /users/x.json - EOM - knife("list -Rf --local /").should_succeed <<~EOM - /clients - /clients/x.json - /cookbooks - /data_bags - /data_bags/x - /data_bags/x/y.json - /environments - /environments/_default.json - /environments/x.json - /nodes - /nodes/x.json - /roles - /roles/x.json - /users - /users/x.json - EOM - end - - it "knife delete -r --local /cookbooks/x deletes x locally but not remotely" do - knife("delete -r --local /cookbooks/x").should_succeed "Deleted /cookbooks/x\n" - knife("list -Rf /").should_succeed server_everything - knife("list -Rf --local /").should_succeed <<~EOM - /clients - /clients/x.json - /cookbooks - /data_bags - /data_bags/x - /data_bags/x/y.json - /environments - /environments/_default.json - /environments/x.json - /nodes - /nodes/x.json - /roles - /roles/x.json - /users - /users/x.json - EOM - end - - it "knife delete -r /cookbooks/x deletes x remotely but not locally" do - knife("delete -r /cookbooks/x").should_succeed "Deleted /cookbooks/x\n" - knife("list -Rf /").should_succeed <<~EOM - /clients - /clients/chef-validator.json - /clients/chef-webui.json - /clients/x.json - /cookbooks - /data_bags - /data_bags/x - /data_bags/x/y.json - /environments - /environments/_default.json - /environments/x.json - /nodes - /nodes/x.json - /roles - /roles/x.json - /users - /users/admin.json - /users/x.json - EOM - knife("list -Rf --local /").should_succeed everything - end - - # TODO delete empty data bag (particularly different on local side) - context "with an empty data bag on both" do - before do - data_bag "empty", {} - directory "data_bags/empty" - end - - it "knife delete --both /data_bags/empty fails but deletes local version" do - knife("delete --both /data_bags/empty").should_fail <<~EOM - ERROR: /data_bags/empty (remote) must be deleted recursively! Pass -r to knife delete. - ERROR: /data_bags/empty (local) must be deleted recursively! Pass -r to knife delete. - EOM - knife("list -Rf /").should_succeed <<~EOM - /clients - /clients/chef-validator.json - /clients/chef-webui.json - /clients/x.json - /cookbooks - /cookbooks/x - /cookbooks/x/metadata.rb - /data_bags - /data_bags/empty - /data_bags/x - /data_bags/x/y.json - /environments - /environments/_default.json - /environments/x.json - /nodes - /nodes/x.json - /roles - /roles/x.json - /users - /users/admin.json - /users/x.json - EOM - knife("list -Rf --local /").should_succeed <<~EOM - /clients - /clients/x.json - /cookbooks - /cookbooks/x - /cookbooks/x/metadata.rb - /data_bags - /data_bags/empty - /data_bags/x - /data_bags/x/y.json - /environments - /environments/_default.json - /environments/x.json - /nodes - /nodes/x.json - /roles - /roles/x.json - /users - /users/x.json - EOM - end - end - - it "knife delete --both /data_bags/x fails" do - knife("delete --both /data_bags/x").should_fail <<~EOM - ERROR: /data_bags/x (remote) must be deleted recursively! Pass -r to knife delete. - ERROR: /data_bags/x (local) must be deleted recursively! Pass -r to knife delete. - EOM - knife("list -Rf /").should_succeed server_everything - knife("list -Rf --local /").should_succeed everything - end - - it "knife delete --both -r /data_bags/x deletes x" do - knife("delete --both -r /data_bags/x").should_succeed "Deleted /data_bags/x\n" - knife("list -Rf /").should_succeed <<~EOM - /clients - /clients/chef-validator.json - /clients/chef-webui.json - /clients/x.json - /cookbooks - /cookbooks/x - /cookbooks/x/metadata.rb - /data_bags - /environments - /environments/_default.json - /environments/x.json - /nodes - /nodes/x.json - /roles - /roles/x.json - /users - /users/admin.json - /users/x.json - EOM - knife("list -Rf --local /").should_succeed <<~EOM - /clients - /clients/x.json - /cookbooks - /cookbooks/x - /cookbooks/x/metadata.rb - /data_bags - /environments - /environments/_default.json - /environments/x.json - /nodes - /nodes/x.json - /roles - /roles/x.json - /users - /users/x.json - EOM - end - - it "knife delete --both /environments/x.json deletes x" do - knife("delete --both /environments/x.json").should_succeed "Deleted /environments/x.json\n" - knife("list -Rf /").should_succeed <<~EOM - /clients - /clients/chef-validator.json - /clients/chef-webui.json - /clients/x.json - /cookbooks - /cookbooks/x - /cookbooks/x/metadata.rb - /data_bags - /data_bags/x - /data_bags/x/y.json - /environments - /environments/_default.json - /nodes - /nodes/x.json - /roles - /roles/x.json - /users - /users/admin.json - /users/x.json - EOM - knife("list -Rf --local /").should_succeed <<~EOM - /clients - /clients/x.json - /cookbooks - /cookbooks/x - /cookbooks/x/metadata.rb - /data_bags - /data_bags/x - /data_bags/x/y.json - /environments - /environments/_default.json - /nodes - /nodes/x.json - /roles - /roles/x.json - /users - /users/x.json - EOM - end - - it "knife delete --both /roles/x.json deletes x" do - knife("delete --both /roles/x.json").should_succeed "Deleted /roles/x.json\n" - knife("list -Rf /").should_succeed <<~EOM - /clients - /clients/chef-validator.json - /clients/chef-webui.json - /clients/x.json - /cookbooks - /cookbooks/x - /cookbooks/x/metadata.rb - /data_bags - /data_bags/x - /data_bags/x/y.json - /environments - /environments/_default.json - /environments/x.json - /nodes - /nodes/x.json - /roles - /users - /users/admin.json - /users/x.json - EOM - knife("list -Rf --local /").should_succeed <<~EOM - /clients - /clients/x.json - /cookbooks - /cookbooks/x - /cookbooks/x/metadata.rb - /data_bags - /data_bags/x - /data_bags/x/y.json - /environments - /environments/_default.json - /environments/x.json - /nodes - /nodes/x.json - /roles - /users - /users/x.json - EOM - end - - it "knife delete --both /environments/_default.json fails but still deletes the local copy" do - knife("delete --both /environments/_default.json").should_fail stderr: "ERROR: /environments/_default.json (remote) cannot be deleted (default environment cannot be modified).\n", stdout: "Deleted /environments/_default.json\n" - knife("list -Rf /").should_succeed server_everything - knife("list -Rf --local /").should_succeed <<~EOM - /clients - /clients/x.json - /cookbooks - /cookbooks/x - /cookbooks/x/metadata.rb - /data_bags - /data_bags/x - /data_bags/x/y.json - /environments - /environments/x.json - /nodes - /nodes/x.json - /roles - /roles/x.json - /users - /users/x.json - EOM - end - - it "knife delete --both /environments/nonexistent.json fails" do - knife("delete --both /environments/nonexistent.json").should_fail "ERROR: /environments/nonexistent.json: No such file or directory\n" - knife("list -Rf /").should_succeed server_everything - knife("list -Rf --local /").should_succeed everything - end - - it "knife delete --both / fails" do - knife("delete --both /").should_fail <<~EOM - ERROR: / (remote) cannot be deleted. - ERROR: / (local) cannot be deleted. - EOM - knife("list -Rf /").should_succeed server_everything - knife("list -Rf --local /").should_succeed everything - end - - it "knife delete --both -r /* fails" do - knife("delete --both -r /*").should_fail <<~EOM - ERROR: / (remote) cannot be deleted. - ERROR: / (local) cannot be deleted. - ERROR: /clients (remote) cannot be deleted. - ERROR: /clients (local) cannot be deleted. - ERROR: /cookbooks (remote) cannot be deleted. - ERROR: /cookbooks (local) cannot be deleted. - ERROR: /data_bags (remote) cannot be deleted. - ERROR: /data_bags (local) cannot be deleted. - ERROR: /environments (remote) cannot be deleted. - ERROR: /environments (local) cannot be deleted. - ERROR: /nodes (remote) cannot be deleted. - ERROR: /nodes (local) cannot be deleted. - ERROR: /roles (remote) cannot be deleted. - ERROR: /roles (local) cannot be deleted. - ERROR: /users (remote) cannot be deleted. - ERROR: /users (local) cannot be deleted. - EOM - knife("list -Rf /").should_succeed server_everything - knife("list -Rf --local /").should_succeed everything - end - end - - when_the_repository "has only top-level directories" do - before do - directory "clients" - directory "cookbooks" - directory "data_bags" - directory "environments" - directory "nodes" - directory "roles" - directory "users" - end - - it "knife delete --both /cookbooks/x fails" do - knife("delete --both /cookbooks/x").should_fail "ERROR: /cookbooks/x (remote) must be deleted recursively! Pass -r to knife delete.\n" - knife("list -Rf /").should_succeed server_everything - knife("list -Rf --local /").should_succeed nothing - end - - it "knife delete --both -r /cookbooks/x deletes x" do - knife("delete --both -r /cookbooks/x").should_succeed "Deleted /cookbooks/x\n" - knife("list -Rf /").should_succeed <<~EOM - /clients - /clients/chef-validator.json - /clients/chef-webui.json - /clients/x.json - /cookbooks - /data_bags - /data_bags/x - /data_bags/x/y.json - /environments - /environments/_default.json - /environments/x.json - /nodes - /nodes/x.json - /roles - /roles/x.json - /users - /users/admin.json - /users/x.json - EOM - knife("list -Rf --local /").should_succeed nothing - end - - it "knife delete --both /data_bags/x fails" do - knife("delete --both /data_bags/x").should_fail "ERROR: /data_bags/x (remote) must be deleted recursively! Pass -r to knife delete.\n" - knife("list -Rf /").should_succeed server_everything - knife("list -Rf --local /").should_succeed nothing - end - - it "knife delete --both -r /data_bags/x deletes x" do - knife("delete --both -r /data_bags/x").should_succeed "Deleted /data_bags/x\n" - knife("list -Rf /").should_succeed <<~EOM - /clients - /clients/chef-validator.json - /clients/chef-webui.json - /clients/x.json - /cookbooks - /cookbooks/x - /cookbooks/x/metadata.rb - /data_bags - /environments - /environments/_default.json - /environments/x.json - /nodes - /nodes/x.json - /roles - /roles/x.json - /users - /users/admin.json - /users/x.json - EOM - knife("list -Rf --local /").should_succeed nothing - end - - it "knife delete --both /environments/x.json deletes x" do - knife("delete --both /environments/x.json").should_succeed "Deleted /environments/x.json\n" - knife("list -Rf /").should_succeed <<~EOM - /clients - /clients/chef-validator.json - /clients/chef-webui.json - /clients/x.json - /cookbooks - /cookbooks/x - /cookbooks/x/metadata.rb - /data_bags - /data_bags/x - /data_bags/x/y.json - /environments - /environments/_default.json - /nodes - /nodes/x.json - /roles - /roles/x.json - /users - /users/admin.json - /users/x.json - EOM - knife("list -Rf --local /").should_succeed nothing - end - - it "knife delete --both /roles/x.json deletes x" do - knife("delete --both /roles/x.json").should_succeed "Deleted /roles/x.json\n" - knife("list -Rf /").should_succeed <<~EOM - /clients - /clients/chef-validator.json - /clients/chef-webui.json - /clients/x.json - /cookbooks - /cookbooks/x - /cookbooks/x/metadata.rb - /data_bags - /data_bags/x - /data_bags/x/y.json - /environments - /environments/_default.json - /environments/x.json - /nodes - /nodes/x.json - /roles - /users - /users/admin.json - /users/x.json - EOM - knife("list -Rf --local /").should_succeed nothing - end - - it "knife delete --both /environments/_default.json fails" do - knife("delete --both /environments/_default.json").should_fail "", stderr: "ERROR: /environments/_default.json (remote) cannot be deleted (default environment cannot be modified).\n" - knife("list -Rf /").should_succeed server_everything - knife("list -Rf --local /").should_succeed nothing - end - - it "knife delete --both / fails" do - knife("delete --both /").should_fail "ERROR: / (remote) cannot be deleted.\nERROR: / (local) cannot be deleted.\n" - knife("list -Rf /").should_succeed server_everything - knife("list -Rf --local /").should_succeed nothing - end - - it "knife delete --both -r /* fails" do - knife("delete --both -r /*").should_fail <<~EOM - ERROR: / (remote) cannot be deleted. - ERROR: / (local) cannot be deleted. - ERROR: /clients (remote) cannot be deleted. - ERROR: /clients (local) cannot be deleted. - ERROR: /cookbooks (remote) cannot be deleted. - ERROR: /cookbooks (local) cannot be deleted. - ERROR: /data_bags (remote) cannot be deleted. - ERROR: /data_bags (local) cannot be deleted. - ERROR: /environments (remote) cannot be deleted. - ERROR: /environments (local) cannot be deleted. - ERROR: /nodes (remote) cannot be deleted. - ERROR: /nodes (local) cannot be deleted. - ERROR: /roles (remote) cannot be deleted. - ERROR: /roles (local) cannot be deleted. - ERROR: /users (remote) cannot be deleted. - ERROR: /users (local) cannot be deleted. - EOM - knife("list -Rf /").should_succeed server_everything - knife("list -Rf --local /").should_succeed nothing - end - - it "knife delete --both /environments/nonexistent.json fails" do - knife("delete --both /environments/nonexistent.json").should_fail "ERROR: /environments/nonexistent.json: No such file or directory\n" - knife("list -Rf /").should_succeed server_everything - knife("list -Rf --local /").should_succeed nothing - end - - context "and cwd is at the top level" do - before { cwd "." } - it "knife delete fails" do - knife("delete").should_fail "FATAL: You must specify at least one argument. If you want to delete everything in this directory, run \"knife delete --recurse .\"\n", stdout: /USAGE/ - knife("list -Rf /").should_succeed <<~EOM - clients - clients/chef-validator.json - clients/chef-webui.json - clients/x.json - cookbooks - cookbooks/x - cookbooks/x/metadata.rb - data_bags - data_bags/x - data_bags/x/y.json - environments - environments/_default.json - environments/x.json - nodes - nodes/x.json - roles - roles/x.json - users - users/admin.json - users/x.json - EOM - knife("list -Rf --local /").should_succeed <<~EOM - clients - cookbooks - data_bags - environments - nodes - roles - users - EOM - end - end - end - end - - when_the_chef_server "is empty" do - when_the_repository "has one of each thing" do - before do - file "clients/x.json", {} - file "cookbooks/x/metadata.rb", "" - file "data_bags/x/y.json", {} - file "environments/_default.json", {} - file "environments/x.json", {} - file "nodes/x.json", {} - file "roles/x.json", {} - file "users/x.json", {} - end - - it "knife delete --both /cookbooks/x fails" do - knife("delete --both /cookbooks/x").should_fail "ERROR: /cookbooks/x (local) must be deleted recursively! Pass -r to knife delete.\n" - knife("list -Rf /").should_succeed server_nothing - knife("list -Rf --local /").should_succeed everything - end - - it "knife delete --both -r /cookbooks/x deletes x" do - knife("delete --both -r /cookbooks/x").should_succeed "Deleted /cookbooks/x\n" - knife("list -Rf /").should_succeed server_nothing - knife("list -Rf --local /").should_succeed <<~EOM - /clients - /clients/x.json - /cookbooks - /data_bags - /data_bags/x - /data_bags/x/y.json - /environments - /environments/_default.json - /environments/x.json - /nodes - /nodes/x.json - /roles - /roles/x.json - /users - /users/x.json - EOM - end - - it "knife delete --both /data_bags/x fails" do - knife("delete --both /data_bags/x").should_fail "ERROR: /data_bags/x (local) must be deleted recursively! Pass -r to knife delete.\n" - knife("list -Rf /").should_succeed server_nothing - knife("list -Rf --local /").should_succeed everything - end - - it "knife delete --both -r /data_bags/x deletes x" do - knife("delete --both -r /data_bags/x").should_succeed "Deleted /data_bags/x\n" - knife("list -Rf /").should_succeed server_nothing - knife("list -Rf --local /").should_succeed <<~EOM - /clients - /clients/x.json - /cookbooks - /cookbooks/x - /cookbooks/x/metadata.rb - /data_bags - /environments - /environments/_default.json - /environments/x.json - /nodes - /nodes/x.json - /roles - /roles/x.json - /users - /users/x.json - EOM - end - - it "knife delete --both /environments/x.json deletes x" do - knife("delete --both /environments/x.json").should_succeed "Deleted /environments/x.json\n" - knife("list -Rf /").should_succeed server_nothing - knife("list -Rf --local /").should_succeed <<~EOM - /clients - /clients/x.json - /cookbooks - /cookbooks/x - /cookbooks/x/metadata.rb - /data_bags - /data_bags/x - /data_bags/x/y.json - /environments - /environments/_default.json - /nodes - /nodes/x.json - /roles - /roles/x.json - /users - /users/x.json - EOM - end - - it "knife delete --both /roles/x.json deletes x" do - knife("delete --both /roles/x.json").should_succeed "Deleted /roles/x.json\n" - knife("list -Rf /").should_succeed server_nothing - knife("list -Rf --local /").should_succeed <<~EOM - /clients - /clients/x.json - /cookbooks - /cookbooks/x - /cookbooks/x/metadata.rb - /data_bags - /data_bags/x - /data_bags/x/y.json - /environments - /environments/_default.json - /environments/x.json - /nodes - /nodes/x.json - /roles - /users - /users/x.json - EOM - end - - it "knife delete --both /environments/_default.json fails but still deletes the local copy" do - knife("delete --both /environments/_default.json").should_fail stderr: "ERROR: /environments/_default.json (remote) cannot be deleted (default environment cannot be modified).\n", stdout: "Deleted /environments/_default.json\n" - knife("list -Rf /").should_succeed server_nothing - knife("list -Rf --local /").should_succeed <<~EOM - /clients - /clients/x.json - /cookbooks - /cookbooks/x - /cookbooks/x/metadata.rb - /data_bags - /data_bags/x - /data_bags/x/y.json - /environments - /environments/x.json - /nodes - /nodes/x.json - /roles - /roles/x.json - /users - /users/x.json - EOM - end - - it "knife delete --both / fails" do - knife("delete --both /").should_fail "ERROR: / (remote) cannot be deleted.\nERROR: / (local) cannot be deleted.\n" - knife("list -Rf /").should_succeed server_nothing - knife("list -Rf --local /").should_succeed everything - end - - it "knife delete --both -r /* fails" do - knife("delete --both -r /*").should_fail <<~EOM - ERROR: / (remote) cannot be deleted. - ERROR: / (local) cannot be deleted. - ERROR: /clients (remote) cannot be deleted. - ERROR: /clients (local) cannot be deleted. - ERROR: /cookbooks (remote) cannot be deleted. - ERROR: /cookbooks (local) cannot be deleted. - ERROR: /data_bags (remote) cannot be deleted. - ERROR: /data_bags (local) cannot be deleted. - ERROR: /environments (remote) cannot be deleted. - ERROR: /environments (local) cannot be deleted. - ERROR: /nodes (remote) cannot be deleted. - ERROR: /nodes (local) cannot be deleted. - ERROR: /roles (remote) cannot be deleted. - ERROR: /roles (local) cannot be deleted. - ERROR: /users (remote) cannot be deleted. - ERROR: /users (local) cannot be deleted. - EOM - knife("list -Rf /").should_succeed server_nothing - knife("list -Rf --local /").should_succeed everything - end - - it "knife delete --both /environments/nonexistent.json fails" do - knife("delete --both /environments/nonexistent.json").should_fail "ERROR: /environments/nonexistent.json: No such file or directory\n" - knife("list -Rf /").should_succeed server_nothing - knife("list -Rf --local /").should_succeed everything - end - - context "and cwd is at the top level" do - before { cwd "." } - it "knife delete fails" do - knife("delete").should_fail "FATAL: You must specify at least one argument. If you want to delete everything in this directory, run \"knife delete --recurse .\"\n", stdout: /USAGE/ - knife("list -Rf /").should_succeed <<~EOM - clients - clients/chef-validator.json - clients/chef-webui.json - cookbooks - data_bags - environments - environments/_default.json - nodes - roles - users - users/admin.json - EOM - knife("list -Rf --local /").should_succeed <<~EOM - clients - clients/x.json - cookbooks - cookbooks/x - cookbooks/x/metadata.rb - data_bags - data_bags/x - data_bags/x/y.json - environments - environments/_default.json - environments/x.json - nodes - nodes/x.json - roles - roles/x.json - users - users/x.json - EOM - end - end - end - end - - when_the_repository "has a cookbook" do - before do - file "cookbooks/x/metadata.rb", 'version "1.0.0"' - file "cookbooks/x/onlyin1.0.0.rb", "old_text" - end - - when_the_chef_server "has a later version for the cookbook" do - before do - cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => "" } - cookbook "x", "1.0.1", { "onlyin1.0.1.rb" => "hi" } - end - - # TODO this seems wrong - it "knife delete --both -r /cookbooks/x deletes the latest version on the server and the local version" do - knife("delete --both -r /cookbooks/x").should_succeed "Deleted /cookbooks/x\n" - knife("raw /cookbooks/x").should_succeed(/1.0.0/) - knife("list --local /cookbooks").should_succeed "" - end - end - - when_the_chef_server "has an earlier version for the cookbook" do - before do - cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => "" } - cookbook "x", "0.9.9", { "onlyin0.9.9.rb" => "hi" } - end - - it "knife delete --both /cookbooks/x deletes the latest version on the server and the local version" do - knife("delete --both -r /cookbooks/x").should_succeed "Deleted /cookbooks/x\n" - knife("raw /cookbooks/x").should_succeed(/0.9.9/) - knife("list --local /cookbooks").should_succeed "" - end - end - - when_the_chef_server "has a later version for the cookbook, and no current version" do - before { cookbook "x", "1.0.1", { "onlyin1.0.1.rb" => "hi" } } - - it "knife delete --both /cookbooks/x deletes the server and client version of the cookbook" do - knife("delete --both -r /cookbooks/x").should_succeed "Deleted /cookbooks/x\n" - knife("raw /cookbooks/x").should_fail(/404/) - knife("list --local /cookbooks").should_succeed "" - end - end - - when_the_chef_server "has an earlier version for the cookbook, and no current version" do - before { cookbook "x", "0.9.9", { "onlyin0.9.9.rb" => "hi" } } - - it "knife delete --both /cookbooks/x deletes the server and client version of the cookbook" do - knife("delete --both -r /cookbooks/x").should_succeed "Deleted /cookbooks/x\n" - knife("raw /cookbooks/x").should_fail(/404/) - knife("list --local /cookbooks").should_succeed "" - end - end - end - - when_the_repository "is empty" do - when_the_chef_server "has two versions of a cookbook" do - before do - cookbook "x", "2.0.11" - cookbook "x", "11.0.0" - end - - it "knife delete deletes the latest version" do - knife("delete --both -r /cookbooks/x").should_succeed "Deleted /cookbooks/x\n" - knife("raw /cookbooks/x").should_succeed( /2.0.11/ ) - end - end - end - - when_the_chef_server "is in Enterprise mode", osc_compat: false, single_org: false do - before do - organization "foo" do - container "x", {} - group "x", {} - policy "x", "1.2.3", {} - policy_group "x", { "policies" => { "x" => { "revision_id" => "1.2.3" } } } - end - end - - before :each do - Chef::Config.chef_server_url = URI.join(Chef::Config.chef_server_url, "/organizations/foo") - end - - it "knife delete /acls/containers/environments.json fails with a reasonable error" do - knife("delete /acls/containers/environments.json").should_fail "ERROR: /acls/containers/environments.json (remote) ACLs cannot be deleted.\n" - end - - it "knife delete /containers/x.json succeeds" do - knife("delete /containers/x.json").should_succeed "Deleted /containers/x.json\n" - knife("raw /containers/x.json").should_fail(/404/) - end - - it "knife delete /groups/x.json succeeds" do - knife("delete /groups/x.json").should_succeed "Deleted /groups/x.json\n" - knife("raw /groups/x.json").should_fail(/404/) - end - - it "knife delete /policies/x-1.2.3.json succeeds" do - knife("raw /policies/x/revisions/1.2.3").should_succeed "{\n \"name\": \"x\",\n \"revision_id\": \"1.2.3\",\n \"run_list\": [\n\n ],\n \"cookbook_locks\": {\n\n }\n}\n" - knife("delete /policies/x-1.2.3.json").should_succeed "Deleted /policies/x-1.2.3.json\n" - knife("raw /policies/x/revisions/1.2.3").should_fail(/404/) - end - - it "knife delete /policy_groups/x.json succeeds" do - knife("raw /policy_groups/x").should_succeed "{\n \"uri\": \"http://127.0.0.1:8900/organizations/foo/policy_groups/x\",\n \"policies\": {\n \"x\": {\n \"revision_id\": \"1.2.3\"\n }\n }\n}\n" - knife("delete /policy_groups/x.json").should_succeed "Deleted /policy_groups/x.json\n" - knife("raw /policy_groups/x").should_fail(/404/) - end - - it "knife delete /org.json fails with a reasonable error" do - knife("delete /org.json").should_fail "ERROR: /org.json (remote) cannot be deleted.\n" - end - - it "knife delete /invitations.json fails with a reasonable error" do - knife("delete /invitations.json").should_fail "ERROR: /invitations.json (remote) cannot be deleted.\n" - end - - it "knife delete /members.json fails with a reasonable error" do - knife("delete /members.json").should_fail "ERROR: /members.json (remote) cannot be deleted.\n" - end - end -end diff --git a/spec/integration/knife/deps_spec.rb b/spec/integration/knife/deps_spec.rb deleted file mode 100644 index 9875277f14..0000000000 --- a/spec/integration/knife/deps_spec.rb +++ /dev/null @@ -1,703 +0,0 @@ -# -# Author:: John Keiser (<jkeiser@chef.io>) -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" -require "chef/knife/deps" - -describe "knife deps", :workstation do - include IntegrationSupport - include KnifeSupport - - context "local" do - when_the_repository "has a role with no run_list" do - before { file "roles/starring.json", {} } - it "knife deps reports no dependencies" do - knife("deps /roles/starring.json").should_succeed "/roles/starring.json\n" - end - end - - when_the_repository "has a role with a default run_list" do - before do - file "roles/starring.json", { "run_list" => %w{role[minor] recipe[quiche] recipe[soup::chicken]} } - file "roles/minor.json", {} - file "cookbooks/quiche/metadata.rb", 'name "quiche"' - file "cookbooks/quiche/recipes/default.rb", "" - file "cookbooks/soup/metadata.rb", 'name "soup"' - file "cookbooks/soup/recipes/chicken.rb", "" - end - it "knife deps reports all dependencies" do - knife("deps /roles/starring.json").should_succeed <<~EOM - /roles/minor.json - /cookbooks/quiche - /cookbooks/soup - /roles/starring.json - EOM - end - end - - when_the_repository "has a role with an env_run_list" do - before do - file "roles/starring.json", { "env_run_lists" => { "desert" => %w{role[minor] recipe[quiche] recipe[soup::chicken]} } } - file "roles/minor.json", {} - file "cookbooks/quiche/metadata.rb", 'name "quiche"' - file "cookbooks/quiche/recipes/default.rb", "" - file "cookbooks/soup/metadata.rb", 'name "soup"' - file "cookbooks/soup/recipes/chicken.rb", "" - end - it "knife deps reports all dependencies" do - knife("deps /roles/starring.json").should_succeed <<~EOM - /roles/minor.json - /cookbooks/quiche - /cookbooks/soup - /roles/starring.json - EOM - end - end - - when_the_repository "has a node with no environment or run_list" do - before { file "nodes/mort.json", {} } - it "knife deps reports just the node" do - knife("deps /nodes/mort.json").should_succeed "/nodes/mort.json\n" - end - end - when_the_repository "has a node with an environment" do - before do - file "environments/desert.json", {} - file "nodes/mort.json", { "chef_environment" => "desert" } - end - it "knife deps reports just the node" do - knife("deps /nodes/mort.json").should_succeed "/environments/desert.json\n/nodes/mort.json\n" - end - end - when_the_repository "has a node with roles and recipes in its run_list" do - before do - file "roles/minor.json", {} - file "cookbooks/quiche/metadata.rb", 'name "quiche"' - file "cookbooks/quiche/recipes/default.rb", "" - file "cookbooks/soup/metadata.rb", 'name "soup"' - file "cookbooks/soup/recipes/chicken.rb", "" - file "nodes/mort.json", { "run_list" => %w{role[minor] recipe[quiche] recipe[soup::chicken]} } - end - it "knife deps reports just the node" do - knife("deps /nodes/mort.json").should_succeed <<~EOM - /roles/minor.json - /cookbooks/quiche - /cookbooks/soup - /nodes/mort.json - EOM - end - end - when_the_repository "has a cookbook with no dependencies" do - before do - file "cookbooks/quiche/metadata.rb", 'name "quiche"' - file "cookbooks/quiche/recipes/default.rb", "" - end - it "knife deps reports just the cookbook" do - knife("deps /cookbooks/quiche").should_succeed "/cookbooks/quiche\n" - end - end - when_the_repository "has a cookbook with dependencies" do - before do - file "cookbooks/kettle/metadata.rb", 'name "kettle"' - file "cookbooks/quiche/metadata.rb", 'name "quiche" -depends "kettle"' - file "cookbooks/quiche/recipes/default.rb", "" - end - it "knife deps reports just the cookbook" do - knife("deps /cookbooks/quiche").should_succeed "/cookbooks/kettle\n/cookbooks/quiche\n" - end - end - when_the_repository "has a data bag" do - before { file "data_bags/bag/item.json", {} } - it "knife deps reports just the data bag" do - knife("deps /data_bags/bag/item.json").should_succeed "/data_bags/bag/item.json\n" - end - end - when_the_repository "has an environment" do - before { file "environments/desert.json", {} } - it "knife deps reports just the environment" do - knife("deps /environments/desert.json").should_succeed "/environments/desert.json\n" - end - end - when_the_repository "has a deep dependency tree" do - before do - file "roles/starring.json", { "run_list" => %w{role[minor] recipe[quiche] recipe[soup::chicken]} } - file "roles/minor.json", {} - file "cookbooks/quiche/metadata.rb", 'name "quiche"' - file "cookbooks/quiche/recipes/default.rb", "" - file "cookbooks/soup/metadata.rb", 'name "soup"' - file "cookbooks/soup/recipes/chicken.rb", "" - file "environments/desert.json", {} - file "nodes/mort.json", { "chef_environment" => "desert", "run_list" => [ "role[starring]" ] } - file "nodes/bart.json", { "run_list" => [ "role[minor]" ] } - end - - it "knife deps reports all dependencies" do - knife("deps /nodes/mort.json").should_succeed <<~EOM - /environments/desert.json - /roles/minor.json - /cookbooks/quiche - /cookbooks/soup - /roles/starring.json - /nodes/mort.json - EOM - end - it "knife deps * reports all dependencies of all things" do - knife("deps /nodes/*").should_succeed <<~EOM - /roles/minor.json - /nodes/bart.json - /environments/desert.json - /cookbooks/quiche - /cookbooks/soup - /roles/starring.json - /nodes/mort.json - EOM - end - it "knife deps a b reports all dependencies of a and b" do - knife("deps /nodes/bart.json /nodes/mort.json").should_succeed <<~EOM - /roles/minor.json - /nodes/bart.json - /environments/desert.json - /cookbooks/quiche - /cookbooks/soup - /roles/starring.json - /nodes/mort.json - EOM - end - it "knife deps --tree /* shows dependencies in a tree" do - knife("deps --tree /nodes/*").should_succeed <<~EOM - /nodes/bart.json - /roles/minor.json - /nodes/mort.json - /environments/desert.json - /roles/starring.json - /roles/minor.json - /cookbooks/quiche - /cookbooks/soup - EOM - end - it "knife deps --tree --no-recurse shows only the first level of dependencies" do - knife("deps --tree --no-recurse /nodes/*").should_succeed <<~EOM - /nodes/bart.json - /roles/minor.json - /nodes/mort.json - /environments/desert.json - /roles/starring.json - EOM - end - end - - context "circular dependencies" do - when_the_repository "has cookbooks with circular dependencies" do - before do - file "cookbooks/foo/metadata.rb", 'name "foo" -depends "bar"' - file "cookbooks/bar/metadata.rb", 'name "bar" -depends "baz"' - file "cookbooks/baz/metadata.rb", 'name "baz" -depends "foo"' - end - - it "knife deps prints each once" do - knife("deps /cookbooks/foo").should_succeed( - stdout: "/cookbooks/baz\n/cookbooks/bar\n/cookbooks/foo\n" - ) - end - it "knife deps --tree prints each once" do - knife("deps --tree /cookbooks/foo").should_succeed( - stdout: "/cookbooks/foo\n /cookbooks/bar\n /cookbooks/baz\n /cookbooks/foo\n" - ) - end - end - when_the_repository "has roles with circular dependencies" do - before do - file "roles/foo.json", { "run_list" => [ "role[bar]" ] } - file "roles/bar.json", { "run_list" => [ "role[baz]" ] } - file "roles/baz.json", { "run_list" => [ "role[foo]" ] } - file "roles/self.json", { "run_list" => [ "role[self]" ] } - end - it "knife deps prints each once" do - knife("deps /roles/foo.json /roles/self.json").should_succeed <<~EOM - /roles/baz.json - /roles/bar.json - /roles/foo.json - /roles/self.json - EOM - end - it "knife deps --tree prints each once" do - knife("deps --tree /roles/foo.json /roles/self.json") do - expect(stdout).to eq("/roles/foo.json\n /roles/bar.json\n /roles/baz.json\n /roles/foo.json\n/roles/self.json\n /roles/self.json\n") - expect(stderr).to eq("WARNING: No knife configuration file found. See https://docs.chef.io/config_rb/ for details.\n") - end - end - end - end - - context "missing objects" do - when_the_repository "is empty" do - it "knife deps /blah reports an error" do - knife("deps /blah").should_fail( - exit_code: 2, - stdout: "/blah\n", - stderr: "ERROR: /blah: No such file or directory\n" - ) - end - it "knife deps /roles/x.json reports an error" do - knife("deps /roles/x.json").should_fail( - exit_code: 2, - stdout: "/roles/x.json\n", - stderr: "ERROR: /roles/x.json: No such file or directory\n" - ) - end - it "knife deps /nodes/x.json reports an error" do - knife("deps /nodes/x.json").should_fail( - exit_code: 2, - stdout: "/nodes/x.json\n", - stderr: "ERROR: /nodes/x.json: No such file or directory\n" - ) - end - it "knife deps /environments/x.json reports an error" do - knife("deps /environments/x.json").should_fail( - exit_code: 2, - stdout: "/environments/x.json\n", - stderr: "ERROR: /environments/x.json: No such file or directory\n" - ) - end - it "knife deps /cookbooks/x reports an error" do - knife("deps /cookbooks/x").should_fail( - exit_code: 2, - stdout: "/cookbooks/x\n", - stderr: "ERROR: /cookbooks/x: No such file or directory\n" - ) - end - it "knife deps /data_bags/bag/item.json reports an error" do - knife("deps /data_bags/bag/item.json").should_fail( - exit_code: 2, - stdout: "/data_bags/bag/item.json\n", - stderr: "ERROR: /data_bags/bag/item.json: No such file or directory\n" - ) - end - end - when_the_repository "is missing a dependent cookbook" do - before do - file "roles/starring.json", { "run_list" => [ "recipe[quiche]"] } - end - it "knife deps reports the cookbook, along with an error" do - knife("deps /roles/starring.json").should_fail( - exit_code: 2, - stdout: "/cookbooks/quiche\n/roles/starring.json\n", - stderr: "ERROR: /cookbooks/quiche: No such file or directory\n" - ) - end - end - when_the_repository "is missing a dependent environment" do - before do - file "nodes/mort.json", { "chef_environment" => "desert" } - end - it "knife deps reports the environment, along with an error" do - knife("deps /nodes/mort.json").should_fail( - exit_code: 2, - stdout: "/environments/desert.json\n/nodes/mort.json\n", - stderr: "ERROR: /environments/desert.json: No such file or directory\n" - ) - end - end - when_the_repository "is missing a dependent role" do - before do - file "roles/starring.json", { "run_list" => [ "role[minor]"] } - end - it "knife deps reports the role, along with an error" do - knife("deps /roles/starring.json").should_fail( - exit_code: 2, - stdout: "/roles/minor.json\n/roles/starring.json\n", - stderr: "ERROR: /roles/minor.json: No such file or directory\n" - ) - end - end - end - context "invalid objects" do - when_the_repository "is empty" do - it "knife deps / reports itself only" do - knife("deps /").should_succeed("/\n") - end - it "knife deps /roles reports an error" do - knife("deps /roles").should_fail( - exit_code: 2, - stderr: "ERROR: /roles: No such file or directory\n", - stdout: "/roles\n" - ) - end - end - when_the_repository "has a data bag" do - before { file "data_bags/bag/item.json", "" } - it "knife deps /data_bags/bag shows no dependencies" do - knife("deps /data_bags/bag").should_succeed("/data_bags/bag\n") - end - end - when_the_repository "has a cookbook" do - before { file "cookbooks/blah/metadata.rb", 'name "blah"' } - it "knife deps on a cookbook file shows no dependencies" do - knife("deps /cookbooks/blah/metadata.rb").should_succeed( - "/cookbooks/blah/metadata.rb\n" - ) - end - end - end - end - - context "remote" do - include_context "default config options" - - when_the_chef_server "has a role with no run_list" do - before { role "starring", {} } - it "knife deps reports no dependencies" do - knife("deps --remote /roles/starring.json").should_succeed "/roles/starring.json\n" - end - end - - when_the_chef_server "has a role with a default run_list" do - before do - role "starring", { "run_list" => %w{role[minor] recipe[quiche] recipe[soup::chicken]} } - role "minor", {} - cookbook "quiche", "1.0.0", { "metadata.rb" => %Q{name "quiche"\nversion "1.0.0"\n}, "recipes" => { "default.rb" => "" } } - cookbook "soup", "1.0.0", { "metadata.rb" => %Q{name "soup"\nversion "1.0.0"\n}, "recipes" => { "chicken.rb" => "" } } - end - it "knife deps reports all dependencies" do - knife("deps --remote /roles/starring.json").should_succeed <<~EOM - /roles/minor.json - /cookbooks/quiche - /cookbooks/soup - /roles/starring.json - EOM - end - end - - when_the_chef_server "has a role with an env_run_list" do - before do - role "starring", { "env_run_lists" => { "desert" => %w{role[minor] recipe[quiche] recipe[soup::chicken]} } } - role "minor", {} - cookbook "quiche", "1.0.0", { "metadata.rb" => %Q{name "quiche"\nversion "1.0.0"\n}, "recipes" => { "default.rb" => "" } } - cookbook "soup", "1.0.0", { "metadata.rb" => %Q{name "soup"\nversion "1.0.0"\n}, "recipes" => { "chicken.rb" => "" } } - end - it "knife deps reports all dependencies" do - knife("deps --remote /roles/starring.json").should_succeed <<~EOM - /roles/minor.json - /cookbooks/quiche - /cookbooks/soup - /roles/starring.json - EOM - end - end - - when_the_chef_server "has a node with no environment or run_list" do - before { node "mort", {} } - it "knife deps reports just the node" do - knife("deps --remote /nodes/mort.json").should_succeed "/nodes/mort.json\n" - end - end - when_the_chef_server "has a node with an environment" do - before do - environment "desert", {} - node "mort", { "chef_environment" => "desert" } - end - it "knife deps reports just the node" do - knife("deps --remote /nodes/mort.json").should_succeed "/environments/desert.json\n/nodes/mort.json\n" - end - end - when_the_chef_server "has a node with roles and recipes in its run_list" do - before do - role "minor", {} - cookbook "quiche", "1.0.0", { "metadata.rb" => %Q{name "quiche"\nversion "1.0.0"\n}, "recipes" => { "default.rb" => "" } } - cookbook "soup", "1.0.0", { "metadata.rb" => %Q{name "soup"\nversion "1.0.0"\n}, "recipes" => { "chicken.rb" => "" } } - node "mort", { "run_list" => %w{role[minor] recipe[quiche] recipe[soup::chicken]} } - end - it "knife deps reports just the node" do - knife("deps --remote /nodes/mort.json").should_succeed <<~EOM - /roles/minor.json - /cookbooks/quiche - /cookbooks/soup - /nodes/mort.json - EOM - end - end - when_the_chef_server "has a cookbook with no dependencies" do - before do - cookbook "quiche", "1.0.0", { "metadata.rb" => %Q{name "quiche"\nversion "1.0.0"\n}, "recipes" => { "default.rb" => "" } } - end - it "knife deps reports just the cookbook" do - knife("deps --remote /cookbooks/quiche").should_succeed "/cookbooks/quiche\n" - end - end - when_the_chef_server "has a cookbook with dependencies" do - before do - cookbook "kettle", "1.0.0", { "metadata.rb" => %Q{name "kettle"\nversion "1.0.0"\n} } - cookbook "quiche", "1.0.0", { "metadata.rb" => 'name "quiche" -depends "kettle"', "recipes" => { "default.rb" => "" } } - end - it "knife deps reports the cookbook and its dependencies" do - knife("deps --remote /cookbooks/quiche").should_succeed "/cookbooks/kettle\n/cookbooks/quiche\n" - end - end - when_the_chef_server "has a data bag" do - before { data_bag "bag", { "item" => {} } } - it "knife deps reports just the data bag" do - knife("deps --remote /data_bags/bag/item.json").should_succeed "/data_bags/bag/item.json\n" - end - end - when_the_chef_server "has an environment" do - before { environment "desert", {} } - it "knife deps reports just the environment" do - knife("deps --remote /environments/desert.json").should_succeed "/environments/desert.json\n" - end - end - when_the_chef_server "has a deep dependency tree" do - before do - role "starring", { "run_list" => %w{role[minor] recipe[quiche] recipe[soup::chicken]} } - role "minor", {} - cookbook "quiche", "1.0.0", { "metadata.rb" => %Q{name "quiche"\nversion "1.0.0"\n}, "recipes" => { "default.rb" => "" } } - cookbook "soup", "1.0.0", { "metadata.rb" => %Q{name "soup"\nversion "1.0.0"\n}, "recipes" => { "chicken.rb" => "" } } - environment "desert", {} - node "mort", { "chef_environment" => "desert", "run_list" => [ "role[starring]" ] } - node "bart", { "run_list" => [ "role[minor]" ] } - end - - it "knife deps reports all dependencies" do - knife("deps --remote /nodes/mort.json").should_succeed <<~EOM - /environments/desert.json - /roles/minor.json - /cookbooks/quiche - /cookbooks/soup - /roles/starring.json - /nodes/mort.json - EOM - end - it "knife deps * reports all dependencies of all things" do - knife("deps --remote /nodes/*").should_succeed <<~EOM - /roles/minor.json - /nodes/bart.json - /environments/desert.json - /cookbooks/quiche - /cookbooks/soup - /roles/starring.json - /nodes/mort.json - EOM - end - it "knife deps a b reports all dependencies of a and b" do - knife("deps --remote /nodes/bart.json /nodes/mort.json").should_succeed <<~EOM - /roles/minor.json - /nodes/bart.json - /environments/desert.json - /cookbooks/quiche - /cookbooks/soup - /roles/starring.json - /nodes/mort.json - EOM - end - it "knife deps --tree /* shows dependencies in a tree" do - knife("deps --remote --tree /nodes/*").should_succeed <<~EOM - /nodes/bart.json - /roles/minor.json - /nodes/mort.json - /environments/desert.json - /roles/starring.json - /roles/minor.json - /cookbooks/quiche - /cookbooks/soup - EOM - end - it "knife deps --tree --no-recurse shows only the first level of dependencies" do - knife("deps --remote --tree --no-recurse /nodes/*").should_succeed <<~EOM - /nodes/bart.json - /roles/minor.json - /nodes/mort.json - /environments/desert.json - /roles/starring.json - EOM - end - end - - context "circular dependencies" do - when_the_chef_server "has cookbooks with circular dependencies" do - before do - cookbook "foo", "1.0.0", { "metadata.rb" => 'name "foo" -depends "bar"' } - cookbook "bar", "1.0.0", { "metadata.rb" => 'name "bar" -depends "baz"' } - cookbook "baz", "1.0.0", { "metadata.rb" => 'name "baz" -depends "foo"' } - cookbook "self", "1.0.0", { "metadata.rb" => 'name "self" -depends "self"' } - end - it "knife deps prints each once" do - knife("deps --remote /cookbooks/foo /cookbooks/self").should_succeed <<~EOM - /cookbooks/baz - /cookbooks/bar - /cookbooks/foo - /cookbooks/self - EOM - end - it "knife deps --tree prints each once" do - knife("deps --remote --tree /cookbooks/foo /cookbooks/self").should_succeed <<~EOM - /cookbooks/foo - /cookbooks/bar - /cookbooks/baz - /cookbooks/foo - /cookbooks/self - /cookbooks/self - EOM - end - end - when_the_chef_server "has roles with circular dependencies" do - before do - role "foo", { "run_list" => [ "role[bar]" ] } - role "bar", { "run_list" => [ "role[baz]" ] } - role "baz", { "run_list" => [ "role[foo]" ] } - role "self", { "run_list" => [ "role[self]" ] } - end - it "knife deps prints each once" do - knife("deps --remote /roles/foo.json /roles/self.json").should_succeed <<~EOM - /roles/baz.json - /roles/bar.json - /roles/foo.json - /roles/self.json - EOM - end - it "knife deps --tree prints each once" do - knife("deps --remote --tree /roles/foo.json /roles/self.json") do - expect(stdout).to eq("/roles/foo.json\n /roles/bar.json\n /roles/baz.json\n /roles/foo.json\n/roles/self.json\n /roles/self.json\n") - expect(stderr).to eq("WARNING: No knife configuration file found. See https://docs.chef.io/config_rb/ for details.\n") - end - end - end - end - - context "missing objects" do - when_the_chef_server "is empty" do - it "knife deps /blah reports an error" do - knife("deps --remote /blah").should_fail( - exit_code: 2, - stdout: "/blah\n", - stderr: "ERROR: /blah: No such file or directory\n" - ) - end - it "knife deps /roles/x.json reports an error" do - knife("deps --remote /roles/x.json").should_fail( - exit_code: 2, - stdout: "/roles/x.json\n", - stderr: "ERROR: /roles/x.json: No such file or directory\n" - ) - end - it "knife deps /nodes/x.json reports an error" do - knife("deps --remote /nodes/x.json").should_fail( - exit_code: 2, - stdout: "/nodes/x.json\n", - stderr: "ERROR: /nodes/x.json: No such file or directory\n" - ) - end - it "knife deps /environments/x.json reports an error" do - knife("deps --remote /environments/x.json").should_fail( - exit_code: 2, - stdout: "/environments/x.json\n", - stderr: "ERROR: /environments/x.json: No such file or directory\n" - ) - end - it "knife deps /cookbooks/x reports an error" do - knife("deps --remote /cookbooks/x").should_fail( - exit_code: 2, - stdout: "/cookbooks/x\n", - stderr: "ERROR: /cookbooks/x: No such file or directory\n" - ) - end - it "knife deps /data_bags/bag/item reports an error" do - knife("deps --remote /data_bags/bag/item.json").should_fail( - exit_code: 2, - stdout: "/data_bags/bag/item.json\n", - stderr: "ERROR: /data_bags/bag/item.json: No such file or directory\n" - ) - end - end - when_the_chef_server "is missing a dependent cookbook" do - before do - role "starring", { "run_list" => [ "recipe[quiche]"] } - end - it "knife deps reports the cookbook, along with an error" do - knife("deps --remote /roles/starring.json").should_fail( - exit_code: 2, - stdout: "/cookbooks/quiche\n/roles/starring.json\n", - stderr: "ERROR: /cookbooks/quiche: No such file or directory\n" - ) - end - end - when_the_chef_server "is missing a dependent environment" do - before do - node "mort", { "chef_environment" => "desert" } - end - it "knife deps reports the environment, along with an error" do - knife("deps --remote /nodes/mort.json").should_fail( - exit_code: 2, - stdout: "/environments/desert.json\n/nodes/mort.json\n", - stderr: "ERROR: /environments/desert.json: No such file or directory\n" - ) - end - end - when_the_chef_server "is missing a dependent role" do - before do - role "starring", { "run_list" => [ "role[minor]"] } - end - it "knife deps reports the role, along with an error" do - knife("deps --remote /roles/starring.json").should_fail( - exit_code: 2, - stdout: "/roles/minor.json\n/roles/starring.json\n", - stderr: "ERROR: /roles/minor.json: No such file or directory\n" - ) - end - end - end - context "invalid objects" do - when_the_chef_server "is empty" do - it "knife deps / reports an error" do - knife("deps --remote /").should_succeed("/\n") - end - it "knife deps /roles reports an error" do - knife("deps --remote /roles").should_succeed("/roles\n") - end - end - when_the_chef_server "has a data bag" do - before { data_bag "bag", { "item" => {} } } - it "knife deps /data_bags/bag shows no dependencies" do - knife("deps --remote /data_bags/bag").should_succeed("/data_bags/bag\n") - end - end - when_the_chef_server "has a cookbook" do - before do - cookbook "blah", "1.0.0", { "metadata.rb" => 'name "blah"' } - end - it "knife deps on a cookbook file shows no dependencies" do - knife("deps --remote /cookbooks/blah/metadata.rb").should_succeed( - "/cookbooks/blah/metadata.rb\n" - ) - end - end - end - end - - it "knife deps --no-recurse reports an error" do - knife("deps --no-recurse /").should_fail("ERROR: --no-recurse requires --tree\n") - end -end diff --git a/spec/integration/knife/diff_spec.rb b/spec/integration/knife/diff_spec.rb deleted file mode 100644 index c69573735a..0000000000 --- a/spec/integration/knife/diff_spec.rb +++ /dev/null @@ -1,605 +0,0 @@ -# -# Author:: John Keiser (<jkeiser@chef.io>) -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "chef/knife/diff" - -describe "knife diff", :workstation do - include IntegrationSupport - include KnifeSupport - - context "without versioned cookbooks" do - when_the_chef_server "has one of each thing" do - before do - client "x", "{}" - cookbook "x", "1.0.0" - data_bag "x", { "y" => "{}" } - environment "x", "{}" - node "x", "{}" - role "x", "{}" - user "x", "{}" - end - - when_the_repository "has only top-level directories" do - before do - directory "clients" - directory "cookbooks" - directory "data_bags" - directory "environments" - directory "nodes" - directory "roles" - directory "users" - end - - it "knife diff reports everything as deleted" do - knife("diff --name-status /").should_succeed <<~EOM - D\t/clients/chef-validator.json - D\t/clients/chef-webui.json - D\t/clients/x.json - D\t/cookbooks/x - D\t/data_bags/x - D\t/environments/_default.json - D\t/environments/x.json - D\t/nodes/x.json - D\t/roles/x.json - D\t/users/admin.json - D\t/users/x.json - EOM - end - end - - when_the_repository "has an identical copy of each thing" do - - before do - file "clients/chef-validator.json", { "validator" => true, "public_key" => ChefZero::PUBLIC_KEY } - file "clients/chef-webui.json", { "admin" => true, "public_key" => ChefZero::PUBLIC_KEY } - file "clients/x.json", { "public_key" => ChefZero::PUBLIC_KEY } - file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0") - file "data_bags/x/y.json", {} - file "environments/_default.json", { "description" => "The default Chef environment" } - file "environments/x.json", {} - file "nodes/x.json", { "normal" => { "tags" => [] } } - file "roles/x.json", {} - file "users/admin.json", { "admin" => true, "public_key" => ChefZero::PUBLIC_KEY } - file "users/x.json", { "public_key" => ChefZero::PUBLIC_KEY } - end - - it "knife diff reports no differences" do - knife("diff /").should_succeed "" - end - - it "knife diff /environments/nonexistent.json reports an error" do - knife("diff /environments/nonexistent.json").should_fail "ERROR: /environments/nonexistent.json: No such file or directory on remote or local\n" - end - - it "knife diff /environments/*.txt reports an error" do - knife("diff /environments/*.txt").should_fail "ERROR: /environments/*.txt: No such file or directory on remote or local\n" - end - - context "except the role file" do - before do - file "roles/x.json", <<~EOM - { - "foo": "bar" - } - EOM - end - - it "knife diff reports the role as different" do - knife("diff --name-status /").should_succeed <<~EOM - M\t/roles/x.json - EOM - end - end - - context "as well as one extra copy of each thing" do - before do - file "clients/y.json", { "public_key" => ChefZero::PUBLIC_KEY } - file "cookbooks/x/blah.rb", "" - file "cookbooks/y/metadata.rb", cb_metadata("y", "1.0.0") - file "data_bags/x/z.json", {} - file "data_bags/y/zz.json", {} - file "environments/y.json", {} - file "nodes/y.json", {} - file "roles/y.json", {} - file "users/y.json", { "public_key" => ChefZero::PUBLIC_KEY } - end - - it "knife diff reports the new files as added" do - knife("diff --name-status /").should_succeed <<~EOM - A\t/clients/y.json - A\t/cookbooks/x/blah.rb - A\t/cookbooks/y - A\t/data_bags/x/z.json - A\t/data_bags/y - A\t/environments/y.json - A\t/nodes/y.json - A\t/roles/y.json - A\t/users/y.json - EOM - end - - context "when cwd is the data_bags directory" do - before { cwd "data_bags" } - it "knife diff reports different data bags" do - knife("diff --name-status").should_succeed <<~EOM - A\tx/z.json - A\ty - EOM - end - it "knife diff * reports different data bags" do - knife("diff --name-status *").should_succeed <<~EOM - A\tx/z.json - A\ty - EOM - end - end - end - end - - when_the_repository "is empty" do - it "knife diff reports everything as deleted" do - knife("diff --name-status /").should_succeed <<~EOM - D\t/clients - D\t/cookbooks - D\t/data_bags - D\t/environments - D\t/nodes - D\t/roles - D\t/users - EOM - end - end - end - - when_the_repository "has a cookbook" do - before do - file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0") - file "cookbooks/x/onlyin1.0.0.rb", "" - end - - when_the_chef_server "has a later version for the cookbook" do - before do - cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => "" } - cookbook "x", "1.0.1", { "onlyin1.0.1.rb" => "" } - end - - it "knife diff /cookbooks/x shows differences" do - knife("diff --name-status /cookbooks/x").should_succeed <<~EOM - M\t/cookbooks/x/metadata.rb - D\t/cookbooks/x/onlyin1.0.1.rb - A\t/cookbooks/x/onlyin1.0.0.rb - EOM - end - - it "knife diff --diff-filter=MAT does not show deleted files" do - knife("diff --diff-filter=MAT --name-status /cookbooks/x").should_succeed <<~EOM - M\t/cookbooks/x/metadata.rb - A\t/cookbooks/x/onlyin1.0.0.rb - EOM - end - end - - when_the_chef_server "has an earlier version for the cookbook" do - before do - cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => "" } - cookbook "x", "0.9.9", { "onlyin0.9.9.rb" => "" } - end - it "knife diff /cookbooks/x shows no differences" do - knife("diff --name-status /cookbooks/x").should_succeed "" - end - end - - when_the_chef_server "has a later version for the cookbook, and no current version" do - before do - cookbook "x", "1.0.1", { "onlyin1.0.1.rb" => "" } - end - - it "knife diff /cookbooks/x shows the differences" do - knife("diff --name-status /cookbooks/x").should_succeed <<~EOM - M\t/cookbooks/x/metadata.rb - D\t/cookbooks/x/onlyin1.0.1.rb - A\t/cookbooks/x/onlyin1.0.0.rb - EOM - end - end - - when_the_chef_server "has an earlier version for the cookbook, and no current version" do - before do - cookbook "x", "0.9.9", { "onlyin0.9.9.rb" => "" } - end - - it "knife diff /cookbooks/x shows the differences" do - knife("diff --name-status /cookbooks/x").should_succeed <<~EOM - M\t/cookbooks/x/metadata.rb - D\t/cookbooks/x/onlyin0.9.9.rb - A\t/cookbooks/x/onlyin1.0.0.rb - EOM - end - end - end - - context "json diff tests" do - when_the_repository "has an empty environment file" do - before do - file "environments/x.json", {} - end - - when_the_chef_server "has an empty environment" do - before { environment "x", {} } - it "knife diff returns no differences" do - knife("diff /environments/x.json").should_succeed "" - end - end - when_the_chef_server "has an environment with a different value" do - before { environment "x", { "description" => "hi" } } - it "knife diff reports the difference" do - knife("diff /environments/x.json").should_succeed(/ - { -- "name": "x", -- "description": "hi" -\+ "name": "x" - } -/) - end - end - end - - when_the_repository "has an environment file with a value in it" do - before do - file "environments/x.json", { "description" => "hi" } - end - - when_the_chef_server "has an environment with the same value" do - before do - environment "x", { "description" => "hi" } - end - it "knife diff returns no differences" do - knife("diff /environments/x.json").should_succeed "" - end - end - when_the_chef_server "has an environment with no value" do - before do - environment "x", {} - end - - it "knife diff reports the difference" do - knife("diff /environments/x.json").should_succeed(/ - { -- "name": "x" -\+ "name": "x", -\+ "description": "hi" - } -/) - end - end - when_the_chef_server "has an environment with a different value" do - before do - environment "x", { "description" => "lo" } - end - it "knife diff reports the difference" do - knife("diff /environments/x.json").should_succeed(/ - { - "name": "x", -- "description": "lo" -\+ "description": "hi" - } -/) - end - end - end - end - - when_the_chef_server "has an environment" do - before { environment "x", {} } - when_the_repository "has an environment with bad JSON" do - before { file "environments/x.json", "{" } - it "knife diff reports an error and does a textual diff" do - error_text = "WARN: Parse error reading #{path_to("environments/x.json")} as JSON: parse error: premature EOF" - error_match = Regexp.new(Regexp.escape(error_text)) - knife("diff /environments/x.json").should_succeed(/- "name": "x"/, stderr: error_match) - end - end - end - end # without versioned cookbooks - - context "with versioned cookbooks" do - before { Chef::Config[:versioned_cookbooks] = true } - - when_the_chef_server "has one of each thing" do - before do - client "x", "{}" - cookbook "x", "1.0.0" - data_bag "x", { "y" => "{}" } - environment "x", "{}" - node "x", "{}" - role "x", "{}" - user "x", "{}" - end - - when_the_repository "has only top-level directories" do - before do - directory "clients" - directory "cookbooks" - directory "data_bags" - directory "environments" - directory "nodes" - directory "roles" - directory "users" - end - - it "knife diff reports everything as deleted" do - knife("diff --name-status /").should_succeed <<~EOM - D\t/clients/chef-validator.json - D\t/clients/chef-webui.json - D\t/clients/x.json - D\t/cookbooks/x-1.0.0 - D\t/data_bags/x - D\t/environments/_default.json - D\t/environments/x.json - D\t/nodes/x.json - D\t/roles/x.json - D\t/users/admin.json - D\t/users/x.json - EOM - end - end - - when_the_repository "has an identical copy of each thing" do - before do - file "clients/chef-validator.json", { "validator" => true, "public_key" => ChefZero::PUBLIC_KEY } - file "clients/chef-webui.json", { "admin" => true, "public_key" => ChefZero::PUBLIC_KEY } - file "clients/x.json", { "public_key" => ChefZero::PUBLIC_KEY } - file "cookbooks/x-1.0.0/metadata.rb", cb_metadata("x", "1.0.0") - file "data_bags/x/y.json", {} - file "environments/_default.json", { "description" => "The default Chef environment" } - file "environments/x.json", {} - file "nodes/x.json", { "normal" => { "tags" => [] } } - file "roles/x.json", {} - file "users/admin.json", { "admin" => true, "public_key" => ChefZero::PUBLIC_KEY } - file "users/x.json", { "public_key" => ChefZero::PUBLIC_KEY } - end - - it "knife diff reports no differences" do - knife("diff /").should_succeed "" - end - - it "knife diff /environments/nonexistent.json reports an error" do - knife("diff /environments/nonexistent.json").should_fail "ERROR: /environments/nonexistent.json: No such file or directory on remote or local\n" - end - - it "knife diff /environments/*.txt reports an error" do - knife("diff /environments/*.txt").should_fail "ERROR: /environments/*.txt: No such file or directory on remote or local\n" - end - - context "except the role file" do - before do - file "roles/x.json", <<~EOM - { - "foo": "bar" - } - EOM - end - - it "knife diff reports the role as different" do - knife("diff --name-status /").should_succeed <<~EOM - M\t/roles/x.json - EOM - end - end - - context "as well as one extra copy of each thing" do - before do - file "clients/y.json", {} - file "cookbooks/x-1.0.0/blah.rb", "" - file "cookbooks/x-2.0.0/metadata.rb", cb_metadata("x", "2.0.0") - file "cookbooks/y-1.0.0/metadata.rb", cb_metadata("y", "1.0.0") - file "data_bags/x/z.json", {} - file "data_bags/y/zz.json", {} - file "environments/y.json", {} - file "nodes/y.json", {} - file "roles/y.json", {} - file "users/y.json", {} - end - - it "knife diff reports the new files as added" do - knife("diff --name-status /").should_succeed <<~EOM - A\t/clients/y.json - A\t/cookbooks/x-1.0.0/blah.rb - A\t/cookbooks/x-2.0.0 - A\t/cookbooks/y-1.0.0 - A\t/data_bags/x/z.json - A\t/data_bags/y - A\t/environments/y.json - A\t/nodes/y.json - A\t/roles/y.json - A\t/users/y.json - EOM - end - - context "when cwd is the data_bags directory" do - before { cwd "data_bags" } - it "knife diff reports different data bags" do - knife("diff --name-status").should_succeed <<~EOM - A\tx/z.json - A\ty - EOM - end - it "knife diff * reports different data bags" do - knife("diff --name-status *").should_succeed <<~EOM - A\tx/z.json - A\ty - EOM - end - end - end - end - - when_the_repository "is empty" do - it "knife diff reports everything as deleted" do - knife("diff --name-status /").should_succeed <<~EOM - D\t/clients - D\t/cookbooks - D\t/data_bags - D\t/environments - D\t/nodes - D\t/roles - D\t/users - EOM - end - end - end - - when_the_repository "has a cookbook" do - before do - file "cookbooks/x-1.0.0/metadata.rb", cb_metadata("x", "1.0.0") - file "cookbooks/x-1.0.0/onlyin1.0.0.rb", "" - end - - when_the_chef_server "has a later version for the cookbook" do - before do - cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => "" } - cookbook "x", "1.0.1", { "onlyin1.0.1.rb" => "" } - end - - it "knife diff /cookbooks shows differences" do - knife("diff --name-status /cookbooks").should_succeed <<~EOM - D\t/cookbooks/x-1.0.1 - EOM - end - - it "knife diff --diff-filter=MAT does not show deleted files" do - knife("diff --diff-filter=MAT --name-status /cookbooks").should_succeed "" - end - end - - when_the_chef_server "has an earlier version for the cookbook" do - before do - cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => "" } - cookbook "x", "0.9.9", { "onlyin0.9.9.rb" => "" } - end - it "knife diff /cookbooks shows the differences" do - knife("diff --name-status /cookbooks").should_succeed "D\t/cookbooks/x-0.9.9\n" - end - end - - when_the_chef_server "has a later version for the cookbook, and no current version" do - before do - cookbook "x", "1.0.1", { "onlyin1.0.1.rb" => "" } - end - - it "knife diff /cookbooks shows the differences" do - knife("diff --name-status /cookbooks").should_succeed <<~EOM - D\t/cookbooks/x-1.0.1 - A\t/cookbooks/x-1.0.0 - EOM - end - end - - when_the_chef_server "has an earlier version for the cookbook, and no current version" do - before do - cookbook "x", "0.9.9", { "onlyin0.9.9.rb" => "" } - end - - it "knife diff /cookbooks shows the differences" do - knife("diff --name-status /cookbooks").should_succeed <<~EOM - D\t/cookbooks/x-0.9.9 - A\t/cookbooks/x-1.0.0 - EOM - end - end - end - - context "json diff tests" do - when_the_repository "has an empty environment file" do - before { file "environments/x.json", {} } - when_the_chef_server "has an empty environment" do - before { environment "x", {} } - it "knife diff returns no differences" do - knife("diff /environments/x.json").should_succeed "" - end - end - when_the_chef_server "has an environment with a different value" do - before { environment "x", { "description" => "hi" } } - it "knife diff reports the difference" do - knife("diff /environments/x.json").should_succeed(/ - { -- "name": "x", -- "description": "hi" -\+ "name": "x" - } -/) - end - end - end - - when_the_repository "has an environment file with a value in it" do - before do - file "environments/x.json", { "description" => "hi" } - end - - when_the_chef_server "has an environment with the same value" do - before do - environment "x", { "description" => "hi" } - end - it "knife diff returns no differences" do - knife("diff /environments/x.json").should_succeed "" - end - end - when_the_chef_server "has an environment with no value" do - before { environment "x", {} } - it "knife diff reports the difference" do - knife("diff /environments/x.json").should_succeed(/ - { -- "name": "x" -\+ "name": "x", -\+ "description": "hi" - } -/) - end - end - when_the_chef_server "has an environment with a different value" do - before do - environment "x", { "description" => "lo" } - end - it "knife diff reports the difference" do - knife("diff /environments/x.json").should_succeed(/ - { - "name": "x", -- "description": "lo" -\+ "description": "hi" - } -/) - end - end - end - end - - when_the_chef_server "has an environment" do - before { environment "x", {} } - when_the_repository "has an environment with bad JSON" do - before { file "environments/x.json", "{" } - it "knife diff reports an error and does a textual diff" do - error_text = "WARN: Parse error reading #{path_to("environments/x.json")} as JSON: parse error: premature EOF" - error_match = Regexp.new(Regexp.escape(error_text)) - knife("diff /environments/x.json").should_succeed(/- "name": "x"/, stderr: error_match) - end - end - end - end # without versioned cookbooks -end diff --git a/spec/integration/knife/download_spec.rb b/spec/integration/knife/download_spec.rb deleted file mode 100644 index 29200d66f2..0000000000 --- a/spec/integration/knife/download_spec.rb +++ /dev/null @@ -1,1336 +0,0 @@ -# -# Author:: John Keiser (<jkeiser@chef.io>) -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "chef/knife/download" -require "chef/knife/diff" - -describe "knife download", :workstation do - include IntegrationSupport - include KnifeSupport - - context "without versioned cookbooks" do - when_the_chef_server "has one of each thing" do - - before do - client "x", {} - cookbook "x", "1.0.0" - data_bag "x", { "y" => {} } - environment "x", {} - node "x", {} - role "x", {} - user "x", {} - end - - when_the_repository "has only top-level directories" do - before do - directory "clients" - directory "cookbooks" - directory "data_bags" - directory "environments" - directory "nodes" - directory "roles" - directory "users" - end - - it "knife download downloads everything" do - knife("download /").should_succeed <<~EOM - Created /clients/chef-validator.json - Created /clients/chef-webui.json - Created /clients/x.json - Created /cookbooks/x - Created /cookbooks/x/metadata.rb - Created /data_bags/x - Created /data_bags/x/y.json - Created /environments/_default.json - Created /environments/x.json - Created /nodes/x.json - Created /roles/x.json - Created /users/admin.json - Created /users/x.json - EOM - knife("diff --name-status /").should_succeed "" - end - end - - when_the_repository "has an identical copy of each thing" do - before do - file "clients/chef-validator.json", { "validator" => true, "public_key" => ChefZero::PUBLIC_KEY } - file "clients/chef-webui.json", { "admin" => true, "public_key" => ChefZero::PUBLIC_KEY } - file "clients/x.json", { "public_key" => ChefZero::PUBLIC_KEY } - file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0") - file "data_bags/x/y.json", {} - file "environments/_default.json", { "description" => "The default Chef environment" } - file "environments/x.json", {} - file "nodes/x.json", { "normal" => { "tags" => [] } } - file "roles/x.json", {} - file "users/admin.json", { "admin" => true, "public_key" => ChefZero::PUBLIC_KEY } - file "users/x.json", { "public_key" => ChefZero::PUBLIC_KEY } - end - - it "knife download makes no changes" do - knife("download /").should_succeed "" - knife("diff --name-status /").should_succeed "" - end - - it "knife download --purge makes no changes" do - knife("download --purge /").should_succeed "" - knife("diff --name-status /").should_succeed "" - end - - context "except the role file" do - before do - file "roles/x.json", <<~EOM - { - "chef_type": "role", - "default_attributes": { - }, - "description": "blarghle", - "env_run_lists": { - }, - "json_class": "Chef::Role", - "name": "x", - "override_attributes": { - }, - "run_list": [ - - ] - } - EOM - end - - it "knife download changes the role" do - knife("download /").should_succeed "Updated /roles/x.json\n" - knife("diff --name-status /").should_succeed "" - end - - it "knife download --no-diff does not change the role" do - knife("download --no-diff /").should_succeed "" - knife("diff --name-status /").should_succeed "M\t/roles/x.json\n" - end - end - - context "except the role file is textually different, but not ACTUALLY different" do - before do - file "roles/x.json", <<~EOM - { - "chef_type": "role", - "default_attributes": { - }, - "env_run_lists": { - }, - "json_class": "Chef::Role", - "name": "x", - "description": "", - "override_attributes": { - }, - "run_list": [ - - ] - } - EOM - end - - it "knife download / does not change anything" do - knife("download /").should_succeed "" - knife("diff --name-status /").should_succeed "" - end - end - - context "as well as one extra copy of each thing" do - before do - file "clients/y.json", { "public_key" => ChefZero::PUBLIC_KEY } - file "cookbooks/x/blah.rb", "" - file "cookbooks/y/metadata.rb", cb_metadata("x", "1.0.0") - file "data_bags/x/z.json", {} - file "data_bags/y/zz.json", {} - file "environments/y.json", {} - file "nodes/y.json", {} - file "roles/y.json", {} - file "users/y.json", { "public_key" => ChefZero::PUBLIC_KEY } - end - - it "knife download does nothing" do - knife("download /").should_succeed "" - knife("diff --name-status /").should_succeed <<~EOM - A\t/clients/y.json - A\t/cookbooks/x/blah.rb - A\t/cookbooks/y - A\t/data_bags/x/z.json - A\t/data_bags/y - A\t/environments/y.json - A\t/nodes/y.json - A\t/roles/y.json - A\t/users/y.json - EOM - end - - it "knife download --purge deletes the extra files" do - knife("download --purge /").should_succeed <<~EOM - Deleted extra entry /clients/y.json (purge is on) - Deleted extra entry /cookbooks/x/blah.rb (purge is on) - Deleted extra entry /cookbooks/y (purge is on) - Deleted extra entry /data_bags/x/z.json (purge is on) - Deleted extra entry /data_bags/y (purge is on) - Deleted extra entry /environments/y.json (purge is on) - Deleted extra entry /nodes/y.json (purge is on) - Deleted extra entry /roles/y.json (purge is on) - Deleted extra entry /users/y.json (purge is on) - EOM - knife("diff --name-status /").should_succeed "" - end - end - end - - when_the_repository "is empty" do - it "knife download creates the extra files" do - knife("download /").should_succeed <<~EOM - Created /clients - Created /clients/chef-validator.json - Created /clients/chef-webui.json - Created /clients/x.json - Created /cookbooks - Created /cookbooks/x - Created /cookbooks/x/metadata.rb - Created /data_bags - Created /data_bags/x - Created /data_bags/x/y.json - Created /environments - Created /environments/_default.json - Created /environments/x.json - Created /nodes - Created /nodes/x.json - Created /roles - Created /roles/x.json - Created /users - Created /users/admin.json - Created /users/x.json - EOM - knife("diff --name-status /").should_succeed "" - end - - it "knife download --no-diff creates the extra files" do - knife("download --no-diff /").should_succeed <<~EOM - Created /clients - Created /clients/chef-validator.json - Created /clients/chef-webui.json - Created /clients/x.json - Created /cookbooks - Created /cookbooks/x - Created /cookbooks/x/metadata.rb - Created /data_bags - Created /data_bags/x - Created /data_bags/x/y.json - Created /environments - Created /environments/_default.json - Created /environments/x.json - Created /nodes - Created /nodes/x.json - Created /roles - Created /roles/x.json - Created /users - Created /users/admin.json - Created /users/x.json - EOM - knife("diff --name-status /").should_succeed "" - end - - context "when current directory is top level" do - before do - cwd "." - end - - it "knife download with no parameters reports an error" do - knife("download").should_fail "FATAL: You must specify at least one argument. If you want to download everything in this directory, run \"knife download .\"\n", stdout: /USAGE/ - end - end - end - end - - # Test download of an item when the other end doesn't even have the container - when_the_repository "is empty" do - when_the_chef_server "has two data bag items" do - before do - data_bag "x", { "y" => {}, "z" => {} } - end - - it "knife download of one data bag item itself succeeds" do - knife("download /data_bags/x/y.json").should_succeed <<~EOM - Created /data_bags - Created /data_bags/x - Created /data_bags/x/y.json - EOM - knife("diff --name-status /data_bags").should_succeed <<~EOM - D\t/data_bags/x/z.json - EOM - end - - it "knife download /data_bags/x /data_bags/x/y.json downloads x once" do - knife("download /data_bags/x /data_bags/x/y.json").should_succeed <<~EOM - Created /data_bags - Created /data_bags/x - Created /data_bags/x/y.json - Created /data_bags/x/z.json - EOM - end - end - end - - when_the_repository "has three data bag items" do - before do - file "data_bags/x/deleted.json", <<~EOM - { - "id": "deleted" - } - EOM - file "data_bags/x/modified.json", <<~EOM - { - "id": "modified" - } - EOM - file "data_bags/x/unmodified.json", <<~EOM - { - "id": "unmodified" - } - EOM - end - - when_the_chef_server "has a modified, unmodified, added and deleted data bag item" do - before do - data_bag "x", { - "added" => {}, - "modified" => { "foo" => "bar" }, - "unmodified" => {}, - } - end - - it "knife download of the modified file succeeds" do - knife("download /data_bags/x/modified.json").should_succeed <<~EOM - Updated /data_bags/x/modified.json - EOM - knife("diff --name-status /data_bags").should_succeed <<~EOM - D\t/data_bags/x/added.json - A\t/data_bags/x/deleted.json - EOM - end - it "knife download of the unmodified file does nothing" do - knife("download /data_bags/x/unmodified.json").should_succeed "" - knife("diff --name-status /data_bags").should_succeed <<~EOM - D\t/data_bags/x/added.json - M\t/data_bags/x/modified.json - A\t/data_bags/x/deleted.json - EOM - end - it "knife download of the added file succeeds" do - knife("download /data_bags/x/added.json").should_succeed <<~EOM - Created /data_bags/x/added.json - EOM - knife("diff --name-status /data_bags").should_succeed <<~EOM - M\t/data_bags/x/modified.json - A\t/data_bags/x/deleted.json - EOM - end - it "knife download of the deleted file does nothing" do - knife("download /data_bags/x/deleted.json").should_succeed "" - knife("diff --name-status /data_bags").should_succeed <<~EOM - D\t/data_bags/x/added.json - M\t/data_bags/x/modified.json - A\t/data_bags/x/deleted.json - EOM - end - it "knife download --purge of the deleted file deletes it" do - knife("download --purge /data_bags/x/deleted.json").should_succeed <<~EOM - Deleted extra entry /data_bags/x/deleted.json (purge is on) - EOM - knife("diff --name-status /data_bags").should_succeed <<~EOM - D\t/data_bags/x/added.json - M\t/data_bags/x/modified.json - EOM - end - it "knife download of the entire data bag downloads everything" do - knife("download /data_bags/x").should_succeed <<~EOM - Created /data_bags/x/added.json - Updated /data_bags/x/modified.json - EOM - knife("diff --name-status /data_bags").should_succeed <<~EOM - A\t/data_bags/x/deleted.json - EOM - end - it "knife download --purge of the entire data bag downloads everything" do - knife("download --purge /data_bags/x").should_succeed <<~EOM - Created /data_bags/x/added.json - Updated /data_bags/x/modified.json - Deleted extra entry /data_bags/x/deleted.json (purge is on) - EOM - knife("diff --name-status /data_bags").should_succeed "" - end - context "when cwd is the /data_bags directory" do - before do - cwd "data_bags" - end - it "knife download fails" do - knife("download").should_fail "FATAL: You must specify at least one argument. If you want to download everything in this directory, run \"knife download .\"\n", stdout: /USAGE/ - end - it "knife download --purge . downloads everything" do - knife("download --purge .").should_succeed <<~EOM - Created x/added.json - Updated x/modified.json - Deleted extra entry x/deleted.json (purge is on) - EOM - knife("diff --name-status /data_bags").should_succeed "" - end - it "knife download --purge * downloads everything" do - knife("download --purge *").should_succeed <<~EOM - Created x/added.json - Updated x/modified.json - Deleted extra entry x/deleted.json (purge is on) - EOM - knife("diff --name-status /data_bags").should_succeed "" - end - end - end - end - - when_the_repository "has a cookbook" do - before do - file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0") - file "cookbooks/x/z.rb", "" - end - - when_the_chef_server "has a modified, added and deleted file for the cookbook" do - before do - cookbook "x", "1.0.0", { "metadata.rb" => cb_metadata("x", "1.0.0", "#extra content"), "y.rb" => "hi" } - end - - it "knife download of a modified file succeeds" do - knife("download /cookbooks/x/metadata.rb").should_succeed "Updated /cookbooks/x/metadata.rb\n" - knife("diff --name-status /cookbooks").should_succeed <<~EOM - D\t/cookbooks/x/y.rb - A\t/cookbooks/x/z.rb - EOM - end - it "knife download of a deleted file does nothing" do - knife("download /cookbooks/x/z.rb").should_succeed "" - knife("diff --name-status /cookbooks").should_succeed <<~EOM - M\t/cookbooks/x/metadata.rb - D\t/cookbooks/x/y.rb - A\t/cookbooks/x/z.rb - EOM - end - it "knife download --purge of a deleted file succeeds" do - knife("download --purge /cookbooks/x/z.rb").should_succeed "Deleted extra entry /cookbooks/x/z.rb (purge is on)\n" - knife("diff --name-status /cookbooks").should_succeed <<~EOM - M\t/cookbooks/x/metadata.rb - D\t/cookbooks/x/y.rb - EOM - end - it "knife download of an added file succeeds" do - knife("download /cookbooks/x/y.rb").should_succeed "Created /cookbooks/x/y.rb\n" - knife("diff --name-status /cookbooks").should_succeed <<~EOM - M\t/cookbooks/x/metadata.rb - A\t/cookbooks/x/z.rb - EOM - end - it "knife download of the cookbook itself succeeds" do - knife("download /cookbooks/x").should_succeed <<~EOM - Updated /cookbooks/x/metadata.rb - Created /cookbooks/x/y.rb - EOM - knife("diff --name-status /cookbooks").should_succeed <<~EOM - A\t/cookbooks/x/z.rb - EOM - end - it "knife download --purge of the cookbook itself succeeds" do - knife("download --purge /cookbooks/x").should_succeed <<~EOM - Updated /cookbooks/x/metadata.rb - Created /cookbooks/x/y.rb - Deleted extra entry /cookbooks/x/z.rb (purge is on) - EOM - knife("diff --name-status /cookbooks").should_succeed "" - end - end - end - - when_the_repository "has a cookbook" do - before do - file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0") - file "cookbooks/x/onlyin1.0.0.rb", "old_text" - end - - when_the_chef_server "has a later version for the cookbook" do - before do - cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => "" } - cookbook "x", "1.0.1", { "onlyin1.0.1.rb" => "hi" } - end - - it "knife download /cookbooks/x downloads the latest version" do - knife("download --purge /cookbooks/x").should_succeed <<~EOM - Updated /cookbooks/x/metadata.rb - Created /cookbooks/x/onlyin1.0.1.rb - Deleted extra entry /cookbooks/x/onlyin1.0.0.rb (purge is on) - EOM - knife("diff --name-status /cookbooks").should_succeed "" - end - end - - when_the_chef_server "has an earlier version for the cookbook" do - before do - cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => "" } - cookbook "x", "0.9.9", { "onlyin0.9.9.rb" => "hi" } - end - - it "knife download /cookbooks/x downloads the updated file" do - knife("download --purge /cookbooks/x").should_succeed <<~EOM - Updated /cookbooks/x/onlyin1.0.0.rb - EOM - knife("diff --name-status /cookbooks").should_succeed "" - end - end - - when_the_chef_server "has a later version for the cookbook, and no current version" do - before do - cookbook "x", "1.0.1", { "onlyin1.0.1.rb" => "hi" } - end - - it "knife download /cookbooks/x downloads the latest version" do - knife("download --purge /cookbooks/x").should_succeed <<~EOM - Updated /cookbooks/x/metadata.rb - Created /cookbooks/x/onlyin1.0.1.rb - Deleted extra entry /cookbooks/x/onlyin1.0.0.rb (purge is on) - EOM - knife("diff --name-status /cookbooks").should_succeed "" - end - end - - when_the_chef_server "has an earlier version for the cookbook, and no current version" do - before do - cookbook "x", "0.9.9", { "onlyin0.9.9.rb" => "hi" } - end - - it "knife download /cookbooks/x downloads the old version" do - knife("download --purge /cookbooks/x").should_succeed <<~EOM - Updated /cookbooks/x/metadata.rb - Created /cookbooks/x/onlyin0.9.9.rb - Deleted extra entry /cookbooks/x/onlyin1.0.0.rb (purge is on) - EOM - knife("diff --name-status /cookbooks").should_succeed "" - end - end - end - - when_the_chef_server "has a role" do - before do - role "x", {} - end - when_the_repository "has the role in ruby" do - before do - file "roles/x.rb", <<~EOM - name "x" - description "x" - EOM - end - - it "knife download refuses to change the role" do - knife("download /roles/x.json").should_succeed "", stderr: "WARNING: /roles/x.rb cannot be updated (can't safely update ruby files).\n" - knife("diff --name-status /roles/x.json").should_succeed "M\t/roles/x.rb\n" - end - end - end - - when_the_chef_server "has an environment" do - before do - environment "x", {} - end - when_the_repository "has an environment with bad JSON" do - before do - file "environments/x.json", "{" - end - it "knife download succeeds" do - warning = <<~EOH - WARN: Parse error reading #{path_to("environments/x.json")} as JSON: parse error: premature EOF - { - (right here) ------^ - - EOH - knife("download /environments/x.json").should_succeed "Updated /environments/x.json\n", stderr: warning - knife("diff --name-status /environments/x.json").should_succeed "" - end - end - - when_the_repository "has the same environment with the wrong name in the file" do - before do - file "environments/x.json", { "name" => "y" } - end - it "knife download succeeds" do - knife("download /environments/x.json").should_succeed "Updated /environments/x.json\n" - knife("diff --name-status /environments/x.json").should_succeed "" - end - end - - when_the_repository "has the same environment with no name in the file" do - before do - file "environments/x.json", { "description" => "hi" } - end - it "knife download succeeds" do - knife("download /environments/x.json").should_succeed "Updated /environments/x.json\n" - knife("diff --name-status /environments/x.json").should_succeed "" - end - end - end - end # without versioned cookbooks - - context "with versioned cookbooks" do - before { Chef::Config[:versioned_cookbooks] = true } - - when_the_chef_server "has one of each thing" do - before do - client "x", {} - cookbook "x", "1.0.0" - data_bag "x", { "y" => {} } - environment "x", {} - node "x", {} - role "x", {} - user "x", {} - end - - when_the_repository "has only top-level directories" do - before do - directory "clients" - directory "cookbooks" - directory "data_bags" - directory "environments" - directory "nodes" - directory "roles" - directory "users" - end - - it "knife download downloads everything" do - knife("download /").should_succeed <<~EOM - Created /clients/chef-validator.json - Created /clients/chef-webui.json - Created /clients/x.json - Created /cookbooks/x-1.0.0 - Created /cookbooks/x-1.0.0/metadata.rb - Created /data_bags/x - Created /data_bags/x/y.json - Created /environments/_default.json - Created /environments/x.json - Created /nodes/x.json - Created /roles/x.json - Created /users/admin.json - Created /users/x.json - EOM - knife("diff --name-status /").should_succeed "" - end - end - - when_the_repository "has an identical copy of each thing" do - before do - file "clients/chef-validator.json", { "validator" => true, "public_key" => ChefZero::PUBLIC_KEY } - file "clients/chef-webui.json", { "admin" => true, "public_key" => ChefZero::PUBLIC_KEY } - file "clients/x.json", { "public_key" => ChefZero::PUBLIC_KEY } - file "cookbooks/x-1.0.0/metadata.rb", cb_metadata("x", "1.0.0") - file "data_bags/x/y.json", {} - file "environments/_default.json", { "description" => "The default Chef environment" } - file "environments/x.json", {} - file "nodes/x.json", { "normal" => { "tags" => [] } } - file "roles/x.json", {} - file "users/admin.json", { "admin" => true, "public_key" => ChefZero::PUBLIC_KEY } - file "users/x.json", { "public_key" => ChefZero::PUBLIC_KEY } - end - - it "knife download makes no changes" do - knife("download /").should_succeed "" - knife("diff --name-status /").should_succeed "" - end - - it "knife download --purge makes no changes" do - knife("download --purge /").should_succeed "" - knife("diff --name-status /").should_succeed "" - end - - context "except the role file" do - before do - file "roles/x.json", { "description" => "blarghle" } - end - - it "knife download changes the role" do - knife("download /").should_succeed "Updated /roles/x.json\n" - knife("diff --name-status /").should_succeed "" - end - end - - context "except the role file is textually different, but not ACTUALLY different" do - before do - file "roles/x.json", <<~EOM - { - "chef_type": "role" , - "default_attributes": { - }, - "env_run_lists": { - }, - "json_class": "Chef::Role", - "name": "x", - "description": "", - "override_attributes": { - }, - "run_list": [ - - ] - } - EOM - end - - it "knife download / does not change anything" do - knife("download /").should_succeed "" - knife("diff --name-status /").should_succeed "" - end - end - - context "as well as one extra copy of each thing" do - before do - file "clients/y.json", { "public_key" => ChefZero::PUBLIC_KEY } - file "cookbooks/x-1.0.0/blah.rb", "" - file "cookbooks/x-2.0.0/metadata.rb", 'version "2.0.0"' - file "cookbooks/y-1.0.0/metadata.rb", 'version "1.0.0"' - file "data_bags/x/z.json", {} - file "data_bags/y/zz.json", {} - file "environments/y.json", {} - file "nodes/y.json", {} - file "roles/y.json", {} - file "users/y.json", { "public_key" => ChefZero::PUBLIC_KEY } - end - - it "knife download does nothing" do - knife("download /").should_succeed "" - knife("diff --name-status /").should_succeed <<~EOM - A\t/clients/y.json - A\t/cookbooks/x-1.0.0/blah.rb - A\t/cookbooks/x-2.0.0 - A\t/cookbooks/y-1.0.0 - A\t/data_bags/x/z.json - A\t/data_bags/y - A\t/environments/y.json - A\t/nodes/y.json - A\t/roles/y.json - A\t/users/y.json - EOM - end - - it "knife download --purge deletes the extra files" do - knife("download --purge /").should_succeed <<~EOM - Deleted extra entry /clients/y.json (purge is on) - Deleted extra entry /cookbooks/x-1.0.0/blah.rb (purge is on) - Deleted extra entry /cookbooks/x-2.0.0 (purge is on) - Deleted extra entry /cookbooks/y-1.0.0 (purge is on) - Deleted extra entry /data_bags/x/z.json (purge is on) - Deleted extra entry /data_bags/y (purge is on) - Deleted extra entry /environments/y.json (purge is on) - Deleted extra entry /nodes/y.json (purge is on) - Deleted extra entry /roles/y.json (purge is on) - Deleted extra entry /users/y.json (purge is on) - EOM - knife("diff --name-status /").should_succeed "" - end - end - end - - when_the_repository "is empty" do - it "knife download creates the extra files" do - knife("download /").should_succeed <<~EOM - Created /clients - Created /clients/chef-validator.json - Created /clients/chef-webui.json - Created /clients/x.json - Created /cookbooks - Created /cookbooks/x-1.0.0 - Created /cookbooks/x-1.0.0/metadata.rb - Created /data_bags - Created /data_bags/x - Created /data_bags/x/y.json - Created /environments - Created /environments/_default.json - Created /environments/x.json - Created /nodes - Created /nodes/x.json - Created /roles - Created /roles/x.json - Created /users - Created /users/admin.json - Created /users/x.json - EOM - knife("diff --name-status /").should_succeed "" - end - - context "when current directory is top level" do - before do - cwd "." - end - it "knife download with no parameters reports an error" do - knife("download").should_fail "FATAL: You must specify at least one argument. If you want to download everything in this directory, run \"knife download .\"\n", stdout: /USAGE/ - end - end - end - end - - # Test download of an item when the other end doesn't even have the container - when_the_repository "is empty" do - when_the_chef_server "has two data bag items" do - before do - data_bag "x", { "y" => {}, "z" => {} } - end - - it "knife download of one data bag item itself succeeds" do - knife("download /data_bags/x/y.json").should_succeed <<~EOM - Created /data_bags - Created /data_bags/x - Created /data_bags/x/y.json - EOM - knife("diff --name-status /data_bags").should_succeed <<~EOM - D\t/data_bags/x/z.json - EOM - end - end - end - - when_the_repository "has three data bag items" do - before do - file "data_bags/x/deleted.json", <<~EOM - { - "id": "deleted" - } - EOM - file "data_bags/x/modified.json", <<~EOM - { - "id": "modified" - } - EOM - file "data_bags/x/unmodified.json", <<~EOM - { - "id": "unmodified" - } - EOM - end - - when_the_chef_server "has a modified, unmodified, added and deleted data bag item" do - before do - data_bag "x", { - "added" => {}, - "modified" => { "foo" => "bar" }, - "unmodified" => {}, - } - end - - it "knife download of the modified file succeeds" do - knife("download /data_bags/x/modified.json").should_succeed <<~EOM - Updated /data_bags/x/modified.json - EOM - knife("diff --name-status /data_bags").should_succeed <<~EOM - D\t/data_bags/x/added.json - A\t/data_bags/x/deleted.json - EOM - end - it "knife download of the unmodified file does nothing" do - knife("download /data_bags/x/unmodified.json").should_succeed "" - knife("diff --name-status /data_bags").should_succeed <<~EOM - D\t/data_bags/x/added.json - M\t/data_bags/x/modified.json - A\t/data_bags/x/deleted.json - EOM - end - it "knife download of the added file succeeds" do - knife("download /data_bags/x/added.json").should_succeed <<~EOM - Created /data_bags/x/added.json - EOM - knife("diff --name-status /data_bags").should_succeed <<~EOM - M\t/data_bags/x/modified.json - A\t/data_bags/x/deleted.json - EOM - end - it "knife download of the deleted file does nothing" do - knife("download /data_bags/x/deleted.json").should_succeed "" - knife("diff --name-status /data_bags").should_succeed <<~EOM - D\t/data_bags/x/added.json - M\t/data_bags/x/modified.json - A\t/data_bags/x/deleted.json - EOM - end - it "knife download --purge of the deleted file deletes it" do - knife("download --purge /data_bags/x/deleted.json").should_succeed <<~EOM - Deleted extra entry /data_bags/x/deleted.json (purge is on) - EOM - knife("diff --name-status /data_bags").should_succeed <<~EOM - D\t/data_bags/x/added.json - M\t/data_bags/x/modified.json - EOM - end - it "knife download of the entire data bag downloads everything" do - knife("download /data_bags/x").should_succeed <<~EOM - Created /data_bags/x/added.json - Updated /data_bags/x/modified.json - EOM - knife("diff --name-status /data_bags").should_succeed <<~EOM - A\t/data_bags/x/deleted.json - EOM - end - it "knife download --purge of the entire data bag downloads everything" do - knife("download --purge /data_bags/x").should_succeed <<~EOM - Created /data_bags/x/added.json - Updated /data_bags/x/modified.json - Deleted extra entry /data_bags/x/deleted.json (purge is on) - EOM - knife("diff --name-status /data_bags").should_succeed "" - end - context "when cwd is the /data_bags directory" do - before do - cwd "data_bags" - end - it "knife download fails" do - knife("download").should_fail "FATAL: You must specify at least one argument. If you want to download everything in this directory, run \"knife download .\"\n", stdout: /USAGE/ - end - it "knife download --purge . downloads everything" do - knife("download --purge .").should_succeed <<~EOM - Created x/added.json - Updated x/modified.json - Deleted extra entry x/deleted.json (purge is on) - EOM - knife("diff --name-status /data_bags").should_succeed "" - end - it "knife download --purge * downloads everything" do - knife("download --purge *").should_succeed <<~EOM - Created x/added.json - Updated x/modified.json - Deleted extra entry x/deleted.json (purge is on) - EOM - knife("diff --name-status /data_bags").should_succeed "" - end - end - end - end - - when_the_repository "has a cookbook" do - before do - file "cookbooks/x-1.0.0/metadata.rb", 'name "x"; version "1.0.0"#unmodified' - file "cookbooks/x-1.0.0/z.rb", "" - end - - when_the_chef_server "has a modified, added and deleted file for the cookbook" do - before do - cookbook "x", "1.0.0", { "y.rb" => "hi" } - end - - it "knife download of a modified file succeeds" do - knife("download /cookbooks/x-1.0.0/metadata.rb").should_succeed "Updated /cookbooks/x-1.0.0/metadata.rb\n" - knife("diff --name-status /cookbooks").should_succeed <<~EOM - D\t/cookbooks/x-1.0.0/y.rb - A\t/cookbooks/x-1.0.0/z.rb - EOM - end - it "knife download of a deleted file does nothing" do - knife("download /cookbooks/x-1.0.0/z.rb").should_succeed "" - knife("diff --name-status /cookbooks").should_succeed <<~EOM - M\t/cookbooks/x-1.0.0/metadata.rb - D\t/cookbooks/x-1.0.0/y.rb - A\t/cookbooks/x-1.0.0/z.rb - EOM - end - it "knife download --purge of a deleted file succeeds" do - knife("download --purge /cookbooks/x-1.0.0/z.rb").should_succeed "Deleted extra entry /cookbooks/x-1.0.0/z.rb (purge is on)\n" - knife("diff --name-status /cookbooks").should_succeed <<~EOM - M\t/cookbooks/x-1.0.0/metadata.rb - D\t/cookbooks/x-1.0.0/y.rb - EOM - end - it "knife download of an added file succeeds" do - knife("download /cookbooks/x-1.0.0/y.rb").should_succeed "Created /cookbooks/x-1.0.0/y.rb\n" - knife("diff --name-status /cookbooks").should_succeed <<~EOM - M\t/cookbooks/x-1.0.0/metadata.rb - A\t/cookbooks/x-1.0.0/z.rb - EOM - end - it "knife download of the cookbook itself succeeds" do - knife("download /cookbooks/x-1.0.0").should_succeed <<~EOM - Updated /cookbooks/x-1.0.0/metadata.rb - Created /cookbooks/x-1.0.0/y.rb - EOM - knife("diff --name-status /cookbooks").should_succeed <<~EOM - A\t/cookbooks/x-1.0.0/z.rb - EOM - end - it "knife download --purge of the cookbook itself succeeds" do - knife("download --purge /cookbooks/x-1.0.0").should_succeed <<~EOM - Updated /cookbooks/x-1.0.0/metadata.rb - Created /cookbooks/x-1.0.0/y.rb - Deleted extra entry /cookbooks/x-1.0.0/z.rb (purge is on) - EOM - knife("diff --name-status /cookbooks").should_succeed "" - end - end - end - - when_the_repository "has a cookbook" do - before do - file "cookbooks/x-1.0.0/metadata.rb", cb_metadata("x", "1.0.0") - file "cookbooks/x-1.0.0/onlyin1.0.0.rb", "old_text" - end - - when_the_chef_server "has a later version for the cookbook" do - before do - cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => "" } - cookbook "x", "1.0.1", { "onlyin1.0.1.rb" => "hi" } - end - - it "knife download /cookbooks/x downloads the latest version" do - knife("download --purge /cookbooks").should_succeed <<~EOM - Updated /cookbooks/x-1.0.0/onlyin1.0.0.rb - Created /cookbooks/x-1.0.1 - Created /cookbooks/x-1.0.1/metadata.rb - Created /cookbooks/x-1.0.1/onlyin1.0.1.rb - EOM - knife("diff --name-status /cookbooks").should_succeed "" - end - end - - when_the_chef_server "has an earlier version for the cookbook" do - before do - cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => "" } - cookbook "x", "0.9.9", { "onlyin0.9.9.rb" => "hi" } - end - - it "knife download /cookbooks downloads the updated file" do - knife("download --purge /cookbooks").should_succeed <<~EOM - Created /cookbooks/x-0.9.9 - Created /cookbooks/x-0.9.9/metadata.rb - Created /cookbooks/x-0.9.9/onlyin0.9.9.rb - Updated /cookbooks/x-1.0.0/onlyin1.0.0.rb - EOM - knife("diff --name-status /cookbooks").should_succeed "" - end - end - - when_the_chef_server "has a later version for the cookbook, and no current version" do - before do - cookbook "x", "1.0.1", { "onlyin1.0.1.rb" => "hi" } - end - - it "knife download /cookbooks/x downloads the latest version" do - knife("download --purge /cookbooks").should_succeed <<~EOM - Created /cookbooks/x-1.0.1 - Created /cookbooks/x-1.0.1/metadata.rb - Created /cookbooks/x-1.0.1/onlyin1.0.1.rb - Deleted extra entry /cookbooks/x-1.0.0 (purge is on) - EOM - knife("diff --name-status /cookbooks").should_succeed "" - end - end - - when_the_chef_server "has an earlier version for the cookbook, and no current version" do - before do - cookbook "x", "0.9.9", { "onlyin0.9.9.rb" => "hi" } - end - - it "knife download --purge /cookbooks downloads the old version and deletes the new version" do - knife("download --purge /cookbooks").should_succeed <<~EOM - Created /cookbooks/x-0.9.9 - Created /cookbooks/x-0.9.9/metadata.rb - Created /cookbooks/x-0.9.9/onlyin0.9.9.rb - Deleted extra entry /cookbooks/x-1.0.0 (purge is on) - EOM - knife("diff --name-status /cookbooks").should_succeed "" - end - end - end - - when_the_chef_server "has an environment" do - before do - environment "x", {} - end - - when_the_repository "has the same environment with the wrong name in the file" do - before do - file "environments/x.json", { "name" => "y" } - end - - it "knife download succeeds" do - knife("download /environments/x.json").should_succeed "Updated /environments/x.json\n" - knife("diff --name-status /environments/x.json").should_succeed "" - end - end - - when_the_repository "has the same environment with no name in the file" do - before do - file "environments/x.json", { "description" => "hi" } - end - - it "knife download succeeds" do - knife("download /environments/x.json").should_succeed "Updated /environments/x.json\n" - knife("diff --name-status /environments/x.json").should_succeed "" - end - end - end - end # with versioned cookbooks - - when_the_chef_server "has a cookbook" do - before do - cookbook "x", "1.0.0" - end - - when_the_repository "is empty" do - it "knife download /cookbooks/x signs all requests" do - - # Check that BasicClient.request() always gets called with X-OPS-USERID - original_new = Chef::HTTP::BasicClient.method(:new) - expect(Chef::HTTP::BasicClient).to receive(:new) { |args| - new_result = original_new.call(*args) - original_request = new_result.method(:request) - expect(new_result).to receive(:request) { |method, url, body, headers, &response_handler| - expect(headers["X-OPS-USERID"]).not_to be_nil - original_request.call(method, url, body, headers, &response_handler) - }.at_least(:once) - new_result - }.at_least(:once) - - knife("download /cookbooks/x").should_succeed <<~EOM - Created /cookbooks - Created /cookbooks/x - Created /cookbooks/x/metadata.rb - EOM - end - end - end - - when_the_chef_server "is in Enterprise mode", osc_compat: false, single_org: false do - before do - user "foo", {} - user "bar", {} - user "foobar", {} - organization "foo", { "full_name" => "Something" } - end - - before :each do - Chef::Config.chef_server_url = URI.join(Chef::Config.chef_server_url, "/organizations/foo") - end - - when_the_repository "has all the default stuff" do - before do - knife("download /").should_succeed <<~EOM - Created /acls - Created /acls/clients - Created /acls/clients/foo-validator.json - Created /acls/containers - Created /acls/containers/clients.json - Created /acls/containers/containers.json - Created /acls/containers/cookbook_artifacts.json - Created /acls/containers/cookbooks.json - Created /acls/containers/data.json - Created /acls/containers/environments.json - Created /acls/containers/groups.json - Created /acls/containers/nodes.json - Created /acls/containers/policies.json - Created /acls/containers/policy_groups.json - Created /acls/containers/roles.json - Created /acls/containers/sandboxes.json - Created /acls/cookbook_artifacts - Created /acls/cookbooks - Created /acls/data_bags - Created /acls/environments - Created /acls/environments/_default.json - Created /acls/groups - Created /acls/groups/admins.json - Created /acls/groups/billing-admins.json - Created /acls/groups/clients.json - Created /acls/groups/users.json - Created /acls/nodes - Created /acls/policies - Created /acls/policy_groups - Created /acls/roles - Created /acls/organization.json - Created /clients - Created /clients/foo-validator.json - Created /containers - Created /containers/clients.json - Created /containers/containers.json - Created /containers/cookbook_artifacts.json - Created /containers/cookbooks.json - Created /containers/data.json - Created /containers/environments.json - Created /containers/groups.json - Created /containers/nodes.json - Created /containers/policies.json - Created /containers/policy_groups.json - Created /containers/roles.json - Created /containers/sandboxes.json - Created /cookbook_artifacts - Created /cookbooks - Created /data_bags - Created /environments - Created /environments/_default.json - Created /groups - Created /groups/admins.json - Created /groups/billing-admins.json - Created /groups/clients.json - Created /groups/users.json - Created /invitations.json - Created /members.json - Created /nodes - Created /org.json - Created /policies - Created /policy_groups - Created /roles - EOM - end - - context "and the server has one of each thing" do - before do - # acl_for %w(organizations foo groups blah) - client "x", {} - cookbook "x", "1.0.0" - cookbook_artifact "x", "1x1", { "metadata.rb" => cb_metadata("x", "1.0.0") } - container "x", {} - data_bag "x", { "y" => {} } - environment "x", {} - group "x", {} - org_invite "foo" - org_member "bar" - node "x", {} - policy "x", "1.0.0", {} - policy "blah", "1.0.0", {} - policy_group "x", { - "policies" => { - "x" => { "revision_id" => "1.0.0" }, - "blah" => { "revision_id" => "1.0.0" }, - }, - } - role "x", {} - end - - before do - knife("download /acls /groups/clients.json /groups/users.json").should_succeed <<~EOM - Created /acls/clients/x.json - Created /acls/containers/x.json - Created /acls/cookbook_artifacts/x.json - Created /acls/cookbooks/x.json - Created /acls/data_bags/x.json - Created /acls/environments/x.json - Created /acls/groups/x.json - Created /acls/nodes/x.json - Created /acls/policies/blah.json - Created /acls/policies/x.json - Created /acls/policy_groups/x.json - Created /acls/roles/x.json - Updated /groups/clients.json - Updated /groups/users.json - EOM - end - - it "knife download / downloads everything" do - knife("download /").should_succeed <<~EOM - Created /clients/x.json - Created /containers/x.json - Created /cookbook_artifacts/x-1x1 - Created /cookbook_artifacts/x-1x1/metadata.rb - Created /cookbooks/x - Created /cookbooks/x/metadata.rb - Created /data_bags/x - Created /data_bags/x/y.json - Created /environments/x.json - Created /groups/x.json - Updated /invitations.json - Updated /members.json - Created /nodes/x.json - Created /policies/blah-1.0.0.json - Created /policies/x-1.0.0.json - Created /policy_groups/x.json - Created /roles/x.json - EOM - knife("diff --name-status /").should_succeed "" - end - - context "and the repository has an identical copy of each thing" do - before do - # TODO We have to upload acls for an existing group due to a lack of - # dependency detection during upload. Fix that! - file "clients/x.json", { "public_key" => ChefZero::PUBLIC_KEY } - file "containers/x.json", {} - file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0") - file "cookbook_artifacts/x-1x1/metadata.rb", cb_metadata("x", "1.0.0") - file "data_bags/x/y.json", {} - file "environments/x.json", {} - file "groups/x.json", {} - file "invitations.json", [ "foo" ] - file "members.json", [ "bar" ] - file "nodes/x.json", { "normal" => { "tags" => [] } } - file "org.json", { "full_name" => "Something" } - file "policies/x-1.0.0.json", {} - file "policies/blah-1.0.0.json", {} - file "policy_groups/x.json", { "policies" => { "x" => { "revision_id" => "1.0.0" }, "blah" => { "revision_id" => "1.0.0" } } } - file "roles/x.json", {} - end - - it "knife download makes no changes" do - knife("download /").should_succeed "" - end - end - - context "and the repository has a slightly different copy of each thing" do - before do - # acl_for %w(organizations foo groups blah) - file "clients/x.json", { "validator" => true } - file "containers/x.json", {} - file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.1") - file "cookbook_artifacts/x-1x1/metadata.rb", cb_metadata("x", "1.0.1") - file "data_bags/x/y.json", { "a" => "b" } - file "environments/x.json", { "description" => "foo" } - file "groups/x.json", { "description" => "foo" } - file "groups/x.json", { "groups" => [ "admin" ] } - file "nodes/x.json", { "normal" => { "tags" => [] }, "run_list" => [ "blah" ] } - file "org.json", { "full_name" => "Something Else " } - file "policies/x-1.0.0.json", { "run_list" => [ "blah" ] } - file "policy_groups/x.json", { - "policies" => { - "x" => { "revision_id" => "1.0.1" }, - "y" => { "revision_id" => "1.0.0" }, - }, - } - file "roles/x.json", { "run_list" => [ "blah" ] } - end - - it "knife download updates everything" do - knife("download /").should_succeed <<~EOM - Updated /clients/x.json - Updated /cookbook_artifacts/x-1x1/metadata.rb - Updated /cookbooks/x/metadata.rb - Updated /data_bags/x/y.json - Updated /environments/x.json - Updated /groups/x.json - Updated /invitations.json - Updated /members.json - Updated /nodes/x.json - Updated /org.json - Created /policies/blah-1.0.0.json - Updated /policies/x-1.0.0.json - Updated /policy_groups/x.json - Updated /roles/x.json - EOM - knife("diff --name-status /").should_succeed "" - end - end - end - end - end -end diff --git a/spec/integration/knife/environment_compare_spec.rb b/spec/integration/knife/environment_compare_spec.rb deleted file mode 100644 index a8d207466a..0000000000 --- a/spec/integration/knife/environment_compare_spec.rb +++ /dev/null @@ -1,75 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife environment compare", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has some environments" do - before do - cookbook "blah", "1.0.1" - cookbook "blah", "1.1.1" - cookbook "krad", "1.1.1" - environment "x", { - "cookbook_versions" => { - "blah" => "= 1.0.0", - "krad" => ">= 1.0.0", - }, - } - environment "y", { - "cookbook_versions" => { - "blah" => "= 1.1.0", - "krad" => ">= 1.0.0", - }, - } - end - - # rubocop:disable Layout/TrailingWhitespace - it "displays the cookbooks for a single environment" do - knife("environment compare x").should_succeed <<~EOM - x - blah = 1.0.0 - krad >= 1.0.0 - - EOM - end - - it "compares the cookbooks for two environments" do - knife("environment compare x y").should_succeed <<~EOM - x y - blah = 1.0.0 = 1.1.0 - krad >= 1.0.0 >= 1.0.0 - - EOM - end - - it "compares the cookbooks for all environments" do - knife("environment compare --all").should_succeed <<~EOM - x y - blah = 1.0.0 = 1.1.0 - krad >= 1.0.0 >= 1.0.0 - - EOM - end - # rubocop:enable Layout/TrailingWhitespace - end -end diff --git a/spec/integration/knife/environment_create_spec.rb b/spec/integration/knife/environment_create_spec.rb deleted file mode 100644 index 496828073d..0000000000 --- a/spec/integration/knife/environment_create_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife environment create", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - let(:out) { "Created bah\n" } - - when_the_chef_server "is empty" do - it "creates a new environment" do - knife("environment create bah").should_succeed out - end - - it "refuses to add an existing environment" do - pending "Knife environment create must not blindly overwrite an existing environment" - knife("environment create bah").should_succeed out - expect { knife("environment create bah") }.to raise_error(Net::HTTPClientException) - end - - end -end diff --git a/spec/integration/knife/environment_delete_spec.rb b/spec/integration/knife/environment_delete_spec.rb deleted file mode 100644 index 93427aaf2f..0000000000 --- a/spec/integration/knife/environment_delete_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife environment delete", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has an environment" do - before do - environment "y", {} - end - - it "deletes an environment" do - knife("environment delete y", input: "y").should_succeed "Do you really want to delete y? (Y/N) Deleted y\n" - end - - end -end diff --git a/spec/integration/knife/environment_from_file_spec.rb b/spec/integration/knife/environment_from_file_spec.rb deleted file mode 100644 index e5ba056bb7..0000000000 --- a/spec/integration/knife/environment_from_file_spec.rb +++ /dev/null @@ -1,116 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife environment from file", :workstation do - include IntegrationSupport - include KnifeSupport - - # include_context "default config options" - - let(:env_dir) { "#{@repository_dir}/environments" } - - when_the_chef_server "is empty" do - when_the_repository "has some environments" do - before do - - file "environments/cons.json", <<~EOM - { - "name": "cons", - "description": "An environment", - "cookbook_versions": { - - }, - "json_class": "Chef::Environment", - "chef_type": "environment", - "default_attributes": { - "hola": "Amigos!" - }, - "override_attributes": { - - } - } - EOM - - file "environments/car.json", <<~EOM - { - "name": "car", - "description": "An environment for list nodes", - "cookbook_versions": { - - }, - "json_class": "Chef::Environment", - "chef_type": "environment", - "default_attributes": { - "hola": "Amigos!" - }, - "override_attributes": { - - } - } - EOM - - file "environments/cdr.json", <<~EOM - { - "name": "cdr", - "description": "An environment for last nodes", - "cookbook_versions": { - - }, - "json_class": "Chef::Environment", - "chef_type": "environment", - "default_attributes": { - "hola": "Amigos!" - }, - "override_attributes": { - - } - } - EOM - - end - - it "uploads a single file" do - knife("environment from file #{env_dir}/cons.json").should_succeed stderr: <<~EOM - Updated Environment cons - EOM - end - - it "uploads many files" do - knife("environment from file #{env_dir}/cons.json #{env_dir}/car.json #{env_dir}/cdr.json").should_succeed stderr: <<~EOM - Updated Environment cons - Updated Environment car - Updated Environment cdr - EOM - end - - it "uploads all environments in the repository" do - cwd(".") - knife("environment from file --all") - knife("environment list").should_succeed <<~EOM - _default - car - cdr - cons - EOM - end - - end - end -end diff --git a/spec/integration/knife/environment_list_spec.rb b/spec/integration/knife/environment_list_spec.rb deleted file mode 100644 index f74b2b6360..0000000000 --- a/spec/integration/knife/environment_list_spec.rb +++ /dev/null @@ -1,42 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife environment list", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has some environments" do - before do - environment "b", {} - environment "y", {} - end - - it "lists all the environments" do - knife("environment list").should_succeed <<~EOM - _default - b - y - EOM - end - - end -end diff --git a/spec/integration/knife/environment_show_spec.rb b/spec/integration/knife/environment_show_spec.rb deleted file mode 100644 index b961e85734..0000000000 --- a/spec/integration/knife/environment_show_spec.rb +++ /dev/null @@ -1,77 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife environment show", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has some environments" do - before do - environment "b", { - "default_attributes" => { "foo" => "bar", "baz" => { "raz.my" => "mataz" } }, - } - end - - # rubocop:disable Layout/TrailingWhitespace - it "shows an environment" do - knife("environment show b").should_succeed <<~EOM - chef_type: environment - cookbook_versions: - default_attributes: - baz: - raz.my: mataz - foo: bar - description: - json_class: Chef::Environment - name: b - override_attributes: - EOM - end - # rubocop:enable Layout/TrailingWhitespace - - it "shows the requested attribute of an environment" do - knife("environment show b -a default_attributes").should_succeed <<~EOM - b: - default_attributes: - baz: - raz.my: mataz - foo: bar - EOM - end - - it "shows the requested nested attribute of an environment" do - knife("environment show b -a default_attributes.baz").should_succeed <<~EON - b: - default_attributes.baz: - raz.my: mataz - EON - end - - it "shows the requested attribute of an environment with custom field separator" do - knife("environment show b -S: -a default_attributes:baz").should_succeed <<~EOT - b: - default_attributes:baz: - raz.my: mataz - EOT - end - end -end diff --git a/spec/integration/knife/list_spec.rb b/spec/integration/knife/list_spec.rb deleted file mode 100644 index 8228ba6056..0000000000 --- a/spec/integration/knife/list_spec.rb +++ /dev/null @@ -1,1060 +0,0 @@ -# -# Author:: John Keiser (<jkeiser@chef.io>) -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" -require "chef/knife/list" - -describe "knife list", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "is empty" do - it "knife list / returns all top level directories" do - knife("list /").should_succeed <<~EOM - /clients - /cookbooks - /data_bags - /environments - /nodes - /roles - /users - EOM - end - - it "knife list -R / returns everything" do - knife("list -R /").should_succeed <<~EOM - /: - clients - cookbooks - data_bags - environments - nodes - roles - users - - /clients: - chef-validator.json - chef-webui.json - - /cookbooks: - - /data_bags: - - /environments: - _default.json - - /nodes: - - /roles: - - /users: - admin.json - EOM - end - end - - when_the_chef_server "has plenty of stuff in it" do - before do - client "client1", {} - client "client2", {} - cookbook "cookbook1", "1.0.0" - cookbook "cookbook2", "1.0.1", { "recipes" => { "default.rb" => "" } } - data_bag "bag1", { "item1" => {}, "item2" => {} } - data_bag "bag2", { "item1" => {}, "item2" => {} } - environment "environment1", {} - environment "environment2", {} - node "node1", {} - node "node2", {} - policy "policy1", "1.2.3", {} - policy "policy2", "1.2.3", {} - policy "policy2", "1.3.5", {} - role "role1", {} - role "role2", {} - user "user1", {} - user "user2", {} - end - - it "knife list / returns all top level directories" do - knife("list /").should_succeed <<~EOM - /clients - /cookbooks - /data_bags - /environments - /nodes - /roles - /users - EOM - end - - it "knife list -R / returns everything" do - knife("list -R /").should_succeed <<~EOM - /: - clients - cookbooks - data_bags - environments - nodes - roles - users - - /clients: - chef-validator.json - chef-webui.json - client1.json - client2.json - - /cookbooks: - cookbook1 - cookbook2 - - /cookbooks/cookbook1: - metadata.rb - - /cookbooks/cookbook2: - metadata.rb - recipes - - /cookbooks/cookbook2/recipes: - default.rb - - /data_bags: - bag1 - bag2 - - /data_bags/bag1: - item1.json - item2.json - - /data_bags/bag2: - item1.json - item2.json - - /environments: - _default.json - environment1.json - environment2.json - - /nodes: - node1.json - node2.json - - /roles: - role1.json - role2.json - - /users: - admin.json - user1.json - user2.json - EOM - end - - it "knife list -R --flat / returns everything" do - knife("list -R --flat /").should_succeed <<~EOM - /clients - /clients/chef-validator.json - /clients/chef-webui.json - /clients/client1.json - /clients/client2.json - /cookbooks - /cookbooks/cookbook1 - /cookbooks/cookbook1/metadata.rb - /cookbooks/cookbook2 - /cookbooks/cookbook2/metadata.rb - /cookbooks/cookbook2/recipes - /cookbooks/cookbook2/recipes/default.rb - /data_bags - /data_bags/bag1 - /data_bags/bag1/item1.json - /data_bags/bag1/item2.json - /data_bags/bag2 - /data_bags/bag2/item1.json - /data_bags/bag2/item2.json - /environments - /environments/_default.json - /environments/environment1.json - /environments/environment2.json - /nodes - /nodes/node1.json - /nodes/node2.json - /roles - /roles/role1.json - /roles/role2.json - /users - /users/admin.json - /users/user1.json - /users/user2.json - EOM - end - - it "knife list -Rfp / returns everything" do - knife("list -Rfp /").should_succeed <<~EOM - /clients/ - /clients/chef-validator.json - /clients/chef-webui.json - /clients/client1.json - /clients/client2.json - /cookbooks/ - /cookbooks/cookbook1/ - /cookbooks/cookbook1/metadata.rb - /cookbooks/cookbook2/ - /cookbooks/cookbook2/metadata.rb - /cookbooks/cookbook2/recipes/ - /cookbooks/cookbook2/recipes/default.rb - /data_bags/ - /data_bags/bag1/ - /data_bags/bag1/item1.json - /data_bags/bag1/item2.json - /data_bags/bag2/ - /data_bags/bag2/item1.json - /data_bags/bag2/item2.json - /environments/ - /environments/_default.json - /environments/environment1.json - /environments/environment2.json - /nodes/ - /nodes/node1.json - /nodes/node2.json - /roles/ - /roles/role1.json - /roles/role2.json - /users/ - /users/admin.json - /users/user1.json - /users/user2.json - EOM - end - - it "knife list /cookbooks returns the list of cookbooks" do - knife("list /cookbooks").should_succeed <<~EOM - /cookbooks/cookbook1 - /cookbooks/cookbook2 - EOM - end - - it "knife list /cookbooks/*2/*/*.rb returns the one file" do - knife("list /cookbooks/*2/*/*.rb").should_succeed "/cookbooks/cookbook2/recipes/default.rb\n" - end - - it "knife list /**.rb returns all ruby files" do - knife("list /**.rb").should_succeed <<~EOM - /cookbooks/cookbook1/metadata.rb - /cookbooks/cookbook2/metadata.rb - /cookbooks/cookbook2/recipes/default.rb - EOM - end - - it "knife list /cookbooks/**.rb returns all ruby files" do - knife("list /cookbooks/**.rb").should_succeed <<~EOM - /cookbooks/cookbook1/metadata.rb - /cookbooks/cookbook2/metadata.rb - /cookbooks/cookbook2/recipes/default.rb - EOM - end - - it "knife list /**.json returns all json files" do - knife("list /**.json").should_succeed <<~EOM - /clients/chef-validator.json - /clients/chef-webui.json - /clients/client1.json - /clients/client2.json - /data_bags/bag1/item1.json - /data_bags/bag1/item2.json - /data_bags/bag2/item1.json - /data_bags/bag2/item2.json - /environments/_default.json - /environments/environment1.json - /environments/environment2.json - /nodes/node1.json - /nodes/node2.json - /roles/role1.json - /roles/role2.json - /users/admin.json - /users/user1.json - /users/user2.json - EOM - end - - it "knife list /data**.json returns all data bag json files" do - knife("list /data**.json").should_succeed <<~EOM - /data_bags/bag1/item1.json - /data_bags/bag1/item2.json - /data_bags/bag2/item1.json - /data_bags/bag2/item2.json - EOM - end - - it "knife list /environments/missing_file.json reports missing file" do - knife("list /environments/missing_file.json").should_fail "ERROR: /environments/missing_file.json: No such file or directory\n" - end - - context "missing file/directory exact match tests" do - it "knife list /blarghle reports missing directory" do - knife("list /blarghle").should_fail "ERROR: /blarghle: No such file or directory\n" - end - end - - context "symlink tests" do - when_the_repository "is empty" do - context "when cwd is at the top of the repository" do - before { cwd "." } - - it "knife list -Rfp returns everything" do - knife("list -Rfp").should_succeed <<~EOM - clients/ - clients/chef-validator.json - clients/chef-webui.json - clients/client1.json - clients/client2.json - cookbooks/ - cookbooks/cookbook1/ - cookbooks/cookbook1/metadata.rb - cookbooks/cookbook2/ - cookbooks/cookbook2/metadata.rb - cookbooks/cookbook2/recipes/ - cookbooks/cookbook2/recipes/default.rb - data_bags/ - data_bags/bag1/ - data_bags/bag1/item1.json - data_bags/bag1/item2.json - data_bags/bag2/ - data_bags/bag2/item1.json - data_bags/bag2/item2.json - environments/ - environments/_default.json - environments/environment1.json - environments/environment2.json - nodes/ - nodes/node1.json - nodes/node2.json - roles/ - roles/role1.json - roles/role2.json - users/ - users/admin.json - users/user1.json - users/user2.json - EOM - end - end - end - - when_the_repository "has a cookbooks directory" do - before { directory "cookbooks" } - context "when cwd is in cookbooks/" do - before { cwd "cookbooks" } - - it "knife list -Rfp / returns everything" do - knife("list -Rfp /").should_succeed <<~EOM - /clients/ - /clients/chef-validator.json - /clients/chef-webui.json - /clients/client1.json - /clients/client2.json - ./ - cookbook1/ - cookbook1/metadata.rb - cookbook2/ - cookbook2/metadata.rb - cookbook2/recipes/ - cookbook2/recipes/default.rb - /data_bags/ - /data_bags/bag1/ - /data_bags/bag1/item1.json - /data_bags/bag1/item2.json - /data_bags/bag2/ - /data_bags/bag2/item1.json - /data_bags/bag2/item2.json - /environments/ - /environments/_default.json - /environments/environment1.json - /environments/environment2.json - /nodes/ - /nodes/node1.json - /nodes/node2.json - /roles/ - /roles/role1.json - /roles/role2.json - /users/ - /users/admin.json - /users/user1.json - /users/user2.json - EOM - end - - it "knife list -Rfp .. returns everything" do - knife("list -Rfp ..").should_succeed <<~EOM - /clients/ - /clients/chef-validator.json - /clients/chef-webui.json - /clients/client1.json - /clients/client2.json - ./ - cookbook1/ - cookbook1/metadata.rb - cookbook2/ - cookbook2/metadata.rb - cookbook2/recipes/ - cookbook2/recipes/default.rb - /data_bags/ - /data_bags/bag1/ - /data_bags/bag1/item1.json - /data_bags/bag1/item2.json - /data_bags/bag2/ - /data_bags/bag2/item1.json - /data_bags/bag2/item2.json - /environments/ - /environments/_default.json - /environments/environment1.json - /environments/environment2.json - /nodes/ - /nodes/node1.json - /nodes/node2.json - /roles/ - /roles/role1.json - /roles/role2.json - /users/ - /users/admin.json - /users/user1.json - /users/user2.json - EOM - end - - it "knife list -Rfp returns cookbooks" do - knife("list -Rfp").should_succeed <<~EOM - cookbook1/ - cookbook1/metadata.rb - cookbook2/ - cookbook2/metadata.rb - cookbook2/recipes/ - cookbook2/recipes/default.rb - EOM - end - end - end - - when_the_repository "has a cookbooks/cookbook2 directory" do - before { directory "cookbooks/cookbook2" } - - context "when cwd is in cookbooks/cookbook2" do - before { cwd "cookbooks/cookbook2" } - - it "knife list -Rfp returns cookbooks" do - knife("list -Rfp").should_succeed <<~EOM - metadata.rb - recipes/ - recipes/default.rb - EOM - end - end - end - - when_the_repository "has a cookbooks directory and a symlinked cookbooks directory", skip: (ChefUtils.windows?) do - before do - directory "cookbooks" - symlink "symlinked", "cookbooks" - end - - context "when cwd is in cookbooks/" do - before { cwd "cookbooks" } - - it "knife list -Rfp returns cookbooks" do - knife("list -Rfp").should_succeed <<~EOM - cookbook1/ - cookbook1/metadata.rb - cookbook2/ - cookbook2/metadata.rb - cookbook2/recipes/ - cookbook2/recipes/default.rb - EOM - end - end - - context "when cwd is in symlinked/" do - before { cwd "symlinked" } - - it "knife list -Rfp returns cookbooks" do - knife("list -Rfp").should_succeed <<~EOM - cookbook1/ - cookbook1/metadata.rb - cookbook2/ - cookbook2/metadata.rb - cookbook2/recipes/ - cookbook2/recipes/default.rb - EOM - end - end - end - - when_the_repository "has a real_cookbooks directory and a cookbooks symlink to it", skip: (ChefUtils.windows?) do - before do - directory "real_cookbooks" - symlink "cookbooks", "real_cookbooks" - end - - context "when cwd is in real_cookbooks/" do - before { cwd "real_cookbooks" } - - it "knife list -Rfp returns cookbooks" do - knife("list -Rfp").should_succeed <<~EOM - cookbook1/ - cookbook1/metadata.rb - cookbook2/ - cookbook2/metadata.rb - cookbook2/recipes/ - cookbook2/recipes/default.rb - EOM - end - end - - context "when cwd is in cookbooks/" do - before { cwd "cookbooks" } - - it "knife list -Rfp returns cookbooks" do - knife("list -Rfp").should_succeed <<~EOM - cookbook1/ - cookbook1/metadata.rb - cookbook2/ - cookbook2/metadata.rb - cookbook2/recipes/ - cookbook2/recipes/default.rb - EOM - end - end - end - end - end - - context "--local" do - when_the_repository "is empty" do - it "knife list --local / returns nothing" do - knife("list --local /").should_succeed "" - end - - it "knife list /roles returns nothing" do - knife("list --local /roles").should_fail "ERROR: /roles: No such file or directory\n" - end - end - - when_the_repository "has a bunch of stuff" do - before do - file "clients/client1.json", {} - file "clients/client2.json", {} - - directory "cookbooks/cookbook1" do - file "metadata.rb", cb_metadata("cookbook1", "1.0.0") - end - directory "cookbooks/cookbook2" do - file "metadata.rb", cb_metadata("cookbook2", "2.0.0") - file "recipes/default.rb", "" - end - - directory "data_bags" do - directory "bag1" do - file "item1.json", {} - file "item2.json", {} - end - directory "bag2" do - file "item1.json", {} - file "item2.json", {} - end - end - - file "environments/environment1.json", {} - file "environments/environment2.json", {} - file "nodes/node1.json", {} - file "nodes/node2.json", {} - - file "roles/role1.json", {} - file "roles/role2.json", {} - file "users/user1.json", {} - file "users/user2.json", {} - end - - it "knife list -Rfp / returns everything" do - knife("list -Rp --local --flat /").should_succeed <<~EOM - /clients/ - /clients/client1.json - /clients/client2.json - /cookbooks/ - /cookbooks/cookbook1/ - /cookbooks/cookbook1/metadata.rb - /cookbooks/cookbook2/ - /cookbooks/cookbook2/metadata.rb - /cookbooks/cookbook2/recipes/ - /cookbooks/cookbook2/recipes/default.rb - /data_bags/ - /data_bags/bag1/ - /data_bags/bag1/item1.json - /data_bags/bag1/item2.json - /data_bags/bag2/ - /data_bags/bag2/item1.json - /data_bags/bag2/item2.json - /environments/ - /environments/environment1.json - /environments/environment2.json - /nodes/ - /nodes/node1.json - /nodes/node2.json - /roles/ - /roles/role1.json - /roles/role2.json - /users/ - /users/user1.json - /users/user2.json - EOM - end - - context "missing file/directory tests" do - it "knife list --local /blarghle reports missing directory" do - knife("list --local /blarghle").should_fail "ERROR: /blarghle: No such file or directory\n" - end - - it "knife list /roles/blarghle reports missing directory" do - knife("list --local /roles/blarghle").should_fail "ERROR: /roles/blarghle: No such file or directory\n" - end - - it "knife list /roles/blarghle/blorghle reports missing directory" do - knife("list --local /roles/blarghle/blorghle").should_fail "ERROR: /roles/blarghle/blorghle: No such file or directory\n" - end - end - end - end - - when_the_chef_server "is in Enterprise mode", osc_compat: false, single_org: false do - before do - organization "foo" - end - - before :each do - Chef::Config.chef_server_url = URI.join(Chef::Config.chef_server_url, "/organizations/foo") - end - - context "and is empty" do - it "knife list / returns all top level directories" do - knife("list /").should_succeed <<~EOM - /acls - /clients - /containers - /cookbook_artifacts - /cookbooks - /data_bags - /environments - /groups - /invitations.json - /members.json - /nodes - /org.json - /policies - /policy_groups - /roles - EOM - end - - it "knife list -R / returns everything" do - knife("list -R /").should_succeed <<~EOM - /: - acls - clients - containers - cookbook_artifacts - cookbooks - data_bags - environments - groups - invitations.json - members.json - nodes - org.json - policies - policy_groups - roles - - /acls: - clients - containers - cookbook_artifacts - cookbooks - data_bags - environments - groups - nodes - organization.json - policies - policy_groups - roles - - /acls/clients: - foo-validator.json - - /acls/containers: - clients.json - containers.json - cookbook_artifacts.json - cookbooks.json - data.json - environments.json - groups.json - nodes.json - policies.json - policy_groups.json - roles.json - sandboxes.json - - /acls/cookbook_artifacts: - - /acls/cookbooks: - - /acls/data_bags: - - /acls/environments: - _default.json - - /acls/groups: - admins.json - billing-admins.json - clients.json - users.json - - /acls/nodes: - - /acls/policies: - - /acls/policy_groups: - - /acls/roles: - - /clients: - foo-validator.json - - /containers: - clients.json - containers.json - cookbook_artifacts.json - cookbooks.json - data.json - environments.json - groups.json - nodes.json - policies.json - policy_groups.json - roles.json - sandboxes.json - - /cookbook_artifacts: - - /cookbooks: - - /data_bags: - - /environments: - _default.json - - /groups: - admins.json - billing-admins.json - clients.json - users.json - - /nodes: - - /policies: - - /policy_groups: - - /roles: - EOM - end - end - - it "knife list -R / returns everything" do - knife("list -R /").should_succeed <<~EOM - /: - acls - clients - containers - cookbook_artifacts - cookbooks - data_bags - environments - groups - invitations.json - members.json - nodes - org.json - policies - policy_groups - roles - - /acls: - clients - containers - cookbook_artifacts - cookbooks - data_bags - environments - groups - nodes - organization.json - policies - policy_groups - roles - - /acls/clients: - foo-validator.json - - /acls/containers: - clients.json - containers.json - cookbook_artifacts.json - cookbooks.json - data.json - environments.json - groups.json - nodes.json - policies.json - policy_groups.json - roles.json - sandboxes.json - - /acls/cookbook_artifacts: - - /acls/cookbooks: - - /acls/data_bags: - - /acls/environments: - _default.json - - /acls/groups: - admins.json - billing-admins.json - clients.json - users.json - - /acls/nodes: - - /acls/policies: - - /acls/policy_groups: - - /acls/roles: - - /clients: - foo-validator.json - - /containers: - clients.json - containers.json - cookbook_artifacts.json - cookbooks.json - data.json - environments.json - groups.json - nodes.json - policies.json - policy_groups.json - roles.json - sandboxes.json - - /cookbook_artifacts: - - /cookbooks: - - /data_bags: - - /environments: - _default.json - - /groups: - admins.json - billing-admins.json - clients.json - users.json - - /nodes: - - /policies: - - /policy_groups: - - /roles: - EOM - end - - context "has plenty of stuff in it" do - before do - client "client1", {} - client "client2", {} - container "container1", {} - container "container2", {} - cookbook "cookbook1", "1.0.0" - cookbook "cookbook2", "1.0.1", { "recipes" => { "default.rb" => "" } } - cookbook_artifact "cookbook_artifact1", "1x1" - cookbook_artifact "cookbook_artifact2", "2x2", { "recipes" => { "default.rb" => "" } } - data_bag "bag1", { "item1" => {}, "item2" => {} } - data_bag "bag2", { "item1" => {}, "item2" => {} } - environment "environment1", {} - environment "environment2", {} - group "group1", {} - group "group2", {} - node "node1", {} - node "node2", {} - org_invite "user1" - org_member "user2" - policy "policy1", "1.2.3", {} - policy "policy2", "1.2.3", {} - policy "policy2", "1.3.5", {} - policy_group "policy_group1", { "policies" => { "policy1" => { "revision_id" => "1.2.3" } } } - policy_group "policy_group2", { "policies" => { "policy2" => { "revision_id" => "1.3.5" } } } - role "role1", {} - role "role2", {} - user "user1", {} - user "user2", {} - end - - it "knife list -Rfp / returns everything" do - knife("list -Rfp /").should_succeed <<~EOM - /acls/ - /acls/clients/ - /acls/clients/client1.json - /acls/clients/client2.json - /acls/clients/foo-validator.json - /acls/containers/ - /acls/containers/clients.json - /acls/containers/container1.json - /acls/containers/container2.json - /acls/containers/containers.json - /acls/containers/cookbook_artifacts.json - /acls/containers/cookbooks.json - /acls/containers/data.json - /acls/containers/environments.json - /acls/containers/groups.json - /acls/containers/nodes.json - /acls/containers/policies.json - /acls/containers/policy_groups.json - /acls/containers/roles.json - /acls/containers/sandboxes.json - /acls/cookbook_artifacts/ - /acls/cookbook_artifacts/cookbook_artifact1.json - /acls/cookbook_artifacts/cookbook_artifact2.json - /acls/cookbooks/ - /acls/cookbooks/cookbook1.json - /acls/cookbooks/cookbook2.json - /acls/data_bags/ - /acls/data_bags/bag1.json - /acls/data_bags/bag2.json - /acls/environments/ - /acls/environments/_default.json - /acls/environments/environment1.json - /acls/environments/environment2.json - /acls/groups/ - /acls/groups/admins.json - /acls/groups/billing-admins.json - /acls/groups/clients.json - /acls/groups/group1.json - /acls/groups/group2.json - /acls/groups/users.json - /acls/nodes/ - /acls/nodes/node1.json - /acls/nodes/node2.json - /acls/organization.json - /acls/policies/ - /acls/policies/policy1.json - /acls/policies/policy2.json - /acls/policy_groups/ - /acls/policy_groups/policy_group1.json - /acls/policy_groups/policy_group2.json - /acls/roles/ - /acls/roles/role1.json - /acls/roles/role2.json - /clients/ - /clients/client1.json - /clients/client2.json - /clients/foo-validator.json - /containers/ - /containers/clients.json - /containers/container1.json - /containers/container2.json - /containers/containers.json - /containers/cookbook_artifacts.json - /containers/cookbooks.json - /containers/data.json - /containers/environments.json - /containers/groups.json - /containers/nodes.json - /containers/policies.json - /containers/policy_groups.json - /containers/roles.json - /containers/sandboxes.json - /cookbook_artifacts/ - /cookbook_artifacts/cookbook_artifact1-1x1/ - /cookbook_artifacts/cookbook_artifact1-1x1/metadata.rb - /cookbook_artifacts/cookbook_artifact2-2x2/ - /cookbook_artifacts/cookbook_artifact2-2x2/metadata.rb - /cookbook_artifacts/cookbook_artifact2-2x2/recipes/ - /cookbook_artifacts/cookbook_artifact2-2x2/recipes/default.rb - /cookbooks/ - /cookbooks/cookbook1/ - /cookbooks/cookbook1/metadata.rb - /cookbooks/cookbook2/ - /cookbooks/cookbook2/metadata.rb - /cookbooks/cookbook2/recipes/ - /cookbooks/cookbook2/recipes/default.rb - /data_bags/ - /data_bags/bag1/ - /data_bags/bag1/item1.json - /data_bags/bag1/item2.json - /data_bags/bag2/ - /data_bags/bag2/item1.json - /data_bags/bag2/item2.json - /environments/ - /environments/_default.json - /environments/environment1.json - /environments/environment2.json - /groups/ - /groups/admins.json - /groups/billing-admins.json - /groups/clients.json - /groups/group1.json - /groups/group2.json - /groups/users.json - /invitations.json - /members.json - /nodes/ - /nodes/node1.json - /nodes/node2.json - /org.json - /policies/ - /policies/policy1-1.2.3.json - /policies/policy2-1.2.3.json - /policies/policy2-1.3.5.json - /policy_groups/ - /policy_groups/policy_group1.json - /policy_groups/policy_group2.json - /roles/ - /roles/role1.json - /roles/role2.json - EOM - end - end - end -end diff --git a/spec/integration/knife/node_bulk_delete_spec.rb b/spec/integration/knife/node_bulk_delete_spec.rb deleted file mode 100644 index 8784b5ea8a..0000000000 --- a/spec/integration/knife/node_bulk_delete_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife node bulk delete", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has some nodes" do - before do - node "cons", {} - node "car", {} - node "cdr", {} - node "cat", {} - end - - it "deletes all matching nodes" do - knife("node bulk delete ^ca.*", input: "Y").should_succeed <<~EOM - The following nodes will be deleted: - - car cat - - Are you sure you want to delete these nodes? (Y/N) Deleted node car - Deleted node cat - EOM - - knife("node list").should_succeed <<~EOM - cdr - cons - EOM - end - end - -end diff --git a/spec/integration/knife/node_create_spec.rb b/spec/integration/knife/node_create_spec.rb deleted file mode 100644 index d3debb8f00..0000000000 --- a/spec/integration/knife/node_create_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" -require "openssl" - -describe "knife node create", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - let(:out) { "Created node[bah]\n" } - - when_the_chef_server "is empty" do - it "creates a new node" do - knife("node create bah").should_succeed out - end - - it "creates a new validator node" do - knife("node create bah").should_succeed out - knife("node show bah").should_succeed(/Node Name: bah/) - end - - it "refuses to add an existing node" do - pending "Knife node create must not blindly overwrite an existing node" - knife("node create bah").should_succeed out - expect { knife("node create bah") }.to raise_error(Net::HTTPClientException) - end - - end -end diff --git a/spec/integration/knife/node_delete_spec.rb b/spec/integration/knife/node_delete_spec.rb deleted file mode 100644 index 3cece6ebaf..0000000000 --- a/spec/integration/knife/node_delete_spec.rb +++ /dev/null @@ -1,48 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife node delete", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has some nodes" do - before do - node "cons", {} - node "car", {} - node "cdr", {} - node "cat", {} - end - - it "deletes a node" do - knife("node delete car", input: "Y").should_succeed <<~EOM - Do you really want to delete car? (Y/N) Deleted node[car] - EOM - - knife("node list").should_succeed <<~EOM - cat - cdr - cons - EOM - end - - end -end diff --git a/spec/integration/knife/node_environment_set_spec.rb b/spec/integration/knife/node_environment_set_spec.rb deleted file mode 100644 index 51b288fe39..0000000000 --- a/spec/integration/knife/node_environment_set_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife node environment set", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has a node and an environment" do - before do - node "cons", {} - environment "lisp", {} - end - - it "sets an environment on a node" do - knife("node environment set cons lisp").should_succeed(/chef_environment:.*lisp/) - knife("node show cons -a chef_environment").should_succeed <<~EOM - cons: - chef_environment: lisp - EOM - end - - it "with no environment" do - knife("node environment set adam").should_fail stderr: "FATAL: You must specify a node name and an environment.\n", - stdout: /^USAGE: knife node environment set NODE ENVIRONMENT\n/ - end - end -end diff --git a/spec/integration/knife/node_from_file_spec.rb b/spec/integration/knife/node_from_file_spec.rb deleted file mode 100644 index 5dcaaaa463..0000000000 --- a/spec/integration/knife/node_from_file_spec.rb +++ /dev/null @@ -1,59 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife node from file", :workstation do - include IntegrationSupport - include KnifeSupport - - # include_context "default config options" - - let(:node_dir) { "#{@repository_dir}/nodes" } - - when_the_chef_server "is empty" do - when_the_repository "has some nodes" do - before do - - file "nodes/cons.json", <<~EOM - { - "name": "cons", - "chef_environment": "_default", - "run_list": [ - "recipe[cons]" - ] - , - "normal": { - "tags": [ - - ] - } - } - EOM - - end - - it "uploads a single file" do - knife("node from file #{node_dir}/cons.json").should_succeed stderr: <<~EOM - Updated Node cons - EOM - end - - end - end -end diff --git a/spec/integration/knife/node_list_spec.rb b/spec/integration/knife/node_list_spec.rb deleted file mode 100644 index 65c201be3f..0000000000 --- a/spec/integration/knife/node_list_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife node list", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has some nodes" do - before do - node "cons", {} - node "car", {} - node "cdr", {} - node "cat", {} - end - - it "lists all cookbooks" do - knife("node list").should_succeed <<~EOM - car - cat - cdr - cons - EOM - end - - end -end diff --git a/spec/integration/knife/node_run_list_add_spec.rb b/spec/integration/knife/node_run_list_add_spec.rb deleted file mode 100644 index 72b5328b17..0000000000 --- a/spec/integration/knife/node_run_list_add_spec.rb +++ /dev/null @@ -1,54 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife node run list add", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has a node with no run_list" do - before do - node "cons", {} - end - - it "sets the run list" do - knife("node run list add cons recipe[foo]").should_succeed(/run_list:\s*recipe\[foo\]\n/) - end - end - - when_the_chef_server "has a node with a run_list" do - before do - node "cons", { run_list: ["recipe[bar]"] } - end - - it "appends to the run list" do - knife("node run list add cons recipe[foo]").should_succeed(/run_list:\n\s*recipe\[bar\]\n\s*recipe\[foo\]\n/m) - end - - it "adds to the run list before the specified item" do - knife("node run list add cons -b recipe[bar] recipe[foo]").should_succeed(/run_list:\n\s*recipe\[foo\]\n\s*recipe\[bar\]\n/m) - end - - it "adds to the run list after the specified item" do - knife("node run list add cons -a recipe[bar] recipe[foo]").should_succeed(/run_list:\n\s*recipe\[bar\]\n\s*recipe\[foo\]\n/m) - end - end -end diff --git a/spec/integration/knife/node_run_list_remove_spec.rb b/spec/integration/knife/node_run_list_remove_spec.rb deleted file mode 100644 index 19aeb81806..0000000000 --- a/spec/integration/knife/node_run_list_remove_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife node run list remove", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has a node with a run_list" do - before do - node "cons", { run_list: ["recipe[bar]", "recipe[foo]"] } - end - - it "removes the item from the run list" do - knife("node run list remove cons recipe[bar]").should_succeed(/run_list:\s*recipe\[foo\]\n/m) - end - end -end diff --git a/spec/integration/knife/node_run_list_set_spec.rb b/spec/integration/knife/node_run_list_set_spec.rb deleted file mode 100644 index d83e74dd04..0000000000 --- a/spec/integration/knife/node_run_list_set_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife node run list set", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has a node with a run_list" do - before do - node "cons", { run_list: ["recipe[bar]", "recipe[foo]"] } - end - - it "sets the run list" do - knife("node run list set cons recipe[bar]").should_succeed(/run_list:\s*recipe\[bar\]\n/m) - end - - it "with no role or recipe" do - knife("node run list set cons").should_fail stderr: "FATAL: You must supply both a node name and a run list.\n", - stdout: /^USAGE: knife node run_list set NODE ENTRIES \(options\)/m - end - end -end diff --git a/spec/integration/knife/node_show_spec.rb b/spec/integration/knife/node_show_spec.rb deleted file mode 100644 index be63011ef8..0000000000 --- a/spec/integration/knife/node_show_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife node show", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has a node with a run_list" do - before do - node "cons", { run_list: ["recipe[bar]", "recipe[foo]"] } - end - - it "shows the node" do - knife("node show cons").should_succeed(/Run List:\s*recipe\[bar\], recipe\[foo\]\n/m) - end - end -end diff --git a/spec/integration/knife/raw_spec.rb b/spec/integration/knife/raw_spec.rb deleted file mode 100644 index 8e7e913b02..0000000000 --- a/spec/integration/knife/raw_spec.rb +++ /dev/null @@ -1,297 +0,0 @@ -# -# Author:: John Keiser (<jkeiser@chef.io>) -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" -require "chef/knife/raw" -require "chef/knife/show" -require "tiny_server" - -describe "knife raw", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has one of each thing" do - before do - client "x", "{}" - cookbook "x", "1.0.0" - data_bag "x", { "y" => "{}" } - environment "x", "{}" - node "x", "{}" - role "x", "{}" - user "x", "{}" - end - - it "knife raw /nodes/x returns the node" do - knife("raw /nodes/x").should_succeed <<~EOM - { - "name": "x", - "json_class": "Chef::Node", - "chef_type": "node", - "chef_environment": "_default", - "override": { - - }, - "normal": { - "tags": [ - - ] - }, - "default": { - - }, - "automatic": { - - }, - "run_list": [ - - ] - } - EOM - end - - it "knife raw /blarghle returns 404" do - knife("raw /blarghle").should_fail(/ERROR: Server responded with error 404 "Not Found\s*"/) - end - - it "knife raw -m DELETE /roles/x succeeds" do - knife("raw -m DELETE /roles/x").should_succeed <<~EOM - { - "name": "x", - "description": "", - "json_class": "Chef::Role", - "chef_type": "role", - "default_attributes": { - - }, - "override_attributes": { - - }, - "run_list": [ - - ], - "env_run_lists": { - - } - } - EOM - knife("show /roles/x.json").should_fail "ERROR: /roles/x.json: No such file or directory\n" - end - - it "knife raw -m PUT -i blah.txt /roles/x succeeds" do - Tempfile.open("raw_put_input") do |file| - file.write <<~EOM - { - "name": "x", - "description": "eek", - "json_class": "Chef::Role", - "chef_type": "role", - "default_attributes": { - - }, - "override_attributes": { - - }, - "run_list": [ - - ], - "env_run_lists": { - - } - } - EOM - file.close - - knife("raw -m PUT -i #{file.path} /roles/x").should_succeed <<~EOM - { - "name": "x", - "description": "eek", - "json_class": "Chef::Role", - "chef_type": "role", - "default_attributes": { - - }, - "override_attributes": { - - }, - "run_list": [ - - ], - "env_run_lists": { - - } - } - EOM - knife("show /roles/x.json").should_succeed <<~EOM - /roles/x.json: - { - "name": "x", - "description": "eek", - "json_class": "Chef::Role", - "chef_type": "role", - "default_attributes": { - - }, - "override_attributes": { - - }, - "run_list": [ - - ], - "env_run_lists": { - - } - } - EOM - end - end - - it "knife raw -m POST -i blah.txt /roles succeeds" do - Tempfile.open("raw_put_input") do |file| - file.write <<~EOM - { - "name": "y", - "description": "eek", - "json_class": "Chef::Role", - "chef_type": "role", - "default_attributes": { - }, - "override_attributes": { - }, - "run_list": [ - - ], - "env_run_lists": { - } - } - EOM - file.close - - knife("raw -m POST -i #{file.path} /roles").should_succeed <<~EOM - { - "uri": "#{Chef::Config.chef_server_url}/roles/y" - } - EOM - knife("show /roles/y.json").should_succeed <<~EOM - /roles/y.json: - { - "name": "y", - "description": "eek", - "json_class": "Chef::Role", - "chef_type": "role", - "default_attributes": { - - }, - "override_attributes": { - - }, - "run_list": [ - - ], - "env_run_lists": { - - } - } - EOM - end - end - - context "When a server returns raw json" do - def start_tiny_server(**server_opts) - @server = TinyServer::Manager.new(**server_opts) - @server.start - @api = TinyServer::API.instance - @api.clear - - @api.get("/blah", 200, nil, { "Content-Type" => "application/json" }) do - '{ "x": "y", "a": "b" }' - end - end - - def stop_tiny_server - @server.stop - @server = @api = nil - end - - before :each do - Chef::Config.chef_server_url = "http://localhost:9000" - start_tiny_server - end - - after :each do - stop_tiny_server - end - - it "knife raw /blah returns the prettified json" do - knife("raw /blah").should_succeed <<~EOM - { - "x": "y", - "a": "b" - } - EOM - end - - it "knife raw --no-pretty /blah returns the raw json" do - knife("raw --no-pretty /blah").should_succeed <<~EOM - { "x": "y", "a": "b" } - EOM - end - end - - context "When a server returns text" do - def start_tiny_server(**server_opts) - @server = TinyServer::Manager.new(**server_opts) - @server.start - @api = TinyServer::API.instance - @api.clear - - @api.get("/blah", 200, nil, { "Content-Type" => "text" }) do - '{ "x": "y", "a": "b" }' - end - end - - def stop_tiny_server - @server.stop - @server = @api = nil - end - - before :each do - Chef::Config.chef_server_url = "http://localhost:9000" - start_tiny_server - end - - after :each do - stop_tiny_server - end - - it "knife raw /blah returns the raw text" do - knife("raw /blah").should_succeed(<<~EOM) - { "x": "y", "a": "b" } - EOM - end - - it "knife raw --no-pretty /blah returns the raw text" do - knife("raw --no-pretty /blah").should_succeed(<<~EOM) - { "x": "y", "a": "b" } - EOM - end - end - end -end diff --git a/spec/integration/knife/redirection_spec.rb b/spec/integration/knife/redirection_spec.rb deleted file mode 100644 index eea5556cff..0000000000 --- a/spec/integration/knife/redirection_spec.rb +++ /dev/null @@ -1,64 +0,0 @@ -# -# Author:: John Keiser (<jkeiser@chef.io>) -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "tiny_server" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" -require "chef/knife/list" - -describe "redirection", :workstation do - include IntegrationSupport - include KnifeSupport - - def start_tiny_server(real_chef_server_url, **server_opts) - @server = TinyServer::Manager.new(**server_opts) - @server.start - @api = TinyServer::API.instance - @api.clear - - @api.get("/roles", 302, nil, { "Content-Type" => "text", "Location" => "#{real_chef_server_url}/roles" }) do - end - end - - def stop_tiny_server - @server.stop - @server = @api = nil - end - - include_context "default config options" - - when_the_chef_server "has a role" do - before { role "x", {} } - - context "and another server redirects to it with 302" do - before(:each) do - real_chef_server_url = Chef::Config.chef_server_url - Chef::Config.chef_server_url = "http://localhost:9000" - start_tiny_server(real_chef_server_url) - end - - after(:each) do - stop_tiny_server - end - - it "knife list /roles returns the role" do - knife("list /roles").should_succeed "/roles/x.json\n" - end - end - end -end diff --git a/spec/integration/knife/role_bulk_delete_spec.rb b/spec/integration/knife/role_bulk_delete_spec.rb deleted file mode 100644 index 76745d9b6a..0000000000 --- a/spec/integration/knife/role_bulk_delete_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife role bulk delete", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has some roles" do - before do - role "cons", {} - role "car", {} - role "cdr", {} - role "cat", {} - end - - it "deletes all matching roles" do - knife("role bulk delete ^ca.*", input: "Y").should_succeed <<~EOM - The following roles will be deleted: - - car cat - - Are you sure you want to delete these roles? (Y/N) Deleted role car - Deleted role cat - EOM - - knife("role list").should_succeed <<~EOM - cdr - cons - EOM - end - - end -end diff --git a/spec/integration/knife/role_create_spec.rb b/spec/integration/knife/role_create_spec.rb deleted file mode 100644 index 03f59d4b99..0000000000 --- a/spec/integration/knife/role_create_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife role create", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - let(:out) { "Created role[bah]\n" } - - when_the_chef_server "is empty" do - it "creates a new role" do - knife("role create bah").should_succeed out - end - - it "refuses to add an existing role" do - pending "Knife role create must not blindly overwrite an existing role" - knife("role create bah").should_succeed out - expect { knife("role create bah") }.to raise_error(Net::HTTPClientException) - end - - end -end diff --git a/spec/integration/knife/role_delete_spec.rb b/spec/integration/knife/role_delete_spec.rb deleted file mode 100644 index 22b36e5572..0000000000 --- a/spec/integration/knife/role_delete_spec.rb +++ /dev/null @@ -1,48 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife role delete", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has some roles" do - before do - role "cons", {} - role "car", {} - role "cdr", {} - role "cat", {} - end - - it "deletes a role" do - knife("role delete car", input: "Y").should_succeed <<~EOM - Do you really want to delete car? (Y/N) Deleted role[car] - EOM - - knife("role list").should_succeed <<~EOM - cat - cdr - cons - EOM - end - - end -end diff --git a/spec/integration/knife/role_from_file_spec.rb b/spec/integration/knife/role_from_file_spec.rb deleted file mode 100644 index ae296122ce..0000000000 --- a/spec/integration/knife/role_from_file_spec.rb +++ /dev/null @@ -1,96 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife role from file", :workstation do - include IntegrationSupport - include KnifeSupport - - # include_context "default config options" - - let(:role_dir) { "#{@repository_dir}/roles" } - - when_the_chef_server "is empty" do - when_the_repository "has some roles" do - before do - - file "roles/cons.json", <<~EOM - { - "name": "cons", - "description": "An role", - "json_class": "Chef::role", - "chef_type": "role", - "default_attributes": { - "hola": "Amigos!" - }, - "override_attributes": { - - } - } - EOM - - file "roles/car.json", <<~EOM - { - "name": "car", - "description": "A role for list nodes", - "json_class": "Chef::Role", - "chef_type": "role", - "default_attributes": { - "hola": "Amigos!" - }, - "override_attributes": { - - } - } - EOM - - file "roles/cdr.json", <<~EOM - { - "name": "cdr", - "description": "A role for last nodes", - "json_class": "Chef::Role", - "chef_type": "role", - "default_attributes": { - "hola": "Amigos!" - }, - "override_attributes": { - - } - } - EOM - - end - - it "uploads a single file" do - knife("role from file #{role_dir}/cons.json").should_succeed stderr: <<~EOM - Updated Role cons - EOM - end - - it "uploads many files" do - knife("role from file #{role_dir}/cons.json #{role_dir}/car.json #{role_dir}/cdr.json").should_succeed stderr: <<~EOM - Updated Role cons - Updated Role car - Updated Role cdr - EOM - end - - end - end -end diff --git a/spec/integration/knife/role_list_spec.rb b/spec/integration/knife/role_list_spec.rb deleted file mode 100644 index 39aa28783f..0000000000 --- a/spec/integration/knife/role_list_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife role list", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has some roles" do - before do - role "cons", {} - role "car", {} - role "cdr", {} - role "cat", {} - end - - it "lists all cookbooks" do - knife("role list").should_succeed <<~EOM - car - cat - cdr - cons - EOM - end - - end -end diff --git a/spec/integration/knife/role_show_spec.rb b/spec/integration/knife/role_show_spec.rb deleted file mode 100644 index a4ecea1d61..0000000000 --- a/spec/integration/knife/role_show_spec.rb +++ /dev/null @@ -1,51 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife role show", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has some roles" do - before do - role "cons", {} - role "car", {} - role "cdr", {} - role "cat", {} - end - - # rubocop:disable Layout/TrailingWhitespace - it "shows a cookbook" do - knife("role show cons").should_succeed <<~EOM - chef_type: role - default_attributes: - description: - env_run_lists: - json_class: Chef::Role - name: cons - override_attributes: - run_list: - EOM - end - # rubocop:enable Layout/TrailingWhitespace - - end -end diff --git a/spec/integration/knife/search_node_spec.rb b/spec/integration/knife/search_node_spec.rb deleted file mode 100644 index 9e7935b83c..0000000000 --- a/spec/integration/knife/search_node_spec.rb +++ /dev/null @@ -1,40 +0,0 @@ -# -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" - -describe "knife node show", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has a node with a run_list" do - before do - node "cons", { run_list: ["recipe[bar]", "recipe[foo]"] } - end - - it "finds the node" do - knife("search node name:cons").should_succeed(/Node Name:\s*cons/, stderr: "1 items found\n\n") - end - - it "does not find a node" do - knife("search node name:snoc").should_fail("", stderr: "0 items found\n\n", exit_code: 1) - end - end -end diff --git a/spec/integration/knife/serve_spec.rb b/spec/integration/knife/serve_spec.rb deleted file mode 100644 index fa9b1dc47c..0000000000 --- a/spec/integration/knife/serve_spec.rb +++ /dev/null @@ -1,92 +0,0 @@ -# -# Author:: John Keiser (<jkeiser@chef.io>) -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "support/shared/integration/integration_helper" -require "chef/knife/serve" -require "chef/server_api" - -describe "knife serve", :workstation do - include IntegrationSupport - include KnifeSupport - - def with_knife_serve - exception = nil - t = Thread.new do - - knife("serve --chef-zero-port=8890") - rescue - exception = $! - - end - begin - Chef::Config.log_level = :debug - Chef::Config.chef_server_url = "http://localhost:8890" - Chef::Config.node_name = nil - Chef::Config.client_key = nil - api = Chef::ServerAPI.new - yield api - rescue - if exception - raise exception - else - raise - end - ensure - t.kill - sleep 0.5 - end - end - - when_the_repository "also has one of each thing" do - before do - file "nodes/a_node_in_json.json", { "foo" => "bar" } - file "nodes/a_node_in_ruby.rb", "name 'a_node_in_ruby'" - file "roles/a_role_in_json.json", { "foo" => "bar" } - file "roles/a_role_in_ruby.rb", "name 'a_role_in_ruby'" - end - - %w{a_node_in_json a_node_in_ruby}.each do |file_type| - context file_type do - it "knife serve serves up /nodes" do - with_knife_serve do |api| - expect(api.get("nodes")).to have_key(file_type) - end - end - it "knife serve serves up /nodes/#{file_type}" do - with_knife_serve do |api| - expect(api.get("nodes/#{file_type}")["name"]).to eq(file_type) - end - end - end - end - - %w{a_role_in_json a_role_in_ruby}.each do |file_type| - context file_type do - it "knife serve serves up /roles" do - with_knife_serve do |api| - expect(api.get("roles")).to have_key(file_type) - end - end - it "knife serve serves up /roles/#{file_type}" do - with_knife_serve do |api| - expect(api.get("roles/#{file_type}")["name"]).to eq(file_type) - end - end - end - end - end -end diff --git a/spec/integration/knife/show_spec.rb b/spec/integration/knife/show_spec.rb deleted file mode 100644 index 6913494916..0000000000 --- a/spec/integration/knife/show_spec.rb +++ /dev/null @@ -1,197 +0,0 @@ -# -# Author:: John Keiser (<jkeiser@chef.io>) -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "support/shared/context/config" -require "chef/knife/show" - -describe "knife show", :workstation do - include IntegrationSupport - include KnifeSupport - - include_context "default config options" - - when_the_chef_server "has one of each thing" do - before do - client "x", "{}" - cookbook "x", "1.0.0" - data_bag "x", { "y" => "{}" } - environment "x", "{}" - node "x", "{}" - role "x", "{}" - user "x", "{}" - end - - when_the_repository "also has one of each thing" do - before do - file "clients/x.json", { "foo" => "bar" } - file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0") - file "data_bags/x/y.json", { "foo" => "bar" } - file "environments/_default.json", { "foo" => "bar" } - file "environments/x.json", { "foo" => "bar" } - file "nodes/x.json", { "foo" => "bar" } - file "roles/x.json", { "foo" => "bar" } - file "users/x.json", { "foo" => "bar" } - end - - it "knife show /cookbooks/x/metadata.rb shows the remote version" do - knife("show /cookbooks/x/metadata.rb").should_succeed <<~EOM - /cookbooks/x/metadata.rb: - name "x"; version "1.0.0" - EOM - end - it "knife show --local /cookbooks/x/metadata.rb shows the local version" do - knife("show --local /cookbooks/x/metadata.rb").should_succeed <<~EOM - /cookbooks/x/metadata.rb: - name "x"; version "1.0.0" - EOM - end - it "knife show /data_bags/x/y.json shows the remote version" do - knife("show /data_bags/x/y.json").should_succeed <<~EOM - /data_bags/x/y.json: - { - "id": "y" - } - EOM - end - it "knife show --local /data_bags/x/y.json shows the local version" do - knife("show --local /data_bags/x/y.json").should_succeed <<~EOM - /data_bags/x/y.json: - { - "foo": "bar" - } - EOM - end - it "knife show /environments/x.json shows the remote version" do - knife("show /environments/x.json").should_succeed <<~EOM - /environments/x.json: - { - "name": "x", - "description": "", - "cookbook_versions": { - - }, - "default_attributes": { - - }, - "override_attributes": { - - }, - "json_class": "Chef::Environment", - "chef_type": "environment" - } - EOM - end - it "knife show --local /environments/x.json shows the local version" do - knife("show --local /environments/x.json").should_succeed <<~EOM - /environments/x.json: - { - "foo": "bar" - } - EOM - end - it "knife show /roles/x.json shows the remote version" do - knife("show /roles/x.json").should_succeed <<~EOM - /roles/x.json: - { - "name": "x", - "description": "", - "json_class": "Chef::Role", - "chef_type": "role", - "default_attributes": { - - }, - "override_attributes": { - - }, - "run_list": [ - - ], - "env_run_lists": { - - } - } - EOM - end - it "knife show --local /roles/x.json shows the local version" do - knife("show --local /roles/x.json").should_succeed <<~EOM - /roles/x.json: - { - "foo": "bar" - } - EOM - end - # show directory - it "knife show /data_bags/x fails" do - knife("show /data_bags/x").should_fail "ERROR: /data_bags/x: is a directory\n" - end - it "knife show --local /data_bags/x fails" do - knife("show --local /data_bags/x").should_fail "ERROR: /data_bags/x: is a directory\n" - end - # show nonexistent file - it "knife show /environments/nonexistent.json fails" do - knife("show /environments/nonexistent.json").should_fail "ERROR: /environments/nonexistent.json: No such file or directory\n" - end - it "knife show --local /environments/nonexistent.json fails" do - knife("show --local /environments/nonexistent.json").should_fail "ERROR: /environments/nonexistent.json: No such file or directory\n" - end - end - end - - when_the_chef_server "has a hash with multiple keys" do - before do - environment "x", { - "default_attributes" => { "foo" => "bar" }, - "cookbook_versions" => { "blah" => "= 1.0.0" }, - "override_attributes" => { "x" => "y" }, - "description" => "woo", - "name" => "x", - } - end - it "knife show shows the attributes in a predetermined order" do - knife("show /environments/x.json").should_succeed <<~EOM - /environments/x.json: - { - "name": "x", - "description": "woo", - "cookbook_versions": { - "blah": "= 1.0.0" - }, - "default_attributes": { - "foo": "bar" - }, - "override_attributes": { - "x": "y" - }, - "json_class": "Chef::Environment", - "chef_type": "environment" - } - EOM - end - end - - when_the_repository "has an environment with bad JSON" do - before { file "environments/x.json", "{" } - it "knife show succeeds" do - knife("show --local /environments/x.json").should_succeed <<~EOM - /environments/x.json: - { - EOM - end - end -end diff --git a/spec/integration/knife/upload_spec.rb b/spec/integration/knife/upload_spec.rb deleted file mode 100644 index e4bb44ad7e..0000000000 --- a/spec/integration/knife/upload_spec.rb +++ /dev/null @@ -1,1617 +0,0 @@ -# -# Author:: John Keiser (<jkeiser@chef.io>) -# Copyright:: Copyright (c) Chef Software Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require "knife_spec_helper" -require "support/shared/integration/integration_helper" -require "chef/knife/upload" -require "chef/knife/diff" -require "chef/knife/raw" -require "chef/json_compat" - -describe "knife upload", :workstation do - include IntegrationSupport - include KnifeSupport - - context "without versioned cookbooks" do - - when_the_chef_server "has one of each thing" do - - before do - client "x", {} - cookbook "x", "1.0.0" - data_bag "x", { "y" => {} } - environment "x", {} - node "x", {} - role "x", {} - user "x", {} - end - - when_the_repository "has only top-level directories" do - before do - directory "clients" - directory "cookbooks" - directory "data_bags" - directory "environments" - directory "nodes" - directory "roles" - directory "users" - end - - it "knife upload does nothing" do - knife("upload /").should_succeed "" - knife("diff --name-status /").should_succeed <<~EOM - D\t/clients/chef-validator.json - D\t/clients/chef-webui.json - D\t/clients/x.json - D\t/cookbooks/x - D\t/data_bags/x - D\t/environments/_default.json - D\t/environments/x.json - D\t/nodes/x.json - D\t/roles/x.json - D\t/users/admin.json - D\t/users/x.json - EOM - end - - it "knife upload --purge deletes everything" do - knife("upload --purge /").should_succeed(<<~EOM, stderr: "WARNING: /environments/_default.json cannot be deleted (default environment cannot be modified).\n") - Deleted extra entry /clients/chef-validator.json (purge is on) - Deleted extra entry /clients/chef-webui.json (purge is on) - Deleted extra entry /clients/x.json (purge is on) - Deleted extra entry /cookbooks/x (purge is on) - Deleted extra entry /data_bags/x (purge is on) - Deleted extra entry /environments/x.json (purge is on) - Deleted extra entry /nodes/x.json (purge is on) - Deleted extra entry /roles/x.json (purge is on) - Deleted extra entry /users/admin.json (purge is on) - Deleted extra entry /users/x.json (purge is on) - EOM - knife("diff --name-status /").should_succeed <<~EOM - D\t/environments/_default.json - EOM - end - end - - when_the_repository "has an identical copy of each thing" do - - before do - file "clients/chef-validator.json", { "validator" => true, "public_key" => ChefZero::PUBLIC_KEY } - file "clients/chef-webui.json", { "admin" => true, "public_key" => ChefZero::PUBLIC_KEY } - file "clients/x.json", { "public_key" => ChefZero::PUBLIC_KEY } - file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0") - file "data_bags/x/y.json", {} - file "environments/_default.json", { "description" => "The default Chef environment" } - file "environments/x.json", {} - file "nodes/x.json", { "normal" => { "tags" => [] } } - file "roles/x.json", {} - file "users/admin.json", { "admin" => true, "public_key" => ChefZero::PUBLIC_KEY } - file "users/x.json", { "public_key" => ChefZero::PUBLIC_KEY } - end - - it "knife upload makes no changes" do - knife("upload /cookbooks/x").should_succeed "" - knife("diff --name-status /").should_succeed "" - end - - it "knife upload --purge makes no changes" do - knife("upload --purge /").should_succeed "" - knife("diff --name-status /").should_succeed "" - end - - context "except the role file" do - before do - file "roles/x.json", { "description" => "blarghle" } - end - - it "knife upload changes the role" do - knife("upload /").should_succeed "Updated /roles/x.json\n" - knife("diff --name-status /").should_succeed "" - end - it "knife upload --no-diff does not change the role" do - knife("upload --no-diff /").should_succeed "" - knife("diff --name-status /").should_succeed "M\t/roles/x.json\n" - end - end - - context "except the role file is textually different, but not ACTUALLY different" do - before do - file "roles/x.json", <<~EOM - { - "chef_type": "role", - "default_attributes": { - }, - "env_run_lists": { - }, - "json_class": "Chef::Role", - "name": "x", - "description": "", - "override_attributes": { - }, - "run_list": [ - - ] - } - EOM - end - - it "knife upload / does not change anything" do - knife("upload /").should_succeed "" - knife("diff --name-status /").should_succeed "" - end - end - - context "the role is in ruby" do - before do - file "roles/x.rb", <<~EOM - name "x" - description "blargle" - EOM - end - - it "knife upload changes the role" do - knife("upload /").should_succeed "Updated /roles/x.json\n" - knife("diff --name-status /").should_succeed "" - end - - it "knife upload --no-diff does not change the role" do - knife("upload --no-diff /").should_succeed "" - knife("diff --name-status /").should_succeed "M\t/roles/x.rb\n" - end - end - - context "when cookbook metadata has a self-dependency" do - before do - file "cookbooks/x/metadata.rb", "name 'x'; version '1.0.0'; depends 'x'" - end - - it "fails with RuntimeError" do - expect { knife("upload /cookbooks") }.to raise_error RuntimeError, /Cookbook depends on itself/ - end - end - - context "as well as one extra copy of each thing" do - before do - file "clients/y.json", { "public_key" => ChefZero::PUBLIC_KEY } - file "cookbooks/x/blah.rb", "" - file "cookbooks/y/metadata.rb", cb_metadata("y", "1.0.0") - file "data_bags/x/z.json", {} - file "data_bags/y/zz.json", {} - file "environments/y.json", {} - file "nodes/y.json", {} - file "roles/y.json", {} - file "users/y.json", { "public_key" => ChefZero::PUBLIC_KEY } - end - - it "knife upload adds the new files" do - knife("upload /").should_succeed <<~EOM - Created /clients/y.json - Updated /cookbooks/x - Created /cookbooks/y - Created /data_bags/x/z.json - Created /data_bags/y - Created /data_bags/y/zz.json - Created /environments/y.json - Created /nodes/y.json - Created /roles/y.json - Created /users/y.json - EOM - knife("diff --name-status /").should_succeed <<~EOM - D\t/cookbooks/x/metadata.json - D\t/cookbooks/y/metadata.json - EOM - end - - it "knife upload --no-diff adds the new files" do - knife("upload --no-diff /").should_succeed <<~EOM - Created /clients/y.json - Updated /cookbooks/x - Created /cookbooks/y - Created /data_bags/x/z.json - Created /data_bags/y - Created /data_bags/y/zz.json - Created /environments/y.json - Created /nodes/y.json - Created /roles/y.json - Created /users/y.json - EOM - knife("diff --name-status /").should_succeed <<~EOM - D\t/cookbooks/x/metadata.json - D\t/cookbooks/y/metadata.json - EOM - end - end - end - - when_the_repository "is empty" do - it "knife upload does nothing" do - knife("upload /").should_succeed "" - knife("diff --name-status /").should_succeed <<~EOM - D\t/clients - D\t/cookbooks - D\t/data_bags - D\t/environments - D\t/nodes - D\t/roles - D\t/users - EOM - end - - it "knife upload --purge deletes nothing" do - knife("upload --purge /").should_fail <<~EOM - ERROR: /clients cannot be deleted. - ERROR: /cookbooks cannot be deleted. - ERROR: /data_bags cannot be deleted. - ERROR: /environments cannot be deleted. - ERROR: /nodes cannot be deleted. - ERROR: /roles cannot be deleted. - ERROR: /users cannot be deleted. - EOM - knife("diff --name-status /").should_succeed <<~EOM - D\t/clients - D\t/cookbooks - D\t/data_bags - D\t/environments - D\t/nodes - D\t/roles - D\t/users - EOM - end - - context "when current directory is top level" do - before do - cwd "." - end - - it "knife upload with no parameters reports an error" do - knife("upload").should_fail "FATAL: You must specify at least one argument. If you want to upload everything in this directory, run \"knife upload .\"\n", stdout: /USAGE/ - end - end - end - end - - when_the_chef_server "is empty" do - when_the_repository "has a data bag item" do - - before do - file "data_bags/x/y.json", { "foo" => "bar" } - end - - it "knife upload of the data bag uploads only the values in the data bag item and no other" do - knife("upload /data_bags/x/y.json").should_succeed <<~EOM - Created /data_bags/x - Created /data_bags/x/y.json - EOM - knife("diff --name-status /data_bags").should_succeed <<~EOM - EOM - expect(Chef::JSONCompat.parse(knife("raw /data/x/y").stdout, create_additions: false).keys.sort).to eq(%w{foo id}) - end - - it "knife upload /data_bags/x /data_bags/x/y.json uploads x once" do - knife("upload /data_bags/x /data_bags/x/y.json").should_succeed <<~EOM - Created /data_bags/x - Created /data_bags/x/y.json - EOM - end - end - - when_the_repository "has a data bag item with keys chef_type and data_bag" do - - before do - file "data_bags/x/y.json", { "chef_type" => "aaa", "data_bag" => "bbb" } - end - - it "upload preserves chef_type and data_bag" do - knife("upload /data_bags/x/y.json").should_succeed <<~EOM - Created /data_bags/x - Created /data_bags/x/y.json - EOM - knife("diff --name-status /data_bags").should_succeed "" - result = Chef::JSONCompat.parse(knife("raw /data/x/y").stdout, create_additions: false) - expect(result.keys.sort).to eq(%w{chef_type data_bag id}) - expect(result["chef_type"]).to eq("aaa") - expect(result["data_bag"]).to eq("bbb") - end - end - - # Test upload of an item when the other end doesn't even have the container - when_the_repository "has two data bag items" do - before do - file "data_bags/x/y.json", {} - file "data_bags/x/z.json", {} - end - it "knife upload of one data bag item itself succeeds" do - knife("upload /data_bags/x/y.json").should_succeed <<~EOM - Created /data_bags/x - Created /data_bags/x/y.json - EOM - knife("diff --name-status /data_bags").should_succeed <<~EOM - A\t/data_bags/x/z.json - EOM - end - end - end - - when_the_chef_server "has three data bag items" do - - before do - data_bag "x", { "deleted" => {}, "modified" => {}, "unmodified" => {} } - end - - when_the_repository "has a modified, unmodified, added and deleted data bag item" do - before do - file "data_bags/x/added.json", {} - file "data_bags/x/modified.json", { "foo" => "bar" } - file "data_bags/x/unmodified.json", {} - end - - it "knife upload of the modified file succeeds" do - knife("upload /data_bags/x/modified.json").should_succeed <<~EOM - Updated /data_bags/x/modified.json - EOM - knife("diff --name-status /data_bags").should_succeed <<~EOM - D\t/data_bags/x/deleted.json - A\t/data_bags/x/added.json - EOM - end - it "knife upload of the unmodified file does nothing" do - knife("upload /data_bags/x/unmodified.json").should_succeed "" - knife("diff --name-status /data_bags").should_succeed <<~EOM - D\t/data_bags/x/deleted.json - M\t/data_bags/x/modified.json - A\t/data_bags/x/added.json - EOM - end - it "knife upload of the added file succeeds" do - knife("upload /data_bags/x/added.json").should_succeed <<~EOM - Created /data_bags/x/added.json - EOM - knife("diff --name-status /data_bags").should_succeed <<~EOM - D\t/data_bags/x/deleted.json - M\t/data_bags/x/modified.json - EOM - end - it "knife upload of the deleted file does nothing" do - knife("upload /data_bags/x/deleted.json").should_succeed "" - knife("diff --name-status /data_bags").should_succeed <<~EOM - D\t/data_bags/x/deleted.json - M\t/data_bags/x/modified.json - A\t/data_bags/x/added.json - EOM - end - it "knife upload --purge of the deleted file deletes it" do - knife("upload --purge /data_bags/x/deleted.json").should_succeed <<~EOM - Deleted extra entry /data_bags/x/deleted.json (purge is on) - EOM - knife("diff --name-status /data_bags").should_succeed <<~EOM - M\t/data_bags/x/modified.json - A\t/data_bags/x/added.json - EOM - end - it "knife upload of the entire data bag uploads everything" do - knife("upload /data_bags/x").should_succeed <<~EOM - Created /data_bags/x/added.json - Updated /data_bags/x/modified.json - EOM - knife("diff --name-status /data_bags").should_succeed <<~EOM - D\t/data_bags/x/deleted.json - EOM - end - it "knife upload --purge of the entire data bag uploads everything" do - knife("upload --purge /data_bags/x").should_succeed <<~EOM - Created /data_bags/x/added.json - Updated /data_bags/x/modified.json - Deleted extra entry /data_bags/x/deleted.json (purge is on) - EOM - knife("diff --name-status /data_bags").should_succeed "" - end - context "when cwd is the /data_bags directory" do - - before do - cwd "data_bags" - end - - it "knife upload fails" do - knife("upload").should_fail "FATAL: You must specify at least one argument. If you want to upload everything in this directory, run \"knife upload .\"\n", stdout: /USAGE/ - end - - it "knife upload --purge . uploads everything" do - knife("upload --purge .").should_succeed <<~EOM - Created x/added.json - Updated x/modified.json - Deleted extra entry x/deleted.json (purge is on) - EOM - knife("diff --name-status /data_bags").should_succeed "" - end - it "knife upload --purge * uploads everything" do - knife("upload --purge *").should_succeed <<~EOM - Created x/added.json - Updated x/modified.json - Deleted extra entry x/deleted.json (purge is on) - EOM - knife("diff --name-status /data_bags").should_succeed "" - end - end - end - end - - # Cookbook upload is a funny thing ... direct cookbook upload works, but - # upload of a file is designed not to work at present. Make sure that is the - # case. - when_the_chef_server "has a cookbook" do - before do - cookbook "x", "1.0.0", { "z.rb" => "" } - end - - when_the_repository "does not have metadata file" do - before do - file "cookbooks/x/y.rb", "hi" - end - - it "raises MetadataNotFound exception" do - expect { knife("upload /cookbooks/x") }.to raise_error(Chef::Exceptions::MetadataNotFound) - end - end - - when_the_repository "does not have valid metadata" do - before do - file "cookbooks/x/metadata.rb", cb_metadata(nil, "1.0.0") - end - - it "raises exception for invalid metadata" do - expect { knife("upload /cookbooks/x") }.to raise_error(Chef::Exceptions::MetadataNotValid) - end - end - - when_the_repository "has a modified, extra and missing file for the cookbook" do - before do - file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0", "#modified") - file "cookbooks/x/y.rb", "hi" - end - - it "knife upload of any individual file fails" do - knife("upload /cookbooks/x/metadata.rb").should_fail "ERROR: /cookbooks/x/metadata.rb cannot be updated.\n" - knife("upload /cookbooks/x/y.rb").should_fail "ERROR: /cookbooks/x cannot have a child created under it.\n" - knife("upload --purge /cookbooks/x/z.rb").should_fail "ERROR: /cookbooks/x/z.rb cannot be deleted.\n" - end - - # TODO this is a bit of an inconsistency: if we didn't specify --purge, - # technically we shouldn't have deleted missing files. But ... cookbooks - # are a special case. - it "knife upload of the cookbook itself succeeds" do - knife("upload /cookbooks/x").should_succeed <<~EOM - Updated /cookbooks/x - EOM - knife("diff --name-status /cookbooks").should_succeed <<~EOM - D\t/cookbooks/x/metadata.json - EOM - end - - it "knife upload --purge of the cookbook itself succeeds" do - knife("upload /cookbooks/x").should_succeed <<~EOM - Updated /cookbooks/x - EOM - knife("diff --name-status /cookbooks").should_succeed <<~EOM - D\t/cookbooks/x/metadata.json - EOM - end - end - when_the_repository "has a missing file for the cookbook" do - - before do - file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0") - end - - it "knife upload of the cookbook succeeds" do - knife("upload /cookbooks/x").should_succeed <<~EOM - Updated /cookbooks/x - EOM - knife("diff --name-status /cookbooks").should_succeed <<~EOM - D\t/cookbooks/x/metadata.json - EOM - end - end - when_the_repository "has an extra file for the cookbook" do - - before do - file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0") - file "cookbooks/x/z.rb", "" - file "cookbooks/x/blah.rb", "" - end - - it "knife upload of the cookbook succeeds" do - knife("upload /cookbooks/x").should_succeed <<~EOM - Updated /cookbooks/x - EOM - knife("diff --name-status /cookbooks").should_succeed <<~EOM - D\t/cookbooks/x/metadata.json - EOM - end - end - - when_the_repository "has a different file in the cookbook" do - before do - file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0") - end - - it "knife upload --freeze freezes the cookbook" do - knife("upload --freeze /cookbooks/x").should_succeed <<~EOM - Updated /cookbooks/x - EOM - # Modify a file and attempt to upload - file "cookbooks/x/metadata.rb", 'name "x"; version "1.0.0"#different' - knife("upload /cookbooks/x").should_fail "ERROR: /cookbooks failed to write: Cookbook x is frozen\n" - end - end - end - - when_the_chef_server "has a frozen cookbook" do - before do - cookbook "frozencook", "1.0.0", {}, frozen: true - end - - when_the_repository "has an update to said cookbook" do - - before do - file "cookbooks/frozencook/metadata.rb", cb_metadata("frozencook", "1.0.0", "# This is different") - end - - it "knife upload fails to upload the frozen cookbook" do - knife("upload /cookbooks/frozencook").should_fail "ERROR: /cookbooks failed to write: Cookbook frozencook is frozen\n" - end - it "knife upload --force uploads the frozen cookbook" do - knife("upload --force /cookbooks/frozencook").should_succeed <<~EOM - Updated /cookbooks/frozencook - EOM - end - end - end - - when_the_repository "has a cookbook" do - before do - file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0") - file "cookbooks/x/metadata.json", { name: "x", version: "1.0.0" } - file "cookbooks/x/onlyin1.0.0.rb", "old_text" - end - - when_the_chef_server "has a later version for the cookbook" do - before do - cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => "" } - cookbook "x", "1.0.1", { "onlyin1.0.1.rb" => "hi" } - end - - it "knife upload /cookbooks/x uploads the local version" do - knife("diff --name-status /cookbooks").should_succeed <<~EOM - M\t/cookbooks/x/metadata.rb - D\t/cookbooks/x/onlyin1.0.1.rb - A\t/cookbooks/x/metadata.json - A\t/cookbooks/x/onlyin1.0.0.rb - EOM - knife("upload --purge /cookbooks/x").should_succeed <<~EOM - Updated /cookbooks/x - EOM - knife("diff --name-status /cookbooks").should_succeed <<~EOM - M\t/cookbooks/x/metadata.rb - D\t/cookbooks/x/onlyin1.0.1.rb - A\t/cookbooks/x/metadata.json - A\t/cookbooks/x/onlyin1.0.0.rb - EOM - end - end - end - - when_the_repository "has a cookbook" do - before do - file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0") - file "cookbooks/x/onlyin1.0.0.rb", "old_text" - end - - when_the_chef_server "has a later version for the cookbook" do - before do - cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => "" } - cookbook "x", "1.0.1", { "onlyin1.0.1.rb" => "hi" } - end - - it "knife upload /cookbooks/x uploads the local version and generates metadata.json from metadata.rb and uploads it." do - knife("diff --name-status /cookbooks").should_succeed <<~EOM - M\t/cookbooks/x/metadata.rb - D\t/cookbooks/x/onlyin1.0.1.rb - A\t/cookbooks/x/onlyin1.0.0.rb - EOM - knife("upload --purge /cookbooks/x").should_succeed <<~EOM - Updated /cookbooks/x - EOM - knife("diff --name-status /cookbooks").should_succeed <<~EOM - M\t/cookbooks/x/metadata.rb - D\t/cookbooks/x/onlyin1.0.1.rb - A\t/cookbooks/x/onlyin1.0.0.rb - EOM - end - end - - when_the_chef_server "has an earlier version for the cookbook" do - before do - cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => "" } - cookbook "x", "0.9.9", { "onlyin0.9.9.rb" => "hi" } - end - - it "knife upload /cookbooks/x uploads the local version generates metadata.json and uploads it." do - knife("upload --purge /cookbooks/x").should_succeed <<~EOM - Updated /cookbooks/x - EOM - knife("diff --name-status /cookbooks").should_succeed <<~EOM - D\t/cookbooks/x/metadata.json - EOM - end - end - - when_the_chef_server "has a later version for the cookbook, and no current version" do - before do - cookbook "x", "1.0.1", { "onlyin1.0.1.rb" => "hi" } - end - - it "knife upload /cookbooks/x uploads the local version and generates metadata.json before upload and uploads it." do - knife("diff --name-status /cookbooks").should_succeed <<~EOM - M\t/cookbooks/x/metadata.rb - D\t/cookbooks/x/onlyin1.0.1.rb - A\t/cookbooks/x/onlyin1.0.0.rb - EOM - knife("upload --purge /cookbooks/x").should_succeed <<~EOM - Updated /cookbooks/x - EOM - knife("diff --name-status /cookbooks").should_succeed <<~EOM - M\t/cookbooks/x/metadata.rb - D\t/cookbooks/x/onlyin1.0.1.rb - A\t/cookbooks/x/onlyin1.0.0.rb - EOM - end - end - - when_the_chef_server "has an earlier version for the cookbook, and no current version" do - before do - cookbook "x", "0.9.9", { "onlyin0.9.9.rb" => "hi" } - end - - it "knife upload /cookbooks/x uploads the new version" do - knife("upload --purge /cookbooks/x").should_succeed <<~EOM - Updated /cookbooks/x - EOM - knife("diff --name-status /cookbooks").should_succeed <<~EOM - D\t/cookbooks/x/metadata.json - EOM - end - end - end - - when_the_chef_server "has an environment" do - before do - environment "x", {} - end - - when_the_repository "has an environment with bad JSON" do - before do - file "environments/x.json", "{" - end - - it "knife upload tries and fails" do - error1 = <<~EOH - WARN: Parse error reading #{path_to("environments/x.json")} as JSON: parse error: premature EOF - { - (right here) ------^ - - ERROR: /environments/x.json failed to write: Parse error reading JSON: parse error: premature EOF - { - (right here) ------^ - EOH - - warn = <<~EOH - WARN: Parse error reading #{path_to("environments/x.json")} as JSON: parse error: premature EOF - { - (right here) ------^ - - EOH - knife("upload /environments/x.json").should_fail(error1) - knife("diff --name-status /environments/x.json").should_succeed("M\t/environments/x.json\n", stderr: warn) - end - end - - when_the_repository "has the same environment with the wrong name in the file" do - before do - file "environments/x.json", { "name" => "y" } - end - it "knife upload fails" do - knife("upload /environments/x.json").should_fail "ERROR: /environments/x.json failed to write: Name must be 'x' (is 'y')\n" - knife("diff --name-status /environments/x.json").should_succeed "M\t/environments/x.json\n" - end - end - - when_the_repository "has the same environment with no name in the file" do - before do - file "environments/x.json", { "description" => "hi" } - end - it "knife upload succeeds" do - knife("upload /environments/x.json").should_succeed "Updated /environments/x.json\n" - knife("diff --name-status /environments/x.json").should_succeed "" - end - end - end - - when_the_chef_server "is empty" do - - when_the_repository "has an environment with the wrong name in the file" do - before do - file "environments/x.json", { "name" => "y" } - end - it "knife upload fails" do - knife("upload /environments/x.json").should_fail "ERROR: /environments failed to create_child: Error creating 'x.json': Name must be 'x' (is 'y')\n" - knife("diff --name-status /environments/x.json").should_succeed "A\t/environments/x.json\n" - end - end - - when_the_repository "has an environment with no name in the file" do - - before do - file "environments/x.json", { "description" => "hi" } - end - it "knife upload succeeds" do - knife("upload /environments/x.json").should_succeed "Created /environments/x.json\n" - knife("diff --name-status /environments/x.json").should_succeed "" - end - end - - when_the_repository "has a data bag with no id in the file" do - before do - file "data_bags/bag/x.json", { "foo" => "bar" } - end - it "knife upload succeeds" do - knife("upload /data_bags/bag/x.json").should_succeed "Created /data_bags/bag\nCreated /data_bags/bag/x.json\n" - knife("diff --name-status /data_bags/bag/x.json").should_succeed "" - end - end - end - when_the_chef_server "is empty" do - when_the_repository "has a cookbook with an invalid chef_version constraint in it" do - before do - file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0", "\nchef_version '~> 999.0'") - end - it "knife upload succeeds" do - knife("upload /cookbooks/x").should_succeed <<~EOM - Created /cookbooks/x - EOM - knife("diff --name-status /cookbooks").should_succeed <<~EOM - D\t/cookbooks/x/metadata.json - EOM - end - end - end - end # without versioned cookbooks - - context "with versioned cookbooks" do - before { Chef::Config[:versioned_cookbooks] = true } - - when_the_chef_server "has one of each thing" do - - before do - client "x", {} - cookbook "x", "1.0.0" - data_bag "x", { "y" => {} } - environment "x", {} - node "x", {} - role "x", {} - user "x", {} - end - - when_the_repository "has only top-level directories" do - before do - directory "clients" - directory "cookbooks" - directory "data_bags" - directory "environments" - directory "nodes" - directory "roles" - directory "users" - end - - it "knife upload does nothing" do - knife("upload /").should_succeed "" - knife("diff --name-status /").should_succeed <<~EOM - D\t/clients/chef-validator.json - D\t/clients/chef-webui.json - D\t/clients/x.json - D\t/cookbooks/x-1.0.0 - D\t/data_bags/x - D\t/environments/_default.json - D\t/environments/x.json - D\t/nodes/x.json - D\t/roles/x.json - D\t/users/admin.json - D\t/users/x.json - EOM - end - - it "knife upload --purge deletes everything" do - knife("upload --purge /").should_succeed(<<~EOM, stderr: "WARNING: /environments/_default.json cannot be deleted (default environment cannot be modified).\n") - Deleted extra entry /clients/chef-validator.json (purge is on) - Deleted extra entry /clients/chef-webui.json (purge is on) - Deleted extra entry /clients/x.json (purge is on) - Deleted extra entry /cookbooks/x-1.0.0 (purge is on) - Deleted extra entry /data_bags/x (purge is on) - Deleted extra entry /environments/x.json (purge is on) - Deleted extra entry /nodes/x.json (purge is on) - Deleted extra entry /roles/x.json (purge is on) - Deleted extra entry /users/admin.json (purge is on) - Deleted extra entry /users/x.json (purge is on) - EOM - knife("diff --name-status /").should_succeed <<~EOM - D\t/environments/_default.json - EOM - end - end - - when_the_repository "has an identical copy of each thing" do - before do - file "clients/chef-validator.json", { "validator" => true, "public_key" => ChefZero::PUBLIC_KEY } - file "clients/chef-webui.json", { "admin" => true, "public_key" => ChefZero::PUBLIC_KEY } - file "clients/x.json", { "public_key" => ChefZero::PUBLIC_KEY } - file "cookbooks/x-1.0.0/metadata.rb", cb_metadata("x", "1.0.0") - file "data_bags/x/y.json", {} - file "environments/_default.json", { "description" => "The default Chef environment" } - file "environments/x.json", {} - file "nodes/x.json", { "normal" => { "tags" => [] } } - file "roles/x.json", {} - file "users/admin.json", { "admin" => true, "public_key" => ChefZero::PUBLIC_KEY } - file "users/x.json", { "public_key" => ChefZero::PUBLIC_KEY } - end - - it "knife upload makes no changes" do - knife("upload /cookbooks/x-1.0.0").should_succeed "" - knife("diff --name-status /").should_succeed "" - end - - it "knife upload --purge makes no changes" do - knife("upload --purge /").should_succeed "" - knife("diff --name-status /").should_succeed "" - end - - context "except the role file" do - before do - file "roles/x.json", { "description" => "blarghle" } - end - - it "knife upload changes the role" do - knife("upload /").should_succeed "Updated /roles/x.json\n" - knife("diff --name-status /").should_succeed "" - end - end - - context "except the role file is textually different, but not ACTUALLY different" do - - before do - file "roles/x.json", <<~EOM - { - "chef_type": "role", - "default_attributes": { - }, - "env_run_lists": { - }, - "json_class": "Chef::Role", - "name": "x", - "description": "", - "override_attributes": { - }, - "run_list": [ - - ] - } - EOM - end - - it "knife upload / does not change anything" do - knife("upload /").should_succeed "" - knife("diff --name-status /").should_succeed "" - end - end - - context "as well as one extra copy of each thing" do - before do - file "clients/y.json", { "public_key" => ChefZero::PUBLIC_KEY } - file "cookbooks/x-1.0.0/blah.rb", "" - file "cookbooks/x-2.0.0/metadata.rb", cb_metadata("x", "2.0.0") - file "cookbooks/y-1.0.0/metadata.rb", cb_metadata("y", "1.0.0") - file "data_bags/x/z.json", {} - file "data_bags/y/zz.json", {} - file "environments/y.json", {} - file "nodes/y.json", {} - file "roles/y.json", {} - file "users/y.json", { "public_key" => ChefZero::PUBLIC_KEY } - end - - it "knife upload adds the new files" do - knife("upload /").should_succeed <<~EOM - Created /clients/y.json - Updated /cookbooks/x-1.0.0 - Created /cookbooks/x-2.0.0 - Created /cookbooks/y-1.0.0 - Created /data_bags/x/z.json - Created /data_bags/y - Created /data_bags/y/zz.json - Created /environments/y.json - Created /nodes/y.json - Created /roles/y.json - Created /users/y.json - EOM - knife("diff --name-status /").should_succeed "" - end - end - end - - when_the_repository "is empty" do - it "knife upload does nothing" do - knife("upload /").should_succeed "" - knife("diff --name-status /").should_succeed <<~EOM - D\t/clients - D\t/cookbooks - D\t/data_bags - D\t/environments - D\t/nodes - D\t/roles - D\t/users - EOM - end - - it "knife upload --purge deletes nothing" do - knife("upload --purge /").should_fail <<~EOM - ERROR: /clients cannot be deleted. - ERROR: /cookbooks cannot be deleted. - ERROR: /data_bags cannot be deleted. - ERROR: /environments cannot be deleted. - ERROR: /nodes cannot be deleted. - ERROR: /roles cannot be deleted. - ERROR: /users cannot be deleted. - EOM - knife("diff --name-status /").should_succeed <<~EOM - D\t/clients - D\t/cookbooks - D\t/data_bags - D\t/environments - D\t/nodes - D\t/roles - D\t/users - EOM - end - - context "when current directory is top level" do - before do - cwd "." - end - it "knife upload with no parameters reports an error" do - knife("upload").should_fail "FATAL: You must specify at least one argument. If you want to upload everything in this directory, run \"knife upload .\"\n", stdout: /USAGE/ - end - end - end - end - - # Test upload of an item when the other end doesn't even have the container - when_the_chef_server "is empty" do - when_the_repository "has two data bag items" do - before do - file "data_bags/x/y.json", {} - file "data_bags/x/z.json", {} - end - - it "knife upload of one data bag item itself succeeds" do - knife("upload /data_bags/x/y.json").should_succeed <<~EOM - Created /data_bags/x - Created /data_bags/x/y.json - EOM - knife("diff --name-status /data_bags").should_succeed <<~EOM - A\t/data_bags/x/z.json - EOM - end - end - end - - when_the_chef_server "has three data bag items" do - before do - data_bag "x", { "deleted" => {}, "modified" => {}, "unmodified" => {} } - end - when_the_repository "has a modified, unmodified, added and deleted data bag item" do - before do - file "data_bags/x/added.json", {} - file "data_bags/x/modified.json", { "foo" => "bar" } - file "data_bags/x/unmodified.json", {} - end - - it "knife upload of the modified file succeeds" do - knife("upload /data_bags/x/modified.json").should_succeed <<~EOM - Updated /data_bags/x/modified.json - EOM - knife("diff --name-status /data_bags").should_succeed <<~EOM - D\t/data_bags/x/deleted.json - A\t/data_bags/x/added.json - EOM - end - it "knife upload of the unmodified file does nothing" do - knife("upload /data_bags/x/unmodified.json").should_succeed "" - knife("diff --name-status /data_bags").should_succeed <<~EOM - D\t/data_bags/x/deleted.json - M\t/data_bags/x/modified.json - A\t/data_bags/x/added.json - EOM - end - it "knife upload of the added file succeeds" do - knife("upload /data_bags/x/added.json").should_succeed <<~EOM - Created /data_bags/x/added.json - EOM - knife("diff --name-status /data_bags").should_succeed <<~EOM - D\t/data_bags/x/deleted.json - M\t/data_bags/x/modified.json - EOM - end - it "knife upload of the deleted file does nothing" do - knife("upload /data_bags/x/deleted.json").should_succeed "" - knife("diff --name-status /data_bags").should_succeed <<~EOM - D\t/data_bags/x/deleted.json - M\t/data_bags/x/modified.json - A\t/data_bags/x/added.json - EOM - end - it "knife upload --purge of the deleted file deletes it" do - knife("upload --purge /data_bags/x/deleted.json").should_succeed <<~EOM - Deleted extra entry /data_bags/x/deleted.json (purge is on) - EOM - knife("diff --name-status /data_bags").should_succeed <<~EOM - M\t/data_bags/x/modified.json - A\t/data_bags/x/added.json - EOM - end - it "knife upload of the entire data bag uploads everything" do - knife("upload /data_bags/x").should_succeed <<~EOM - Created /data_bags/x/added.json - Updated /data_bags/x/modified.json - EOM - knife("diff --name-status /data_bags").should_succeed <<~EOM - D\t/data_bags/x/deleted.json - EOM - end - it "knife upload --purge of the entire data bag uploads everything" do - knife("upload --purge /data_bags/x").should_succeed <<~EOM - Created /data_bags/x/added.json - Updated /data_bags/x/modified.json - Deleted extra entry /data_bags/x/deleted.json (purge is on) - EOM - knife("diff --name-status /data_bags").should_succeed "" - end - context "when cwd is the /data_bags directory" do - before do - cwd "data_bags" - end - it "knife upload fails" do - knife("upload").should_fail "FATAL: You must specify at least one argument. If you want to upload everything in this directory, run \"knife upload .\"\n", stdout: /USAGE/ - end - it "knife upload --purge . uploads everything" do - knife("upload --purge .").should_succeed <<~EOM - Created x/added.json - Updated x/modified.json - Deleted extra entry x/deleted.json (purge is on) - EOM - knife("diff --name-status /data_bags").should_succeed "" - end - it "knife upload --purge * uploads everything" do - knife("upload --purge *").should_succeed <<~EOM - Created x/added.json - Updated x/modified.json - Deleted extra entry x/deleted.json (purge is on) - EOM - knife("diff --name-status /data_bags").should_succeed "" - end - end - end - end - - # Cookbook upload is a funny thing ... direct cookbook upload works, but - # upload of a file is designed not to work at present. Make sure that is the - # case. - when_the_chef_server "has a cookbook" do - before do - cookbook "x", "1.0.0", { "z.rb" => "" } - end - - when_the_repository "has a modified, extra and missing file for the cookbook" do - before do - file "cookbooks/x-1.0.0/metadata.rb", cb_metadata("x", "1.0.0", "#modified") - file "cookbooks/x-1.0.0/y.rb", "hi" - end - - it "knife upload of any individual file fails" do - knife("upload /cookbooks/x-1.0.0/metadata.rb").should_fail "ERROR: /cookbooks/x-1.0.0/metadata.rb cannot be updated.\n" - knife("upload /cookbooks/x-1.0.0/y.rb").should_fail "ERROR: /cookbooks/x-1.0.0 cannot have a child created under it.\n" - knife("upload --purge /cookbooks/x-1.0.0/z.rb").should_fail "ERROR: /cookbooks/x-1.0.0/z.rb cannot be deleted.\n" - end - - # TODO this is a bit of an inconsistency: if we didn't specify --purge, - # technically we shouldn't have deleted missing files. But ... cookbooks - # are a special case. - it "knife upload of the cookbook itself succeeds" do - knife("upload /cookbooks/x-1.0.0").should_succeed <<~EOM - Updated /cookbooks/x-1.0.0 - EOM - knife("diff --name-status /cookbooks").should_succeed "" - end - - it "knife upload --purge of the cookbook itself succeeds" do - knife("upload /cookbooks/x-1.0.0").should_succeed <<~EOM - Updated /cookbooks/x-1.0.0 - EOM - knife("diff --name-status /cookbooks").should_succeed "" - end - end - - when_the_repository "has a missing file for the cookbook" do - before do - file "cookbooks/x-1.0.0/metadata.rb", cb_metadata("x", "1.0.0") - end - - it "knife upload of the cookbook succeeds" do - knife("upload /cookbooks/x-1.0.0").should_succeed <<~EOM - Updated /cookbooks/x-1.0.0 - EOM - knife("diff --name-status /cookbooks").should_succeed "" - end - end - - when_the_repository "has an extra file for the cookbook" do - before do - file "cookbooks/x-1.0.0/metadata.rb", cb_metadata("x", "1.0.0") - file "cookbooks/x-1.0.0/z.rb", "" - file "cookbooks/x-1.0.0/blah.rb", "" - end - - it "knife upload of the cookbook succeeds" do - knife("upload /cookbooks/x-1.0.0").should_succeed <<~EOM - Updated /cookbooks/x-1.0.0 - EOM - knife("diff --name-status /cookbooks").should_succeed "" - end - end - end - - when_the_repository "has a cookbook" do - before do - file "cookbooks/x-1.0.0/metadata.rb", cb_metadata("x", "1.0.0") - file "cookbooks/x-1.0.0/onlyin1.0.0.rb", "old_text" - end - - when_the_chef_server "has a later version for the cookbook" do - before do - cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => "" } - cookbook "x", "1.0.1", { "onlyin1.0.1.rb" => "hi" } - end - - it "knife upload /cookbooks uploads the local version" do - knife("diff --name-status /cookbooks").should_succeed <<~EOM - M\t/cookbooks/x-1.0.0/onlyin1.0.0.rb - D\t/cookbooks/x-1.0.1 - EOM - knife("upload --purge /cookbooks").should_succeed <<~EOM - Updated /cookbooks/x-1.0.0 - Deleted extra entry /cookbooks/x-1.0.1 (purge is on) - EOM - knife("diff --name-status /cookbooks").should_succeed "" - end - end - - when_the_chef_server "has an earlier version for the cookbook" do - before do - cookbook "x", "1.0.0", { "onlyin1.0.0.rb" => "" } - cookbook "x", "0.9.9", { "onlyin0.9.9.rb" => "hi" } - end - it "knife upload /cookbooks uploads the local version" do - knife("upload --purge /cookbooks").should_succeed <<~EOM - Updated /cookbooks/x-1.0.0 - Deleted extra entry /cookbooks/x-0.9.9 (purge is on) - EOM - knife("diff --name-status /cookbooks").should_succeed "" - end - end - - when_the_chef_server "has a later version for the cookbook, and no current version" do - before do - cookbook "x", "1.0.1", { "onlyin1.0.1.rb" => "hi" } - end - - it "knife upload /cookbooks/x uploads the local version" do - knife("diff --name-status /cookbooks").should_succeed <<~EOM - D\t/cookbooks/x-1.0.1 - A\t/cookbooks/x-1.0.0 - EOM - knife("upload --purge /cookbooks").should_succeed <<~EOM - Created /cookbooks/x-1.0.0 - Deleted extra entry /cookbooks/x-1.0.1 (purge is on) - EOM - knife("diff --name-status /cookbooks").should_succeed "" - end - end - - when_the_chef_server "has an earlier version for the cookbook, and no current version" do - before do - cookbook "x", "0.9.9", { "onlyin0.9.9.rb" => "hi" } - end - - it "knife upload /cookbooks/x uploads the new version" do - knife("upload --purge /cookbooks").should_succeed <<~EOM - Created /cookbooks/x-1.0.0 - Deleted extra entry /cookbooks/x-0.9.9 (purge is on) - EOM - knife("diff --name-status /cookbooks").should_succeed "" - end - end - end - - when_the_chef_server "has an environment" do - before do - environment "x", {} - end - - when_the_repository "has the same environment with the wrong name in the file" do - before do - file "environments/x.json", { "name" => "y" } - end - it "knife upload fails" do - knife("upload /environments/x.json").should_fail "ERROR: /environments/x.json failed to write: Name must be 'x' (is 'y')\n" - knife("diff --name-status /environments/x.json").should_succeed "M\t/environments/x.json\n" - end - end - - when_the_repository "has the same environment with no name in the file" do - before do - file "environments/x.json", { "description" => "hi" } - end - it "knife upload succeeds" do - knife("upload /environments/x.json").should_succeed "Updated /environments/x.json\n" - knife("diff --name-status /environments/x.json").should_succeed "" - end - end - end - - when_the_chef_server "is empty" do - - when_the_repository "has an environment with the wrong name in the file" do - before do - file "environments/x.json", { "name" => "y" } - end - it "knife upload fails" do - knife("upload /environments/x.json").should_fail "ERROR: /environments failed to create_child: Error creating 'x.json': Name must be 'x' (is 'y')\n" - knife("diff --name-status /environments/x.json").should_succeed "A\t/environments/x.json\n" - end - end - - when_the_repository "has an environment with no name in the file" do - before do - file "environments/x.json", { "description" => "hi" } - end - it "knife upload succeeds" do - knife("upload /environments/x.json").should_succeed "Created /environments/x.json\n" - knife("diff --name-status /environments/x.json").should_succeed "" - end - end - - when_the_repository "has a data bag with no id in the file" do - before do - file "data_bags/bag/x.json", { "foo" => "bar" } - end - it "knife upload succeeds" do - knife("upload /data_bags/bag/x.json").should_succeed "Created /data_bags/bag\nCreated /data_bags/bag/x.json\n" - knife("diff --name-status /data_bags/bag/x.json").should_succeed "" - end - end - end - - when_the_chef_server "is empty" do - when_the_repository "has a cookbook with an invalid chef_version constraint in it" do - before do - file "cookbooks/x-1.0.0/metadata.rb", cb_metadata("x", "1.0.0", "\nchef_version '~> 999.0'") - end - it "knife upload succeeds" do - knife("upload /cookbooks/x-1.0.0").should_succeed <<~EOM - Created /cookbooks/x-1.0.0 - EOM - knife("diff --name-status /cookbooks").should_succeed "" - end - end - end - end # with versioned cookbooks - - when_the_chef_server "has a user" do - before do - user "x", {} - end - - when_the_repository "has the same user with json_class in it" do - before do - file "users/x.json", { "admin" => true, "json_class" => "Chef::WebUIUser" } - end - it "knife upload /users/x.json succeeds" do - knife("upload /users/x.json").should_succeed "Updated /users/x.json\n" - end - end - end - - when_the_chef_server "is in Enterprise mode", osc_compat: false, single_org: false do - before do - user "foo", {} - user "bar", {} - user "foobar", {} - organization "foo", { "full_name" => "Something" } - end - - before :each do - Chef::Config.chef_server_url = URI.join(Chef::Config.chef_server_url, "/organizations/foo") - end - - context "and has nothing but a single group named blah" do - group "blah", {} - - when_the_repository "has at least one of each thing" do - - before do - # TODO We have to upload acls for an existing group due to a lack of - # dependency detection during upload. Fix that! - file "acls/groups/blah.json", {} - file "clients/x.json", { "public_key" => ChefZero::PUBLIC_KEY } - file "containers/x.json", {} - file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0") - file "cookbook_artifacts/x-1x1/metadata.rb", cb_metadata("x", "1.0.0") - file "data_bags/x/y.json", {} - file "environments/x.json", {} - file "groups/x.json", {} - file "invitations.json", [ "foo" ] - file "members.json", [ "bar" ] - file "org.json", { "full_name" => "wootles" } - file "nodes/x.json", { "normal" => { "tags" => [] } } - file "policies/x-1.0.0.json", {} - file "policies/blah-1.0.0.json", {} - file "policy_groups/x.json", { "policies" => { "x" => { "revision_id" => "1.0.0" }, "blah" => { "revision_id" => "1.0.0" } } } - file "roles/x.json", {} - end - - it "knife upload / uploads everything" do - knife("upload /").should_succeed <<~EOM - Updated /acls/groups/blah.json - Created /clients/x.json - Created /containers/x.json - Created /cookbook_artifacts/x-1x1 - Created /cookbooks/x - Created /data_bags/x - Created /data_bags/x/y.json - Created /environments/x.json - Created /groups/x.json - Updated /invitations.json - Updated /members.json - Created /nodes/x.json - Updated /org.json - Created /policies/blah-1.0.0.json - Created /policies/x-1.0.0.json - Created /policy_groups/x.json - Created /roles/x.json - EOM - expect(api.get("association_requests").map { |a| a["username"] }).to eq([ "foo" ]) - expect(api.get("users").map { |a| a["user"]["username"] }).to eq([ "bar" ]) - knife("diff --name-status --diff-filter=AMT /").should_succeed "" - end - - context "When the chef server has an identical copy of each thing" do - before do - file "invitations.json", [ "foo" ] - file "members.json", [ "bar" ] - file "org.json", { "full_name" => "Something" } - - # acl_for %w(organizations foo groups blah) - client "x", {} - cookbook "x", "1.0.0" - cookbook_artifact "x", "1x1", "metadata.rb" => cb_metadata("x", "1.0.0") - container "x", {} - data_bag "x", { "y" => {} } - environment "x", {} - group "x", {} - org_invite "foo" - org_member "bar" - node "x", {} - policy "x", "1.0.0", {} - policy "blah", "1.0.0", {} - policy_group "x", { - "policies" => { - "x" => { "revision_id" => "1.0.0" }, - "blah" => { "revision_id" => "1.0.0" }, - }, - } - role "x", {} - end - - it "knife upload makes no changes" do - knife("upload /").should_succeed <<~EOM - Updated /acls/groups/blah.json - EOM - end - end - - context "When the chef server has a slightly different copy of the policy revision" do - before do - policy "x", "1.0.0", { "run_list" => [ "blah" ] } - end - - it "should fail because policies are not updateable" do - knife("upload /policies/x-1.0.0.json").should_fail <<~EOM - ERROR: /policies/x-1.0.0.json cannot be updated: policy revisions are immutable once uploaded. If you want to change the policy, create a new revision with your changes. - EOM - end - end - - context "When the chef server has a slightly different copy of the cookbook artifact" do - before do - cookbook_artifact "x", "1x1", { "recipes" => { "default.rb" => "" } } - end - - it "should fail because cookbook_artifacts cannot be updated" do - knife("upload /cookbook_artifacts/x-1x1").should_fail <<~EOM - ERROR: /cookbook_artifacts/x-1x1 cannot be updated: cookbook artifacts are immutable once uploaded. - EOM - end - end - - context "When the chef server has a slightly different copy of each thing (except policy revisions)" do - before do - # acl_for %w(organizations foo groups blah) - client "x", { "validator" => true } - container "x", {} - cookbook "x", "1.0.0", { "recipes" => { "default.rb" => "" } } - cookbook_artifact "x", "1x1", { "metadata.rb" => cb_metadata("x", "1.0.0") } - data_bag "x", { "y" => { "a" => "b" } } - environment "x", { "description" => "foo" } - group "x", { "groups" => [ "admin" ] } - node "x", { "run_list" => [ "blah" ] } - policy "x", "1.0.0", {} - policy "x", "1.0.1", {} - policy "y", "1.0.0", {} - policy_group "x", { - "policies" => { - "x" => { "revision_id" => "1.0.1" }, - "y" => { "revision_id" => "1.0.0" }, - }, - } - role "x", { "run_list" => [ "blah" ] } - end - - it "knife upload updates everything" do - knife("upload /").should_succeed <<~EOM - Updated /acls/groups/blah.json - Updated /clients/x.json - Updated /cookbooks/x - Updated /data_bags/x/y.json - Updated /environments/x.json - Updated /groups/x.json - Updated /invitations.json - Updated /members.json - Updated /nodes/x.json - Updated /org.json - Created /policies/blah-1.0.0.json - Updated /policy_groups/x.json - Updated /roles/x.json - EOM - knife("diff --name-status --diff-filter=AMT /").should_succeed "" - end - end - end - - when_the_repository "has an org.json that does not change full_name" do - before do - file "org.json", { "full_name" => "Something" } - end - - it "knife upload / emits a warning for bar and adds foo and foobar" do - knife("upload /").should_succeed "" - expect(api.get("/")["full_name"]).to eq("Something") - end - end - - when_the_repository "has an org.json that changes full_name" do - before do - file "org.json", { "full_name" => "Something Else" } - end - - it "knife upload / emits a warning for bar and adds foo and foobar" do - knife("upload /").should_succeed "Updated /org.json\n" - expect(api.get("/")["full_name"]).to eq("Something Else") - end - end - - context "and has invited foo and bar is already a member" do - org_invite "foo" - org_member "bar" - - when_the_repository "wants to invite foo, bar and foobar" do - before do - file "invitations.json", %w{foo bar foobar} - end - - it "knife upload / emits a warning for bar and invites foobar" do - knife("upload /").should_succeed "Updated /invitations.json\n", stderr: "WARN: Could not invite bar to organization foo: User bar is already in organization foo\n" - expect(api.get("association_requests").map { |a| a["username"] }).to eq(%w{foo foobar}) - expect(api.get("users").map { |a| a["user"]["username"] }).to eq([ "bar" ]) - end - end - - when_the_repository "wants to make foo, bar and foobar members" do - before do - file "members.json", %w{foo bar foobar} - end - - it "knife upload / emits a warning for bar and adds foo and foobar" do - knife("upload /").should_succeed "Updated /members.json\n" - expect(api.get("association_requests").map { |a| a["username"] }).to eq([ ]) - expect(api.get("users").map { |a| a["user"]["username"] }).to eq(%w{bar foo foobar}) - end - end - - when_the_repository "wants to invite foo and have bar as a member" do - before do - file "invitations.json", [ "foo" ] - file "members.json", [ "bar" ] - end - - it "knife upload / does nothing" do - knife("upload /").should_succeed "" - expect(api.get("association_requests").map { |a| a["username"] }).to eq([ "foo" ]) - expect(api.get("users").map { |a| a["user"]["username"] }).to eq([ "bar" ]) - end - end - end - - context "and has invited bar and foo" do - org_invite "bar", "foo" - - when_the_repository "wants to invite foo and bar (different order)" do - before do - file "invitations.json", %w{foo bar} - end - - it "knife upload / does nothing" do - knife("upload /").should_succeed "" - expect(api.get("association_requests").map { |a| a["username"] }).to eq(%w{bar foo}) - expect(api.get("users").map { |a| a["user"]["username"] }).to eq([ ]) - end - end - end - - context "and has already added bar and foo as members of the org" do - org_member "bar", "foo" - - when_the_repository "wants to add foo and bar (different order)" do - before do - file "members.json", %w{foo bar} - end - - it "knife upload / does nothing" do - knife("upload /").should_succeed "" - expect(api.get("association_requests").map { |a| a["username"] }).to eq([ ]) - expect(api.get("users").map { |a| a["user"]["username"] }).to eq(%w{bar foo}) - end - end - end - end - end -end |