Skip to content

Commit

Permalink
(CAT-1869) - Add tests for timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanbreen28 committed Jun 11, 2024
1 parent a6e1419 commit 8a31945
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@
subject(:result) { provider.invoke_set_method(context, name, should_hash) }

let(:name) { { name: 'foo', dsc_name: 'foo' } }
let(:should_hash) { name.merge(dsc_foo: 'bar') }
let(:should_hash) { name.merge(dsc_foo: 'bar')}

Check failure on line 760 in spec/unit/puppet/provider/dsc_base_provider/dsc_base_provider_spec.rb

View workflow job for this annotation

GitHub Actions / spec (ruby 2.7 | puppet ~> 7.0) / spec

Layout/SpaceInsideBlockBraces: Space missing inside }.

Check failure on line 760 in spec/unit/puppet/provider/dsc_base_provider/dsc_base_provider_spec.rb

View workflow job for this annotation

GitHub Actions / spec (ruby 3.2 | puppet ~> 8.0) / spec

Layout/SpaceInsideBlockBraces: Space missing inside }.
let(:apply_props) { { dsc_name: 'foo', dsc_foo: 'bar' } }
let(:resource) { "Resource: #{apply_props}" }
let(:script) { "Script: #{apply_props}" }
Expand All @@ -783,7 +783,7 @@
context 'when the invocation script returns nil' do
it 'errors via context but does not raise' do
expect(ps_manager).to receive(:execute).and_return({ stdout: nil })
expect(context).to receive(:err).with('Nothing returned.')
expect(context).to receive(:err).with(/Nothing returned./)
expect { result }.not_to raise_error
end
end
Expand Down Expand Up @@ -835,6 +835,26 @@
end
end

context 'when a dsc_timeout is specified' do
let(:should_hash) { name.merge(dsc_timeout: 5) }
let(:apply_props_with_timeout) { { dsc_name: 'foo', dsc_timeout: 5 } }
let(:resource_with_timeout) { "Resource: #{apply_props_with_timeout}" }
let(:script_with_timeout) { "Script: #{apply_props_with_timeout}" }

Check failure on line 843 in spec/unit/puppet/provider/dsc_base_provider/dsc_base_provider_spec.rb

View workflow job for this annotation

GitHub Actions / spec (ruby 2.7 | puppet ~> 7.0) / spec

Layout/TrailingWhitespace: Trailing whitespace detected.

Check failure on line 843 in spec/unit/puppet/provider/dsc_base_provider/dsc_base_provider_spec.rb

View workflow job for this annotation

GitHub Actions / spec (ruby 3.2 | puppet ~> 8.0) / spec

Layout/TrailingWhitespace: Trailing whitespace detected.
before do
allow(provider).to receive(:invocable_resource).with(apply_props_with_timeout, context, 'set').and_return(resource_with_timeout)
allow(provider).to receive(:ps_script_content).with(resource_with_timeout).and_return(script_with_timeout)
allow(provider).to receive(:remove_secret_identifiers).with(script_with_timeout).and_return(script_with_timeout)
end

Check failure on line 849 in spec/unit/puppet/provider/dsc_base_provider/dsc_base_provider_spec.rb

View workflow job for this annotation

GitHub Actions / spec (ruby 2.7 | puppet ~> 7.0) / spec

Layout/TrailingWhitespace: Trailing whitespace detected.

Check failure on line 849 in spec/unit/puppet/provider/dsc_base_provider/dsc_base_provider_spec.rb

View workflow job for this annotation

GitHub Actions / spec (ruby 3.2 | puppet ~> 8.0) / spec

Layout/TrailingWhitespace: Trailing whitespace detected.
it 'sets @timeout and passes it to ps_manager.execute' do
provider.instance_variable_set(:@timeout, nil)
expect(ps_manager).to receive(:execute).with(script_with_timeout, 5000).and_return({ stdout: '{"in_desired_state": true, "errormessage": null}' })
provider.invoke_set_method(context, name, should_hash)
expect(provider.instance_variable_get(:@timeout)).to eq(5000)
end
end

context 'when the invocation script returns data without errors' do
it 'filters for the correct properties to invoke and returns the results' do
expect(ps_manager).to receive(:execute).with("Script: #{apply_props}", nil).and_return({ stdout: '{"in_desired_state": true, "errormessage": null}' })
Expand Down

0 comments on commit 8a31945

Please sign in to comment.