Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

improve error reporting in cctray parsing #3

Merged
merged 1 commit into from over 1 year ago

2 participants

Perryn Fowler Mark Ryall
Perryn Fowler
Collaborator

I had some trouble figuring out why blinky was green working when watching a travis url that had a failing build.

It turned out I had the url slightly wrong and it was returning a 301 with an empty body - which was interpreted as 0 jobs and hence "no failures"

I've made it complain bitterly if it gets a non 200 response or if the body has no jobs

Mark Ryall markryall merged commit b45c06d into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jan 02, 2013
Perryn Fowler perryn report some error cases when reading cctray.xml b030092
This page is out of date. Refresh to see the latest.
52 fixtures/vcr_cassettes/no_projects.yml
... ... @@ -0,0 +1,52 @@
  1 +---
  2 +http_interactions:
  3 +- request:
  4 + method: get
  5 + uri: https://api.travis-ci.org/repositories/markryall/chicanery/cc.xml
  6 + body:
  7 + encoding: US-ASCII
  8 + string: ''
  9 + headers:
  10 + accept:
  11 + - ! '*/*'
  12 + user-agent:
  13 + - Ruby
  14 + response:
  15 + status:
  16 + code: 200
  17 + message: OK
  18 + headers:
  19 + access-control-allow-credentials:
  20 + - 'true'
  21 + access-control-allow-origin:
  22 + - ! '*'
  23 + access-control-expose-headers:
  24 + - Content-Type, Cache-Control, Expires, Etag, Last-Modified
  25 + cache-control:
  26 + - no-cache
  27 + content-type:
  28 + - application/json;charset=utf-8
  29 + date:
  30 + - Sat, 15 Dec 2012 02:39:04 GMT
  31 + etag:
  32 + - ! '"aa451983b94cbec99aa94346f358b5b0"'
  33 + status:
  34 + - 200 OK
  35 + strict-transport-security:
  36 + - max-age=31536000
  37 + vary:
  38 + - Accept,Accept-Encoding
  39 + x-accepted-oauth-scopes:
  40 + - public
  41 + x-oauth-scopes:
  42 + - public
  43 + content-length:
  44 + - '217'
  45 + connection:
  46 + - keep-alive
  47 + body:
  48 + encoding: US-ASCII
  49 + string: ! "Nothing here but us chickens"
  50 + http_version: '1.1'
  51 + recorded_at: Sat, 15 Dec 2012 02:39:09 GMT
  52 +recorded_with: VCR 2.3.0
52 fixtures/vcr_cassettes/redirect.yml
... ... @@ -0,0 +1,52 @@
  1 +---
  2 +http_interactions:
  3 +- request:
  4 + method: get
  5 + uri: https://api.travis-ci.org/repositories/markryall/chicanery/cc.xml
  6 + body:
  7 + encoding: US-ASCII
  8 + string: ''
  9 + headers:
  10 + accept:
  11 + - ! '*/*'
  12 + user-agent:
  13 + - Ruby
  14 + response:
  15 + status:
  16 + code: 301
  17 + message: Redirect
  18 + headers:
  19 + access-control-allow-credentials:
  20 + - 'true'
  21 + access-control-allow-origin:
  22 + - ! '*'
  23 + access-control-expose-headers:
  24 + - Content-Type, Cache-Control, Expires, Etag, Last-Modified
  25 + cache-control:
  26 + - no-cache
  27 + content-type:
  28 + - application/json;charset=utf-8
  29 + date:
  30 + - Sat, 15 Dec 2012 02:39:04 GMT
  31 + etag:
  32 + - ! '"aa451983b94cbec99aa94346f358b5b0"'
  33 + status:
  34 + - 200 OK
  35 + strict-transport-security:
  36 + - max-age=31536000
  37 + vary:
  38 + - Accept,Accept-Encoding
  39 + x-accepted-oauth-scopes:
  40 + - public
  41 + x-oauth-scopes:
  42 + - public
  43 + content-length:
  44 + - '217'
  45 + connection:
  46 + - keep-alive
  47 + body:
  48 + encoding: US-ASCII
  49 + string: ! "hhh"
  50 + http_version: '1.1'
  51 + recorded_at: Sat, 15 Dec 2012 02:39:09 GMT
  52 +recorded_with: VCR 2.3.0
5 lib/chicanery/cctray.rb
@@ -25,12 +25,14 @@ def get
25 25 res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https', verify_mode: OpenSSL::SSL::VERIFY_NONE) do |https|
26 26 https.request(req)
27 27 end
  28 + res.value #check for success via a spectactulalry poorly named method
28 29 res.body
29 30 end
30 31
31 32 def jobs
32 33 jobs = {}
33   - Nokogiri::XML(get).css("Project").each do |project|
  34 + response_body = get
  35 + Nokogiri::XML(response_body).css("Project").each do |project|
34 36 job = {
35 37 activity: project[:activity] == 'Sleeping' ? :sleeping : :building,
36 38 last_build_status: parse_build_status(project[:lastBuildStatus]),
@@ -40,6 +42,7 @@ def jobs
40 42 }
41 43 jobs[project[:name]] = job unless filtered project[:name]
42 44 end
  45 + raise "could not find any jobs in response: [#{response_body}]" if jobs.empty?
43 46 jobs
44 47 end
45 48
13 spec/chicanery/cctray_spec.rb
@@ -52,4 +52,17 @@
52 52 }
53 53 end
54 54 end
  55 +
  56 + it 'should complain if there are no jobs in response' do
  57 + VCR.use_cassette('no_projects') do
  58 + expect{server.jobs}.to raise_error "could not find any jobs in response: [Nothing here but us chickens]"
  59 + end
  60 + end
  61 +
  62 + it 'should complain if it gets a non 2xx response' do
  63 + VCR.use_cassette('redirect') do
  64 + expect{server.jobs}.to raise_error Net::HTTPRetriableError
  65 + end
  66 + end
  67 +
55 68 end

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.