Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion spec/tasks/abs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
include_context('with tmpdir')

def with_env(env_vars)
previous = {}
env_vars.each_key { |k| previous[k] = ENV.fetch(k, nil) }
env_vars.each { |k, v| ENV[k] = v }
yield
ensure
env_vars.each { |k, _v| ENV.delete(k) }
previous.each { |k, v| v.nil? ? ENV.delete(k) : (ENV[k] = v) }
end

before(:each) do
Expand Down Expand Up @@ -120,7 +122,40 @@
expect(abs.task(**params)).to eq({ status: 'ok', nodes: 1 })
end

it 'raises an error if abs returns error response'

Check warning on line 125 in spec/tasks/abs_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 9.0, Ruby Ver: 4)

provision::abs when provisioning raises an error if abs returns error response Skipped: Not yet implemented

Check warning on line 125 in spec/tasks/abs_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

provision::abs when provisioning raises an error if abs returns error response Skipped: Not yet implemented

it 'requests priority 3 (not 1) when running in CI' do
request = stub_request(:post, 'https://abs-prod.k8s.infracore.puppet.net/api/v2/request')
.with { |req| JSON.parse(req.body)['priority'] == 3 }
.to_return({ status: 202 }, { status: 200, body: response_body.to_json })

with_env('CI' => 'true') do
expect(abs.task(**params)).to eq({ status: 'ok', nodes: 1 })
end
Comment thread
isaac-jha marked this conversation as resolved.
expect(request).to have_been_made.at_least_once
end

it "requests priority 3 for AppVeyor's capitalized CI=True" do
request = stub_request(:post, 'https://abs-prod.k8s.infracore.puppet.net/api/v2/request')
.with { |req| JSON.parse(req.body)['priority'] == 3 }
.to_return({ status: 202 }, { status: 200, body: response_body.to_json })

with_env('CI' => 'True') do
expect(abs.task(**params)).to eq({ status: 'ok', nodes: 1 })
end
expect(request).to have_been_made.at_least_once
end

it 'requests priority 2 for local/non-CI runs' do
request = stub_request(:post, 'https://abs-prod.k8s.infracore.puppet.net/api/v2/request')
.with { |req| JSON.parse(req.body)['priority'] == 2 }
.to_return({ status: 202 }, { status: 200, body: response_body.to_json })

with_env('CI' => 'false') do
expect(abs.task(**params)).to eq({ status: 'ok', nodes: 1 })
end
expect(request).to have_been_made.at_least_once
end
end

context 'when tearing down' do
Expand Down Expand Up @@ -168,6 +203,6 @@
end
end

it 'raises an error if abs returns error response'

Check warning on line 206 in spec/tasks/abs_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 9.0, Ruby Ver: 4)

provision::abs when tearing down raises an error if abs returns error response Skipped: Not yet implemented

Check warning on line 206 in spec/tasks/abs_spec.rb

View workflow job for this annotation

GitHub Actions / Spec / Spec tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

provision::abs when tearing down raises an error if abs returns error response Skipped: Not yet implemented
end
end
4 changes: 3 additions & 1 deletion tasks/abs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def provision(platform, inventory, vars)
job_id = "iac-task-pid-#{Process.pid}-#{DateTime.now.strftime('%Q')}"

headers = { 'X-AUTH-TOKEN' => token_from_fogfile('abs'), 'Content-Type' => 'application/json' }
priority = ENV['CI'] ? 1 : 2
# ENV['CI'] is a string, so `? 1 : 2` was always truthy and made every CI run priority 1.
# casecmp? matches 'true'/'True' (Travis, GitHub Actions, AppVeyor all set CI).
priority = ENV['CI'].to_s.casecmp?('true') ? 3 : 2
payload = if platform.instance_of?(String)
{ 'resources' => { platform => 1 },
'priority' => priority,
Expand Down
Loading