summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorvasu1105 <vasundhara.jagdale@msystechnologies.com>2018-05-11 15:44:55 +0530
committervasu1105 <vasundhara.jagdale@msystechnologies.com>2018-05-15 16:44:41 +0530
commite72c34556fe132919c4b8d879f5eee4ce67b3135 (patch)
treed248c53c27fbe6279efc6a95f48d81bea25bebc5 /spec
parentc0609e449135fae43d436136a4f0fd3889a9b8f1 (diff)
downloadchef-e72c34556fe132919c4b8d879f5eee4ce67b3135.tar.gz
[MSYS-809] Fix for command resource does not handle commands with arguments
Signed-off-by: vasu1105 <vasundhara.jagdale@msystechnologies.com>
Diffstat (limited to 'spec')
-rw-r--r--spec/functional/resource/windows_task_spec.rb84
-rw-r--r--spec/unit/provider/windows_task_spec.rb9
2 files changed, 93 insertions, 0 deletions
diff --git a/spec/functional/resource/windows_task_spec.rb b/spec/functional/resource/windows_task_spec.rb
index 621802bd44..d8a6e6808c 100644
--- a/spec/functional/resource/windows_task_spec.rb
+++ b/spec/functional/resource/windows_task_spec.rb
@@ -31,6 +31,90 @@ describe Chef::Resource::WindowsTask, :windows_only do
describe "action :create" do
after { delete_task }
+ context "when command is with arguments" do
+ subject do
+ new_resource = Chef::Resource::WindowsTask.new(task_name, run_context)
+ new_resource.execution_time_limit = 259200 / 60 # converting "PT72H" into minutes and passing here since win32-taskscheduler accespts this
+ # Make sure MM/DD/YYYY is accepted
+
+ new_resource.start_day "09/20/2017"
+ new_resource.frequency :hourly
+ new_resource
+ end
+
+ it "creates scheduled task and sets command arguments" do
+ subject.command "chef-client -W"
+ call_for_create_action
+ #loading current resource again to check new task is creted and it matches task parameters
+ current_resource = call_for_load_current_resource
+ expect(current_resource.exists).to eq(true)
+ expect(current_resource.task.application_name).to eq("chef-client")
+ expect(current_resource.task.parameters).to eq("-W")
+ end
+
+ it "does not converge the resource if it is already converged" do
+ subject.command "chef-client -W"
+ subject.run_action(:create)
+ subject.command "chef-client -W"
+ subject.run_action(:create)
+ expect(subject).not_to be_updated_by_last_action
+ end
+
+ it "creates scheduled task and sets command arguments" do
+ subject.command "chef-client -W -L 'C:\\chef\\chef-ad-join.log'"
+ call_for_create_action
+ #loading current resource again to check new task is creted and it matches task parameters
+ current_resource = call_for_load_current_resource
+ expect(current_resource.exists).to eq(true)
+ expect(current_resource.task.application_name).to eq("chef-client")
+ expect(current_resource.task.parameters).to eq("-W -L C:\\chef\\chef-ad-join.log")
+ end
+
+ it "does not converge the resource if it is already converged" do
+ subject.command "chef-client -W -L 'C:\\chef\\chef-ad-join.log'"
+ subject.run_action(:create)
+ subject.command "chef-client -W -L 'C:\\chef\\chef-ad-join.log'"
+ subject.run_action(:create)
+ expect(subject).not_to be_updated_by_last_action
+ end
+
+ it "creates scheduled task and sets command arguments" do
+ subject.command '"C:\\Program Files\\example\program.exe" -arg1 --arg2'
+ call_for_create_action
+ #loading current resource again to check new task is creted and it matches task parameters
+ current_resource = call_for_load_current_resource
+ expect(current_resource.exists).to eq(true)
+ expect(current_resource.task.application_name).to eq("C:\\Program Files\\example\\program.exe")
+ expect(current_resource.task.parameters).to eq("-arg1 --arg2")
+ end
+
+ it "does not converge the resource if it is already converged" do
+ subject.command '"C:\\Program Files\\example\program.exe" -arg1 --arg2'
+ subject.run_action(:create)
+ subject.command '"C:\\Program Files\\example\program.exe" -arg1 --arg2'
+ subject.run_action(:create)
+ expect(subject).not_to be_updated_by_last_action
+ end
+
+ it "creates scheduled task and sets command arguments" do
+ subject.command "ping http://www.google.com"
+ call_for_create_action
+ #loading current resource again to check new task is creted and it matches task parameters
+ current_resource = call_for_load_current_resource
+ expect(current_resource.exists).to eq(true)
+ expect(current_resource.task.application_name).to eq("ping")
+ expect(current_resource.task.parameters).to eq("http://www.google.com")
+ end
+
+ it "does not converge the resource if it is already converged" do
+ subject.command "ping http://www.google.com"
+ subject.run_action(:create)
+ subject.command "ping http://www.google.com"
+ subject.run_action(:create)
+ expect(subject).not_to be_updated_by_last_action
+ end
+ end
+
context "when frequency_modifier are not passed" do
subject do
new_resource = Chef::Resource::WindowsTask.new(task_name, run_context)
diff --git a/spec/unit/provider/windows_task_spec.rb b/spec/unit/provider/windows_task_spec.rb
index 603c9d1342..66bd6854b6 100644
--- a/spec/unit/provider/windows_task_spec.rb
+++ b/spec/unit/provider/windows_task_spec.rb
@@ -35,6 +35,15 @@ describe Chef::Provider::WindowsTask, :windows_only do
end
end
+ describe "#set_command_and_arguments" do
+ it "sets the command arguments if command has arguments passed in it" do
+ new_resource.command = "chef-client -W"
+ provider.send(:set_command_and_arguments)
+ expect(new_resource.command).to eq("chef-client")
+ expect(new_resource.command_arguments).to eq("-W")
+ end
+ end
+
describe "#set_start_day_and_time" do
it "sets the curret date and time start_day and start_time if nothing is provided by user" do
new_resource.start_day = nil