Skip to content
This repository was archived by the owner on Mar 24, 2022. It is now read-only.

Commit d2afc71

Browse files
Elana Korenpivotal
authored andcommitted
Get integration test working for concourse V2 projects [#131657693]
Signed-off-by: Ian Fisher <[email protected]>
1 parent a3c6f99 commit d2afc71

File tree

6 files changed

+100
-7
lines changed

6 files changed

+100
-7
lines changed

lib/concourse_authenticator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ def authenticate(url, username, password)
1919
end
2020

2121
request.errback do |client|
22-
# do we actually want to yield this?
2322
yield PollState::FAILED, client.error
2423
end
2524
else
2625
puts 'Error: Is your Concourse project set up correctly?'
26+
yield PollState::FAILED
2727
end
2828
end
2929
end

lib/concourse_project_strategy.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ def create_handler(project)
1010

1111
def create_workload(project)
1212
workload = PollerWorkload.new
13-
workload.add_job(:concourse_project, project)
13+
workload.add_job(:concourse_project, project.feed_url)
1414
workload
1515
end
1616

1717
# returns a request that gets callback/errback assigned to it
1818
def fetch_status(project, url)
19-
@concourse_authenticator.authenticate do |session_token|
19+
@concourse_authenticator.authenticate(project.auth_url, project.auth_username, project.auth_password) do |session_token|
2020
request_options = {
2121
head: {'Set-Cookie' => "ATC-Authorization=Bearer #{session_token}"}
2222
}
@@ -30,7 +30,6 @@ def fetch_status(project, url)
3030

3131
request.callback do |client|
3232
yield PollState::SUCCEEDED, client.response
33-
3433
end
3534

3635
request.errback do |client|

spec/integration/project_polling_scheduler_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@
4040
expect(p.tracker_online).to eq(true)
4141
end
4242

43+
it 'should update concourse (V2) projects' do
44+
project = create(:concourse_project)
45+
project.update_attributes(
46+
ci_base_url: 'https://jetway.pivotal.io',
47+
ci_build_identifier: 'build',
48+
concourse_pipeline_name: 'augur-production',
49+
)
50+
51+
log_entry_count = PayloadLogEntry.count
52+
53+
VCR.use_cassette('poller_concourse_run_once') do
54+
subject.run_once
55+
end
56+
57+
expect(PayloadLogEntry.count).to eq(log_entry_count + 1)
58+
end
59+
4360
it 'should exit gracefully when there are no projects' do
4461
Project.delete_all
4562

spec/lib/concourse_authenticator_spec.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,19 @@
3434

3535
it 'should log an error' do
3636
expect {
37-
subject.authenticate('https://auth/url', 'user', 'pass')
37+
subject.authenticate('https://auth/url', 'user', 'pass') {}
3838
}.to output(/Error/).to_stdout
3939
end
40+
41+
it 'should yield a failure' do
42+
flag = false
43+
44+
subject.authenticate('url', 'uname', 'pw') do |_flag, response|
45+
flag = _flag
46+
end
47+
48+
expect(flag).to eq(PollState::FAILED)
49+
end
4050
end
4151

4252
context 'when the request fails because of a network error' do

spec/lib/concourse_project_strategy_spec.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
let(:request_double) { double(:request) }
55
let(:client_double) { double(:client, response: 'some response', error: 'some error') }
66
let(:requester) { double(:http_requester, initiate_request: request_double) }
7-
let(:project) { build(:concourse_project) }
7+
let(:project) { build(:concourse_project,
8+
ci_base_url: 'http://concourse.com',
9+
auth_username: 'me',
10+
auth_password: 'pw')
11+
}
812
let(:concourse_authenticator) { double(:concourse_authenticator) }
913

1014
subject { ConcourseProjectStrategy.new(requester, concourse_authenticator) }
@@ -15,7 +19,7 @@
1519
before do
1620
allow(request_double).to receive(:callback).and_return(client_double)
1721
allow(request_double).to receive(:errback).and_return(client_double)
18-
allow(concourse_authenticator).to receive(:authenticate).and_yield('session-token')
22+
allow(concourse_authenticator).to receive(:authenticate).with(project.auth_url, project.auth_username, project.auth_password).and_yield('session-token')
1923
end
2024

2125
it 'makes a request to the auth endpoint, then makes a request for the build status' do

spec/vcr_cassettes/poller_concourse_run_once.yml

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)