summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorsnehaldwivedi <sdwivedi@msystechnologies.com>2020-08-06 06:36:57 -0700
committersnehaldwivedi <sdwivedi@msystechnologies.com>2021-02-16 02:45:13 -0800
commitc9080be779d38478960425b53afc08fd52a96562 (patch)
tree2c0a64df18d77d957b5aceebd8636ae16ac3c198 /spec
parent43c05d73aa15b1d5148ccacf36e2f6def5c814e4 (diff)
downloadchef-c9080be779d38478960425b53afc08fd52a96562.tar.gz
Updated reviewed changes for copyrights and roo_rest
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/knife/org_delete_spec.rb18
-rw-r--r--spec/unit/knife/org_list_spec.rb12
-rw-r--r--spec/unit/knife/org_show_spec.rb19
-rw-r--r--spec/unit/knife/org_user_add_spec.rb2
-rw-r--r--spec/unit/knife/user_create_spec.rb46
-rw-r--r--spec/unit/knife/user_delete_spec.rb4
-rw-r--r--spec/unit/knife/user_edit_spec.rb2
-rw-r--r--spec/unit/knife/user_list_spec.rb2
-rw-r--r--spec/unit/knife/user_password_spec.rb18
-rw-r--r--spec/unit/knife/user_show_spec.rb30
10 files changed, 80 insertions, 73 deletions
diff --git a/spec/unit/knife/org_delete_spec.rb b/spec/unit/knife/org_delete_spec.rb
index a39965c761..aa457cd414 100644
--- a/spec/unit/knife/org_delete_spec.rb
+++ b/spec/unit/knife/org_delete_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Snehal Dwivedi (<sdwivedi@msystechnologies.com>)
-# Copyright:: Copyright 2014-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,25 +17,25 @@
#
require "spec_helper"
+require "chef/org"
describe Chef::Knife::OrgDelete do
+ let(:chef_rest) { double("Chef::ServerAPI") }
+
before :each do
@knife = Chef::Knife::OrgDelete.new
@org_name = "foobar"
+ @org_full_name = "secretsauce"
@knife.name_args << @org_name
- end
-
- let(:rest) do
- Chef::Config[:chef_server_root] = "http://www.example.com"
- root_rest = double("rest")
- allow(Chef::ServerAPI).to receive(:new).and_return(root_rest)
+ @org = double("Chef::Org")
end
it "should confirm that you want to delete and then delete organizations" do
- allow(@knife).to receive(:root_rest).and_return(rest)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(chef_rest)
+ allow(@org).to receive(:chef_rest).and_return(chef_rest)
expect(@knife.ui).to receive(:confirm).with("Do you want to delete the organization #{@org_name}")
- expect(rest).to receive(:delete).with("organizations/#{@org_name}")
+ expect(@org.chef_rest).to receive(:delete).with("organizations/#{@org_name}")
expect(@knife.ui).to receive(:output)
@knife.run
end
diff --git a/spec/unit/knife/org_list_spec.rb b/spec/unit/knife/org_list_spec.rb
index de4affe83c..d4152b66e3 100644
--- a/spec/unit/knife/org_list_spec.rb
+++ b/spec/unit/knife/org_list_spec.rb
@@ -1,5 +1,5 @@
#
-# Copyright:: Copyright 2014-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,9 +16,12 @@
#
require "spec_helper"
+require "chef/org"
describe Chef::Knife::OrgList do
+ let(:chef_rest) { double("Chef::ServerAPI") }
+
let(:orgs) do
{
"org1" => "first",
@@ -28,10 +31,11 @@ describe Chef::Knife::OrgList do
end
before :each do
- @rest = double("Chef::ServerAPI")
- allow(Chef::ServerAPI).to receive(:new).and_return(@rest)
- allow(@rest).to receive(:get).with("organizations").and_return(orgs)
+ @org = double("Chef::Org")
@knife = Chef::Knife::OrgList.new
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(chef_rest)
+ allow(@org).to receive(:chef_rest).and_return(chef_rest)
+ allow(@org.chef_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 7c7e044b64..90765f4273 100644
--- a/spec/unit/knife/org_show_spec.rb
+++ b/spec/unit/knife/org_show_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Snehal Dwivedi (<sdwivedi@msystechnologies.com>)
-# Copyright:: Copyright 2011-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,27 +21,24 @@ require "chef/org"
describe Chef::Knife::OrgShow do
+ let(:chef_rest) { double("Chef::ServerAPI") }
+
before :each do
@knife = Chef::Knife::OrgShow.new
@org_name = "foobar"
@knife.name_args << @org_name
- end
-
- let(:rest) do
- Chef::Config[:chef_server_root] = "http://www.example.com"
- root_rest = double("rest")
- allow(Chef::ServerAPI).to receive(:new).and_return(root_rest)
+ @org = double("Chef::Org")
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url]).and_return(chef_rest)
+ allow(@org).to receive(:chef_rest).and_return(chef_rest)
end
it "should load the organisation" do
- allow(@knife).to receive(:root_rest).and_return(rest)
- expect(rest).to receive(:get).with("organizations/#{@org_name}")
+ expect(@org.chef_rest).to receive(:get).with("organizations/#{@org_name}")
@knife.run
end
it "should pretty print the output organisation" do
- allow(@knife).to receive(:root_rest).and_return(rest)
- expect(rest).to receive(:get).with("organizations/#{@org_name}")
+ expect(@org.chef_rest).to receive(:get).with("organizations/#{@org_name}")
expect(@knife.ui).to receive(:output)
@knife.run
end
diff --git a/spec/unit/knife/org_user_add_spec.rb b/spec/unit/knife/org_user_add_spec.rb
index b92ceaed21..20e28d6919 100644
--- a/spec/unit/knife/org_user_add_spec.rb
+++ b/spec/unit/knife/org_user_add_spec.rb
@@ -1,5 +1,5 @@
#
-# Copyright:: Copyright 2014-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/spec/unit/knife/user_create_spec.rb b/spec/unit/knife/user_create_spec.rb
index 16479402a1..3a97d12817 100644
--- a/spec/unit/knife/user_create_spec.rb
+++ b/spec/unit/knife/user_create_spec.rb
@@ -1,7 +1,7 @@
#
# Author:: Steven Danna (<steve@chef.io>)
# Author:: Tyler Cloke (<tyler@chef.io>)
-# Copyright:: Copyright 2011-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -38,11 +38,7 @@ describe Chef::Knife::UserCreate do
allow(knife.ui).to receive(:warn)
end
- let(:rest) do
- Chef::Config[:chef_server_root] = "http://www.example.com"
- root_rest = double("rest")
- allow(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root]).and_return(root_rest)
- end
+ let(:chef_root_rest_v0) { double("Chef::ServerAPI") }
context "when USERNAME isn't specified" do
# from spec/support/shared/unit/knife_shared.rb
@@ -81,6 +77,8 @@ 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: "0" }).and_return(chef_root_rest_v0)
+ allow(@user).to receive(:chef_root_rest_v0).and_return(chef_root_rest_v0)
allow(Chef::User).to receive(:new).and_return(@user)
@key = "You don't come into cooking to get rich - Ramsay"
allow(@user).to receive(:[]).with("private_key").and_return(@key)
@@ -89,8 +87,7 @@ describe Chef::Knife::UserCreate do
end
it "creates an user" do
- allow(knife).to receive(:root_rest).and_return(rest)
- expect(rest).to receive(:post).and_return(@user)
+ expect(@user.chef_root_rest_v0).to receive(:post).and_return(@user)
knife.run
end
end
@@ -99,6 +96,7 @@ describe Chef::Knife::UserCreate do
before do
@user = double("Chef::User")
allow(Chef::User).to receive(:new).and_return(@user)
+ allow(@user).to receive(:chef_root_rest_v0).and_return(chef_root_rest_v0)
@key = "You don't come into cooking to get rich - Ramsay"
allow(@user).to receive(:[]).with("private_key").and_return(@key)
knife.name_args = %w{some_user some_display_name some_first_name some_last_name some_email some_password}
@@ -110,8 +108,8 @@ describe Chef::Knife::UserCreate do
end
it "sets all the mandatory fields" do
- allow(knife).to receive(:root_rest).and_return(rest)
- expect(rest).to receive(:post).and_return(@user)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "0" }).and_return(chef_root_rest_v0)
+ expect(@user.chef_root_rest_v0).to receive(:post).and_return(@user)
knife.run
expect(knife.user.username).to eq("some_user")
expect(knife.user.display_name).to eq("some_display_name")
@@ -125,6 +123,7 @@ describe Chef::Knife::UserCreate do
knife.config[:user_key] = "some_key"
knife.config[:prevent_keygen] = true
end
+
it "prints the usage" do
expect(knife).to receive(:show_usage)
expect { knife.run }.to raise_error(SystemExit)
@@ -142,8 +141,8 @@ describe Chef::Knife::UserCreate do
end
it "does not set user.create_key" do
- allow(knife).to receive(:root_rest).and_return(rest)
- expect(rest).to receive(:post).and_return(@user)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "0" }).and_return(chef_root_rest_v0)
+ expect(@user.chef_root_rest_v0).to receive(:post).and_return(@user)
knife.run
expect(knife.user.create_key).to be_falsey
end
@@ -151,8 +150,8 @@ describe Chef::Knife::UserCreate do
context "when --prevent-keygen is not passed" do
it "sets user.create_key to true" do
- allow(knife).to receive(:root_rest).and_return(rest)
- expect(rest).to receive(:post).and_return(@user)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "0" }).and_return(chef_root_rest_v0)
+ expect(@user.chef_root_rest_v0).to receive(:post).and_return(@user)
knife.run
expect(knife.user.create_key).to be_truthy
end
@@ -166,8 +165,8 @@ describe Chef::Knife::UserCreate do
end
it "sets user.public_key" do
- allow(knife).to receive(:root_rest).and_return(rest)
- expect(rest).to receive(:post).and_return(@user)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "0" }).and_return(chef_root_rest_v0)
+ expect(@user.chef_root_rest_v0).to receive(:post).and_return(@user)
knife.run
expect(knife.user.public_key).to eq("some_key")
end
@@ -175,8 +174,8 @@ describe Chef::Knife::UserCreate do
context "when --user-key is not passed" do
it "does not set user.public_key" do
- allow(knife).to receive(:root_rest).and_return(rest)
- expect(rest).to receive(:post).and_return(@user)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "0" }).and_return(chef_root_rest_v0)
+ expect(@user.chef_root_rest_v0).to receive(:post).and_return(@user)
knife.run
expect(knife.user.public_key).to be_nil
end
@@ -188,14 +187,15 @@ describe Chef::Knife::UserCreate do
before :each do
@user = double("Chef::User")
allow(Chef::User).to receive(:new).and_return(@user)
+ allow(@user).to receive(:chef_root_rest_v0).and_return(chef_root_rest_v0)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "0" }).and_return(chef_root_rest_v0)
+ expect(@user.chef_root_rest_v0).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)
knife.name_args = name_args
end
it "creates an user" do
- allow(knife).to receive(:root_rest).and_return(rest)
- expect(rest).to receive(:post).and_return(@user)
expect(knife.ui).to receive(:msg).with(@key)
knife.run
end
@@ -212,10 +212,8 @@ describe Chef::Knife::UserCreate do
}
it "creates an user, associates a user, and adds it to the admins group" do
- allow(knife).to receive(:root_rest).and_return(rest)
- expect(rest).to receive(:post).and_return(@user)
- expect(rest).to receive(:post).with("organizations/ramsay/association_requests", request_body).and_return(@user)
- expect(rest).to receive(:put).with("users/some_user/association_requests/1", { response: "accept" })
+ expect(@user.chef_root_rest_v0).to receive(:post).with("organizations/ramsay/association_requests", request_body).and_return(@user)
+ expect(@user.chef_root_rest_v0).to receive(:put).with("users/some_user/association_requests/1", { response: "accept" })
knife.run
end
end
diff --git a/spec/unit/knife/user_delete_spec.rb b/spec/unit/knife/user_delete_spec.rb
index 924cc44b8d..64d9679895 100644
--- a/spec/unit/knife/user_delete_spec.rb
+++ b/spec/unit/knife/user_delete_spec.rb
@@ -1,5 +1,5 @@
#
-# # Copyright:: Copyright 2014-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,6 +18,8 @@
require "spec_helper"
require "chef/org"
+Chef::Knife::UserDelete.load_deps
+
describe Chef::Knife::UserDelete do
subject(:knife) { Chef::Knife::UserDelete.new }
diff --git a/spec/unit/knife/user_edit_spec.rb b/spec/unit/knife/user_edit_spec.rb
index c160f8c402..54a44890e0 100644
--- a/spec/unit/knife/user_edit_spec.rb
+++ b/spec/unit/knife/user_edit_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Steven Danna (<steve@chef.io>)
-# Copyright:: Copyright 2011-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/spec/unit/knife/user_list_spec.rb b/spec/unit/knife/user_list_spec.rb
index a5895cf82d..d91ec09434 100644
--- a/spec/unit/knife/user_list_spec.rb
+++ b/spec/unit/knife/user_list_spec.rb
@@ -18,6 +18,8 @@
require "spec_helper"
+Chef::Knife::UserList.load_deps
+
describe Chef::Knife::UserList do
let(:knife) { Chef::Knife::UserList.new }
diff --git a/spec/unit/knife/user_password_spec.rb b/spec/unit/knife/user_password_spec.rb
index c34f2074a5..d53abfb34d 100644
--- a/spec/unit/knife/user_password_spec.rb
+++ b/spec/unit/knife/user_password_spec.rb
@@ -19,23 +19,22 @@
require "spec_helper"
require "chef/org"
+Chef::Knife::UserDelete.load_deps
+
describe Chef::Knife::UserPassword do
+ let(:chef_root_rest_v0) { double("Chef::ServerAPI") }
+
before :each do
@knife = Chef::Knife::UserPassword.new
@user_name = "foobar"
@password = "abc123"
@user = double("Chef::User")
+ allow(@user).to receive(:chef_root_rest_v0).and_return(chef_root_rest_v0)
allow(Chef::User).to receive(:new).and_return(@user)
@key = "You don't come into cooking to get rich - Ramsay"
end
- let(:rest) do
- Chef::Config[:chef_server_root] = "http://www.example.com"
- root_rest = double("rest")
- allow(Chef::ServerAPI).to receive(:new).and_return(root_rest)
- end
-
describe "should change user's password" do
before :each do
@knife.name_args << @user_name << @password
@@ -43,12 +42,11 @@ describe Chef::Knife::UserPassword do
it "with username and password" do
result = { "password" => [], "recovery_authentication_enabled" => true }
-
- allow(@knife).to receive(:root_rest).and_return(rest)
allow(@user).to receive(:[]).with("organization")
- expect(rest).to receive(:get).with("users/#{@user_name}").and_return(result)
- expect(rest).to receive(:put).with("users/#{@user_name}", result)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "0" }).and_return(chef_root_rest_v0)
+ expect(@user.chef_root_rest_v0).to receive(:get).with("users/#{@user_name}").and_return(result)
+ expect(@user.chef_root_rest_v0).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 ec473f5e7c..273cf638ee 100644
--- a/spec/unit/knife/user_show_spec.rb
+++ b/spec/unit/knife/user_show_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Steven Danna (<steve@chef.io>)
-# Copyright:: Copyright 2011-2016 Chef Software, Inc.
+# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,14 +19,20 @@
require "spec_helper"
require "chef/org"
+Chef::Knife::UserShow.load_deps
+
describe Chef::Knife::UserShow do
let(:knife) { Chef::Knife::UserShow.new }
let(:user_mock) { double("user_mock") }
+ let(:chef_root_rest_v0) { double("Chef::ServerAPI") }
- let(:rest) do
- Chef::Config[:chef_server_root] = "http://www.example.com"
- root_rest = double("rest")
- allow(Chef::ServerAPI).to receive(:new).and_return(root_rest)
+ before :each do
+ @user_name = "foobar"
+ @password = "abc123"
+ @user = double("Chef::User")
+ allow(@user).to receive(:chef_root_rest_v0).and_return(chef_root_rest_v0)
+ allow(Chef::User).to receive(:new).and_return(@user)
+ @key = "You don't come into cooking to get rich - Ramsay"
end
describe "withot organisation argument" do
@@ -36,14 +42,14 @@ describe Chef::Knife::UserShow do
end
it "should load the user" do
- allow(knife).to receive(:root_rest).and_return(rest)
- expect(rest).to receive(:get).with("users/my_user")
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "0" }).and_return(chef_root_rest_v0)
+ expect(@user.chef_root_rest_v0).to receive(:get).with("users/my_user")
knife.run
end
it "loads and displays the user" do
- allow(knife).to receive(:root_rest).and_return(rest)
- expect(rest).to receive(:get).with("users/my_user")
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "0" }).and_return(chef_root_rest_v0)
+ expect(@user.chef_root_rest_v0).to receive(:get).with("users/my_user")
expect(knife).to receive(:format_for_display)
knife.run
end
@@ -75,10 +81,10 @@ describe Chef::Knife::UserShow do
result = { "organizations" => [] }
knife.config[:with_orgs] = true
- allow(knife).to receive(:root_rest).and_return(rest)
+ expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "0" }).and_return(chef_root_rest_v0)
allow(@org).to receive(:[]).with("organization").and_return({ "name" => "test" })
- expect(rest).to receive(:get).with("users/#{@user_name}").and_return(result)
- expect(rest).to receive(:get).with("users/#{@user_name}/organizations").and_return(orgs)
+ expect(@user.chef_root_rest_v0).to receive(:get).with("users/#{@user_name}").and_return(result)
+ expect(@user.chef_root_rest_v0).to receive(:get).with("users/#{@user_name}/organizations").and_return(orgs)
knife.run
end
end