diff options
author | snehaldwivedi <sdwivedi@msystechnologies.com> | 2020-08-10 06:40:43 -0700 |
---|---|---|
committer | snehaldwivedi <sdwivedi@msystechnologies.com> | 2021-02-16 02:45:13 -0800 |
commit | 16d0f32cad6456012186a1494ab19f6f8b080c7a (patch) | |
tree | 0d8c18db8d55d0790481243483bb72b64c0cc14c | |
parent | 7ead343d039cb86ef9cd59443e16ef6bc5411aeb (diff) | |
download | chef-16d0f32cad6456012186a1494ab19f6f8b080c7a.tar.gz |
knife org edit NAME does not work
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
-rw-r--r-- | lib/chef/knife/org_edit.rb | 11 | ||||
-rw-r--r-- | spec/unit/knife/org_edit_spec.rb | 50 |
2 files changed, 58 insertions, 3 deletions
diff --git a/lib/chef/knife/org_edit.rb b/lib/chef/knife/org_edit.rb index f35262181b..9857e27600 100644 --- a/lib/chef/knife/org_edit.rb +++ b/lib/chef/knife/org_edit.rb @@ -22,6 +22,10 @@ class Chef category "CHEF ORGANIZATION MANAGEMENT" banner "knife org edit ORG" + deps do + require_relative "../org" + end + def run org_name = @name_args[0] @@ -31,8 +35,9 @@ class Chef exit 1 end - original_org = root_rest.get("organizations/#{org_name}") - edited_org = edit_data(original_org) + chef_rest = Chef::Org.from_hash({ "name" => org_name }).chef_rest + original_org = chef_rest.get("organizations/#{org_name}") + edited_org = edit_hash(original_org) if original_org == edited_org ui.msg("Organization unchanged, not saving.") @@ -40,7 +45,7 @@ class Chef end ui.msg edited_org - root_rest.put("organizations/#{org_name}", edited_org) + chef_rest.put("organizations/#{org_name}", edited_org) ui.msg("Saved #{org_name}.") end end diff --git a/spec/unit/knife/org_edit_spec.rb b/spec/unit/knife/org_edit_spec.rb new file mode 100644 index 0000000000..5cc5d9e54b --- /dev/null +++ b/spec/unit/knife/org_edit_spec.rb @@ -0,0 +1,50 @@ +# +# Author:: Snehal Dwivedi (<sdwivedi@msystechnologies.com>) +# 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 "spec_helper" + +describe Chef::Knife::OrgEdit do + let(:knife) { Chef::Knife::OrgEdit.new } + let(:chef_rest) { double("Chef::ServerAPI") } + + before :each do + Chef::Knife::OrgEdit.load_deps + @org_name = "foobar" + knife.name_args << @org_name + @org = double("Chef::Org") + allow(@org).to receive(:chef_rest).and_return(chef_rest) + knife.config[:disable_editing] = true + end + + it "loads and edits the organisation" do + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(chef_rest) + original_data = { "org_name" => "my_org" } + data = { "org_name" => "my_org1" } + expect(@org.chef_rest).to receive(:get).with("organizations/foobar").and_return(original_data) + expect(knife).to receive(:edit_hash).with(original_data).and_return(data) + expect(@org.chef_rest).to receive(:put).with("organizations/foobar", data) + knife.run + end + + it "prints usage and exits when a org name is not provided" do + knife.name_args = [] + expect(knife).to receive(:show_usage) + expect(knife.ui).to receive(:fatal) + expect { knife.run }.to raise_error(SystemExit) + end +end |