diff options
author | snehaldwivedi <sdwivedi@msystechnologies.com> | 2021-02-11 04:24:01 -0800 |
---|---|---|
committer | snehaldwivedi <sdwivedi@msystechnologies.com> | 2021-02-16 02:45:13 -0800 |
commit | 8f32723295c4ef04724270a4d6e4b77e5caf7b3a (patch) | |
tree | 49746969dc2ac35f84f442fff5623aafe3923b49 /spec/unit | |
parent | 3c1bf664db5c20b02aa5d2f0b1a1f4b18d19d750 (diff) | |
download | chef-8f32723295c4ef04724270a4d6e4b77e5caf7b3a.tar.gz |
Updated rest object URL and removed api_version 1
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Diffstat (limited to 'spec/unit')
-rw-r--r-- | spec/unit/knife/org_delete_spec.rb | 6 | ||||
-rw-r--r-- | spec/unit/knife/org_edit_spec.rb | 8 | ||||
-rw-r--r-- | spec/unit/knife/org_list_spec.rb | 6 | ||||
-rw-r--r-- | spec/unit/knife/org_show_spec.rb | 10 | ||||
-rw-r--r-- | spec/unit/knife/user_create_spec.rb | 16 | ||||
-rw-r--r-- | spec/unit/knife/user_edit_spec.rb | 8 | ||||
-rw-r--r-- | spec/unit/knife/user_password_spec.rb | 10 | ||||
-rw-r--r-- | spec/unit/knife/user_show_spec.rb | 19 |
8 files changed, 40 insertions, 43 deletions
diff --git a/spec/unit/knife/org_delete_spec.rb b/spec/unit/knife/org_delete_spec.rb index 94c224f1e6..b82c144116 100644 --- a/spec/unit/knife/org_delete_spec.rb +++ b/spec/unit/knife/org_delete_spec.rb @@ -21,7 +21,7 @@ require "chef/org" describe Chef::Knife::OrgDelete do - let(:root_rest) { double("Chef::ServerAPI") } + let(:rest) { double("Chef::ServerAPI") } before :each do @knife = Chef::Knife::OrgDelete.new @@ -32,9 +32,9 @@ describe Chef::Knife::OrgDelete do end it "should confirm that you want to delete and then delete organizations" do - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root]).and_return(rest) expect(@knife.ui).to receive(:confirm).with("Do you want to delete the organization #{@org_name}") - expect(root_rest).to receive(:delete).with("organizations/#{@org_name}") + expect(rest).to receive(:delete).with("organizations/#{@org_name}") expect(@knife.ui).to receive(:output) @knife.run end diff --git a/spec/unit/knife/org_edit_spec.rb b/spec/unit/knife/org_edit_spec.rb index 3badaf5168..7a99f1355a 100644 --- a/spec/unit/knife/org_edit_spec.rb +++ b/spec/unit/knife/org_edit_spec.rb @@ -20,7 +20,7 @@ require "spec_helper" describe Chef::Knife::OrgEdit do let(:knife) { Chef::Knife::OrgEdit.new } - let(:root_rest) { double("Chef::ServerAPI") } + let(:rest) { double("Chef::ServerAPI") } before :each do Chef::Knife::OrgEdit.load_deps @@ -31,12 +31,12 @@ describe Chef::Knife::OrgEdit do end it "loads and edits the organisation" do - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root]).and_return(rest) original_data = { "org_name" => "my_org" } data = { "org_name" => "my_org1" } - expect(root_rest).to receive(:get).with("organizations/foobar").and_return(original_data) + expect(rest).to receive(:get).with("organizations/foobar").and_return(original_data) expect(knife).to receive(:edit_hash).with(original_data).and_return(data) - expect(root_rest).to receive(:put).with("organizations/foobar", data) + expect(rest).to receive(:put).with("organizations/foobar", data) knife.run end diff --git a/spec/unit/knife/org_list_spec.rb b/spec/unit/knife/org_list_spec.rb index 1c6fb956af..05fb289e6b 100644 --- a/spec/unit/knife/org_list_spec.rb +++ b/spec/unit/knife/org_list_spec.rb @@ -20,7 +20,7 @@ require "chef/org" describe Chef::Knife::OrgList do - let(:root_rest) { double("Chef::ServerAPI") } + let(:rest) { double("Chef::ServerAPI") } let(:orgs) do { @@ -33,8 +33,8 @@ describe Chef::Knife::OrgList do before :each do @org = double("Chef::Org") @knife = Chef::Knife::OrgList.new - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) - allow(root_rest).to receive(:get).with("organizations").and_return(orgs) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root]).and_return(rest) + allow(rest).to receive(:get).with("organizations").and_return(orgs) end describe "with no arguments" do diff --git a/spec/unit/knife/org_show_spec.rb b/spec/unit/knife/org_show_spec.rb index 6a6260273f..033bf6f14e 100644 --- a/spec/unit/knife/org_show_spec.rb +++ b/spec/unit/knife/org_show_spec.rb @@ -21,24 +21,24 @@ require "chef/org" describe Chef::Knife::OrgShow do - let(:root_rest) { double("Chef::ServerAPI") } + let(:rest) { double("Chef::ServerAPI") } before :each do @knife = Chef::Knife::OrgShow.new @org_name = "foobar" @knife.name_args << @org_name @org = double("Chef::Org") - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) - allow(@org).to receive(:root_rest).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root]).and_return(rest) + allow(@org).to receive(:rest).and_return(rest) end it "should load the organisation" do - expect(root_rest).to receive(:get).with("organizations/#{@org_name}") + expect(rest).to receive(:get).with("organizations/#{@org_name}") @knife.run end it "should pretty print the output organisation" do - expect(root_rest).to receive(:get).with("organizations/#{@org_name}") + expect(rest).to receive(:get).with("organizations/#{@org_name}") expect(@knife.ui).to receive(:output) @knife.run end diff --git a/spec/unit/knife/user_create_spec.rb b/spec/unit/knife/user_create_spec.rb index ec221fb8c0..d763debad1 100644 --- a/spec/unit/knife/user_create_spec.rb +++ b/spec/unit/knife/user_create_spec.rb @@ -40,8 +40,6 @@ describe Chef::Knife::UserCreate do allow(knife.ui).to receive(:warn) end - let(:chef_root_rest_v0) { double("Chef::ServerAPI") } - context "when USERNAME isn't specified" do # from spec/support/shared/unit/knife_shared.rb it_should_behave_like "mandatory field missing" do @@ -86,7 +84,7 @@ describe Chef::Knife::UserCreate do end it "creates an user" do - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root ]).and_return(root_rest) expect(root_rest).to receive(:post).and_return(@user) expect(knife.ui).to receive(:ask).with("Please enter the user's password: ", echo: false).and_return("password") knife.run @@ -102,7 +100,7 @@ describe Chef::Knife::UserCreate do end it "sets all the mandatory fields" do - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root ]).and_return(root_rest) expect(root_rest).to receive(:post).and_return(@user) knife.run expect(knife.user.username).to eq("some_user") @@ -135,7 +133,7 @@ describe Chef::Knife::UserCreate do end it "does not set user.create_key" do - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root ]).and_return(root_rest) expect(root_rest).to receive(:post).and_return(@user) knife.run expect(knife.user.create_key).to be_falsey @@ -144,7 +142,7 @@ describe Chef::Knife::UserCreate do context "when --prevent-keygen is not passed" do it "sets user.create_key to true" do - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root ]).and_return(root_rest) expect(root_rest).to receive(:post).and_return(@user) knife.run expect(knife.user.create_key).to be_truthy @@ -159,7 +157,7 @@ describe Chef::Knife::UserCreate do end it "sets user.public_key" do - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root ]).and_return(root_rest) expect(root_rest).to receive(:post).and_return(@user) knife.run expect(knife.user.public_key).to eq("some_key") @@ -168,7 +166,7 @@ describe Chef::Knife::UserCreate do context "when --user-key is not passed" do it "does not set user.public_key" do - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root ]).and_return(root_rest) expect(root_rest).to receive(:post).and_return(@user) knife.run expect(knife.user.public_key).to be_nil @@ -180,7 +178,7 @@ describe Chef::Knife::UserCreate do before :each do @user = double("Chef::User") - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root ]).and_return(root_rest) expect(root_rest).to receive(:post).and_return(@user) @key = "You don't come into cooking to get rich - Ramsay" allow(@user).to receive(:[]).with("private_key").and_return(@key) diff --git a/spec/unit/knife/user_edit_spec.rb b/spec/unit/knife/user_edit_spec.rb index 1467d05af3..17f2e2e2d3 100644 --- a/spec/unit/knife/user_edit_spec.rb +++ b/spec/unit/knife/user_edit_spec.rb @@ -20,7 +20,7 @@ require "spec_helper" describe Chef::Knife::UserEdit do let(:knife) { Chef::Knife::UserEdit.new } - let(:root_rest) { double("Chef::ServerAPI") } + let(:rest) { double("Chef::ServerAPI") } before(:each) do @stderr = StringIO.new @@ -38,10 +38,10 @@ describe Chef::Knife::UserEdit do @key = "You don't come into cooking to get rich - Ramsay" allow(result).to receive(:[]).with("private_key").and_return(@key) - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) - expect(root_rest).to receive(:get).with("users/my_user2").and_return(data) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root]).and_return(rest) + expect(rest).to receive(:get).with("users/my_user2").and_return(data) expect(knife).to receive(:get_updated_user).with(data).and_return(edited_data) - expect(root_rest).to receive(:put).with("users/my_user2", edited_data).and_return(result) + expect(rest).to receive(:put).with("users/my_user2", edited_data).and_return(result) knife.run end diff --git a/spec/unit/knife/user_password_spec.rb b/spec/unit/knife/user_password_spec.rb index 853e21cd6d..3994ef57cb 100644 --- a/spec/unit/knife/user_password_spec.rb +++ b/spec/unit/knife/user_password_spec.rb @@ -23,14 +23,14 @@ Chef::Knife::UserDelete.load_deps describe Chef::Knife::UserPassword do - let(:root_rest) { double("Chef::ServerAPI") } + let(:rest) { double("Chef::ServerAPI") } before :each do @knife = Chef::Knife::UserPassword.new @user_name = "foobar" @password = "abc123" @user = double("Chef::User") - allow(@user).to receive(:root_rest).and_return(root_rest) + allow(@user).to receive(:rest).and_return(rest) @key = "You don't come into cooking to get rich - Ramsay" end @@ -43,9 +43,9 @@ describe Chef::Knife::UserPassword do result = { "password" => [], "recovery_authentication_enabled" => true } allow(@user).to receive(:[]).with("organization") - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) - expect(@user.root_rest).to receive(:get).with("users/#{@user_name}").and_return(result) - expect(@user.root_rest).to receive(:put).with("users/#{@user_name}", result) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root]).and_return(rest) + expect(@user.rest).to receive(:get).with("users/#{@user_name}").and_return(result) + expect(@user.rest).to receive(:put).with("users/#{@user_name}", result) expect(@knife.ui).to receive(:msg).with("Authentication info updated for #{@user_name}.") @knife.run diff --git a/spec/unit/knife/user_show_spec.rb b/spec/unit/knife/user_show_spec.rb index 941592cb56..9780b6a340 100644 --- a/spec/unit/knife/user_show_spec.rb +++ b/spec/unit/knife/user_show_spec.rb @@ -24,14 +24,13 @@ Chef::Knife::UserShow.load_deps describe Chef::Knife::UserShow do let(:knife) { Chef::Knife::UserShow.new } let(:user_mock) { double("user_mock") } - let(:root_rest) { double("Chef::ServerAPI") } + let(:rest) { double("Chef::ServerAPI") } before :each do @user_name = "foobar" @password = "abc123" @user = double("Chef::User") - allow(@user).to receive(:root_rest).and_return(root_rest) - # allow(Chef::User).to receive(:new).and_return(@user) + allow(@user).to receive(:rest).and_return(rest) @key = "You don't come into cooking to get rich - Ramsay" end @@ -42,14 +41,14 @@ describe Chef::Knife::UserShow do end it "should load the user" do - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) - expect(@user.root_rest).to receive(:get).with("users/my_user") + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root]).and_return(rest) + expect(@user.rest).to receive(:get).with("users/my_user") knife.run end it "loads and displays the user" do - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) - expect(@user.root_rest).to receive(:get).with("users/my_user") + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root]).and_return(rest) + expect(@user.rest).to receive(:get).with("users/my_user") expect(knife).to receive(:format_for_display) knife.run end @@ -81,10 +80,10 @@ describe Chef::Knife::UserShow do result = { "organizations" => [] } knife.config[:with_orgs] = true - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root]).and_return(rest) allow(@org).to receive(:[]).with("organization").and_return({ "name" => "test" }) - expect(@user.root_rest).to receive(:get).with("users/#{@user_name}").and_return(result) - expect(@user.root_rest).to receive(:get).with("users/#{@user_name}/organizations").and_return(orgs) + expect(@user.rest).to receive(:get).with("users/#{@user_name}").and_return(result) + expect(@user.rest).to receive(:get).with("users/#{@user_name}/organizations").and_return(orgs) knife.run end end |