mirror of
https://github.com/inspec/inspec
synced 2024-11-10 07:04:15 +00:00
Functional tests for command resource timeout
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
This commit is contained in:
parent
e5b74b5760
commit
8df0fb0814
3 changed files with 54 additions and 0 deletions
11
test/fixtures/profiles/timeouts/controls/inline-timeout.rb
vendored
Normal file
11
test/fixtures/profiles/timeouts/controls/inline-timeout.rb
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
control "timeout-test-01" do
|
||||
# Do something that will timeout, with inline timeout option
|
||||
describe command("sleep 10; echo oops", timeout: 2) do
|
||||
its("stdout") { should be_empty }
|
||||
end
|
||||
|
||||
# Validate that the connection still works after a timeout
|
||||
describe command("echo hello") do
|
||||
its("exit_status") { should cmp 0 }
|
||||
end
|
||||
end
|
10
test/fixtures/profiles/timeouts/inspec.yml
vendored
Normal file
10
test/fixtures/profiles/timeouts/inspec.yml
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
name: sleepy
|
||||
title: InSpec Profile
|
||||
maintainer: The Authors
|
||||
copyright: The Authors
|
||||
copyright_email: you@example.com
|
||||
license: Apache-2.0
|
||||
summary: A profile that contains tests that take a long time to execute, to test the command timeout feature
|
||||
version: 0.1.0
|
||||
supports:
|
||||
platform: os
|
|
@ -1051,4 +1051,37 @@ Test Summary: 2 successful, 0 failures, 0 skipped\n"
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "when running a profile using timeouts on a command resource" do
|
||||
let(:profile) { "#{profile_path}/timeouts" }
|
||||
|
||||
describe "when using the DSL command resource option" do
|
||||
let(:run_result) { run_inspec_process("exec #{profile}") }
|
||||
|
||||
it "properly timesout an inlined command resource" do
|
||||
# Command timeout not available on local windows pipe train transports
|
||||
skip if windows?
|
||||
_(run_result.stderr).must_be_empty
|
||||
|
||||
# Control with inline timeout should be interrupted correctly
|
||||
_(run_result.stdout).must_include "Command `sleep 10; echo oops` timed out after 2 seconds"
|
||||
# Subsequent control must still run correctly
|
||||
_(run_result.stdout).must_include "Command: `echo hello` exit_status is expected to cmp == 0"
|
||||
end
|
||||
end
|
||||
|
||||
describe "when using the CLI option to override the command timeout" do
|
||||
let(:run_result) { run_inspec_process("exec #{profile} --command-timeout 1") }
|
||||
it "properly overrides the DSL setting with the CLI timeout option" do
|
||||
# Command timeout not available on local windows pipe train transports
|
||||
skip if windows?
|
||||
_(run_result.stderr).must_be_empty
|
||||
|
||||
# Command timeout should be interrupted correctly, with CLI timeout applied
|
||||
_(run_result.stdout).must_include "Command `sleep 10; echo oops` timed out after 1 seconds"
|
||||
# Subsequent control must still run correctly
|
||||
_(run_result.stdout).must_include "Command: `echo hello` exit_status is expected to cmp == 0"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue