go_api_client 0.5.4 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.travis.yml +26 -0
  4. data/README.md +86 -0
  5. data/go_api_client.gemspec +11 -11
  6. data/lib/go_api_client/api/abstract_api.rb +12 -0
  7. data/lib/go_api_client/api/cctray.rb +53 -0
  8. data/lib/go_api_client/api/config.rb +60 -0
  9. data/lib/go_api_client/api/feed.rb +39 -0
  10. data/lib/go_api_client/api/job.rb +34 -0
  11. data/lib/go_api_client/api/pipeline.rb +87 -0
  12. data/lib/go_api_client/api/properties.rb +43 -0
  13. data/lib/go_api_client/api/stage.rb +45 -0
  14. data/lib/go_api_client/attribute_helper.rb +9 -0
  15. data/lib/go_api_client/client.rb +20 -0
  16. data/lib/go_api_client/domain/artifact.rb +16 -0
  17. data/lib/go_api_client/domain/author.rb +22 -0
  18. data/lib/go_api_client/domain/changeset.rb +13 -0
  19. data/lib/go_api_client/domain/config/job.rb +15 -0
  20. data/lib/go_api_client/domain/config/pipeline.rb +15 -0
  21. data/lib/go_api_client/domain/config/stage.rb +15 -0
  22. data/lib/go_api_client/domain/entry.rb +13 -0
  23. data/lib/go_api_client/domain/feed.rb +13 -0
  24. data/lib/go_api_client/domain/internal_cache.rb +28 -0
  25. data/lib/go_api_client/domain/job.rb +17 -0
  26. data/lib/go_api_client/domain/material.rb +14 -0
  27. data/lib/go_api_client/domain/pipeline.rb +27 -0
  28. data/lib/go_api_client/domain/project.rb +14 -0
  29. data/lib/go_api_client/domain/scheduled_job.rb +12 -0
  30. data/lib/go_api_client/domain/stage.rb +28 -0
  31. data/lib/go_api_client/domain/user.rb +30 -0
  32. data/lib/go_api_client/http_fetcher.rb +73 -48
  33. data/lib/go_api_client/parsers/artifact_parser.rb +17 -0
  34. data/lib/go_api_client/parsers/author_parser.rb +24 -0
  35. data/lib/go_api_client/parsers/changeset.rb +26 -0
  36. data/lib/go_api_client/parsers/config/job_parser.rb +48 -0
  37. data/lib/go_api_client/parsers/config/pipeline_parser.rb +42 -0
  38. data/lib/go_api_client/parsers/config/stage_parser.rb +33 -0
  39. data/lib/go_api_client/parsers/entry_parser.rb +27 -0
  40. data/lib/go_api_client/parsers/feed_parser.rb +27 -0
  41. data/lib/go_api_client/parsers/job_parser.rb +47 -0
  42. data/lib/go_api_client/parsers/material_parser.rb +29 -0
  43. data/lib/go_api_client/parsers/parser_helper.rb +11 -0
  44. data/lib/go_api_client/parsers/pipeline_parser.rb +30 -0
  45. data/lib/go_api_client/parsers/project_parser.rb +26 -0
  46. data/lib/go_api_client/parsers/scheduled_job_parser.rb +28 -0
  47. data/lib/go_api_client/parsers/stage_parser.rb +31 -0
  48. data/lib/go_api_client/parsers/user_parser.rb +12 -0
  49. data/lib/go_api_client/version.rb +4 -4
  50. data/lib/go_api_client.rb +56 -110
  51. data/test/go_api_client/artifact_test.rb +8 -8
  52. data/test/go_api_client/author_test.rb +27 -0
  53. data/test/go_api_client/building_test.rb +21 -19
  54. data/test/go_api_client/{atom/entry_test.rb → entry_test.rb} +8 -8
  55. data/test/go_api_client/job_test.rb +15 -14
  56. data/test/go_api_client/pipeline_test.rb +24 -27
  57. data/test/go_api_client/stage_test.rb +21 -74
  58. data/test/go_api_client/user_test.rb +15 -20
  59. metadata +108 -78
  60. data/.init.sh +0 -8
  61. data/.rbenv-gemsets +0 -1
  62. data/.ruby-version +0 -1
  63. data/.rvmrc +0 -1
  64. data/.yardopts +0 -6
  65. data/Gemfile.lock +0 -32
  66. data/README.textile +0 -64
  67. data/lib/go_api_client/artifact.rb +0 -27
  68. data/lib/go_api_client/atom/author.rb +0 -42
  69. data/lib/go_api_client/atom/entry.rb +0 -34
  70. data/lib/go_api_client/atom/feed.rb +0 -40
  71. data/lib/go_api_client/atom/feed_page.rb +0 -49
  72. data/lib/go_api_client/atom.rb +0 -4
  73. data/lib/go_api_client/commit.rb +0 -30
  74. data/lib/go_api_client/helpers/simple_attribute_support.rb +0 -11
  75. data/lib/go_api_client/helpers.rb +0 -1
  76. data/lib/go_api_client/job.rb +0 -68
  77. data/lib/go_api_client/pipeline.rb +0 -48
  78. data/lib/go_api_client/stage.rb +0 -57
  79. data/lib/go_api_client/user.rb +0 -36
  80. data/test/go_api_client/atom/author_test.rb +0 -27
  81. data/test/go_api_client/atom/feed_page_test.rb +0 -41
  82. data/test/go_api_client/atom/feed_test.rb +0 -39
  83. data/test/go_api_client/commit_test.rb +0 -38
  84. data/test/schedule_test.rb +0 -12
@@ -0,0 +1,29 @@
1
+ require 'time'
2
+
3
+ module GoApiClient
4
+ module Parsers
5
+ class Material
6
+ class << self
7
+
8
+ def parse(root)
9
+ url = root.attributes['url'].value if root.attributes['url']
10
+ branch = root.attributes['url'].value if root.attributes['branch']
11
+ pipeline_name = root.attributes['pipelineName'].value if root.attributes['pipelineName']
12
+ stage_name = root.attributes['stageName'].value if root.attributes['stageName']
13
+ GoApiClient::Domain::Material.new(
14
+ {
15
+ :uri => root.attributes['materialUri'].value,
16
+ :type => root.attributes['type'].value,
17
+ :url => url,
18
+ :branch => branch,
19
+ :pipeline_name => pipeline_name,
20
+ :stage_name => stage_name,
21
+ :parsed_changesets => root.xpath('./modifications/changeset').collect do |element|
22
+ GoApiClient::Parsers::Changeset.parse(element)
23
+ end
24
+ })
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,11 @@
1
+ module GoApiClient
2
+ module Parsers
3
+ class Helper
4
+ class << self
5
+ def href_from(xml)
6
+ xml.first.attribute('href').value unless xml.empty?
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,30 @@
1
+ require 'time'
2
+
3
+ module GoApiClient
4
+ module Parsers
5
+ class Pipeline < GoApiClient::Parsers::Helper
6
+ class << self
7
+ def parse(root)
8
+ GoApiClient::Domain::Pipeline.new(
9
+ {
10
+ :name => root.attributes['name'].value,
11
+ :label => root.attributes['label'].value,
12
+ :counter => root.attributes['counter'].value.to_i,
13
+ :self_uri => href_from(root.xpath("./link[@rel='self']")),
14
+ :inserted_after_uri => href_from(root.xpath("./link[@rel='insertedAfter']")),
15
+ :id => root.xpath('./id').first.content,
16
+ :schedule_time => Time.parse(root.xpath('./scheduleTime').first.content).utc,
17
+ :approved_by => root.xpath('./approvedBy').first.content,
18
+ :stages => root.xpath('./stages/stage').collect do |element|
19
+ element.attributes['href'].value
20
+ end,
21
+ :parsed_materials => root.xpath('./materials/material').collect do |element|
22
+ GoApiClient::Parsers::Material.parse(element)
23
+ end
24
+ })
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,26 @@
1
+ require 'time'
2
+
3
+ module GoApiClient
4
+ module Parsers
5
+ class Project < GoApiClient::Parsers::Helper
6
+ class << self
7
+ def parse(root)
8
+ messages = root.xpath('./messages/message').collect do |element|
9
+ {:text => element.attributes['text'].value, :kind => element.attributes['kind'].value}
10
+ end if root.xpath('./messages/message')
11
+ GoApiClient::Domain::Project.new(
12
+ {
13
+ :name => root.attributes['name'].value,
14
+ :activity => root.attributes['activity'].value,
15
+ :last_build_status => root.attributes['lastBuildStatus'].value,
16
+ :last_build_label => root.attributes['lastBuildLabel'].value,
17
+ :last_build_time => Time.parse(root.attributes['lastBuildTime'].value).utc,
18
+ :web_uri => root.attributes['webUrl'].value,
19
+ :parsed_messages => messages
20
+ })
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,28 @@
1
+ module GoApiClient
2
+ module Parsers
3
+ class ScheduledJob < GoApiClient::Parsers::Helper
4
+
5
+ class << self
6
+ def parse(root)
7
+ environment = root.xpath('./environment').first.content if root.xpath('./environment').first
8
+ resources = root.xpath('./resources/resource').collect do |element|
9
+ element.content
10
+ end if root.xpath('./resources/resource')
11
+ environment_variables = root.xpath('./environmentVariables/variable').collect do |element|
12
+ {:name => element.attributes['name'].value, :value => element.content}
13
+ end if root.xpath('./environmentVariables/variable')
14
+ GoApiClient::Domain::ScheduledJob.new(
15
+ {
16
+ :name => root.attributes['name'].value,
17
+ :id => root.attributes['id'].value.to_i,
18
+ :self_uri => href_from(root.xpath("./link[@rel='self']")),
19
+ :build_locator => root.xpath('./buildLocator').first.content,
20
+ :environment => environment,
21
+ :resources => resources,
22
+ :environment_variables => environment_variables
23
+ })
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,31 @@
1
+ require 'time'
2
+
3
+ module GoApiClient
4
+ module Parsers
5
+ class Stage < GoApiClient::Parsers::Helper
6
+ class << self
7
+ def parse(root)
8
+ GoApiClient::Domain::Stage.new(
9
+ {
10
+ :name => root.attributes['name'].value,
11
+ :counter => root.attributes['counter'].value.to_i,
12
+ :id => root.xpath('./id').first.content,
13
+ :self_uri => href_from(root.xpath("./link[@rel='self']")),
14
+ :result => root.xpath('./result').first.content,
15
+ :updated => Time.parse(root.xpath('./updated').first.content).utc,
16
+ :state => root.xpath('./state').first.content,
17
+ :approved_by => root.xpath('./approvedBy').first.content,
18
+ :jobs => root.xpath('./jobs/job').collect do |element|
19
+ element.attributes['href'].value
20
+ end,
21
+ :pipeline_name => root.xpath('./pipeline').first.attributes['name'].value,
22
+ :pipeline_counter => root.xpath('./pipeline').first.attributes['counter'].value,
23
+ :pipeline_label => root.xpath('./pipeline').first.attributes['label'].value,
24
+ :pipeline_uri => root.xpath('./pipeline').first.attributes['href'].value
25
+ })
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+
@@ -0,0 +1,12 @@
1
+ module GoApiClient
2
+ module Parsers
3
+ class User
4
+ class << self
5
+ def parse(root)
6
+ _, name, email = *root.content.match(/(.*) <(.+?)>/)
7
+ GoApiClient::Domain::User.new(name, email)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,9 +1,9 @@
1
1
  module GoApiClient
2
2
  module Version
3
- MAJOR = 0
4
- MINOR = 5
5
- PATCH = 4
3
+ MAJOR = 1
4
+ MINOR = 0
5
+ PATCH = 0
6
6
  RELEASE = ENV['GO_PIPELINE_COUNTER']
7
7
  VERSION = [MAJOR, MINOR, PATCH, RELEASE].compact.join('.')
8
8
  end
9
- end
9
+ end
data/lib/go_api_client.rb CHANGED
@@ -1,119 +1,65 @@
1
- require 'nokogiri'
2
-
3
- require 'net/http'
4
-
5
- require 'go_api_client/version'
6
- require 'go_api_client/helpers'
7
- require 'go_api_client/http_fetcher'
8
-
9
- require 'go_api_client/atom'
10
- require 'go_api_client/pipeline'
11
- require 'go_api_client/stage'
12
- require 'go_api_client/job'
13
- require 'go_api_client/artifact'
14
- require 'go_api_client/commit'
15
- require 'go_api_client/user'
16
1
  require 'go_api_client/logger'
17
- require 'go_api_client/engine' if defined?(::Rails)
2
+ require 'go_api_client/version'
18
3
 
19
4
  module GoApiClient
20
-
21
- # A wrapper that contains the last run information of scraping the go atom feed
22
- class LastRun
23
- # A list of pipelines
24
- # @return [Array<Pipeline>]
25
- # @see GoApiClient.runs
26
- attr_reader :pipelines
27
-
28
- # The most recent atom entry when the feed was last fetched
29
- attr_reader :latest_atom_entry_id
30
-
31
- def initialize(pipelines, latest_atom_entry_id)
32
- @pipelines = pipelines
33
- @latest_atom_entry_id = latest_atom_entry_id
34
- end
5
+ autoload :Client, 'go_api_client/client'
6
+ autoload :HttpFetcher, 'go_api_client/http_fetcher'
7
+ autoload :Engine, 'go_api_client/engine' if defined?(::Rails)
8
+ autoload :AttributeHelper, 'go_api_client/attribute_helper'
9
+
10
+ module Api
11
+ autoload :AbstractApi, 'go_api_client/api/abstract_api'
12
+ autoload :Cctray, 'go_api_client/api/cctray'
13
+ autoload :Config, 'go_api_client/api/config'
14
+ autoload :Pipeline, 'go_api_client/api/pipeline'
15
+ autoload :Properties, 'go_api_client/api/properties'
16
+ autoload :Feed, 'go_api_client/api/feed'
17
+ autoload :Job, 'go_api_client/api/job'
18
+ autoload :Stage, 'go_api_client/api/stage'
35
19
  end
36
20
 
37
- class << self
38
- # Connects to the a go server via the "Atom Feed API":http://www.thoughtworks-studios.com/docs/go/current/help/Feeds_API.html
39
- # and fetches entire the pipeline history for that pipeline. Since this this is a wrapper around an atom feed,
40
- # it is important to remember the last atom feed entry that was seen in order to prevent crawling the entire atom feed
41
- # over and over again and slow the process down.
42
- #
43
- # @return [LastRun] an object containing a list of all pipelines ordered by their counter along with the last stage that ran in the pipeline
44
- # @param [Hash] options the connection options
45
- # @option options [String] :host ("localhost") Host to connect to.
46
- # @option options [Ingeger] :port (8153) Port to connect to.
47
- # @option options [Boolean] :ssl (false) If connection should be made over ssl.
48
- # @option options [String] :username (nil) The username to be used if server or the pipeline requires authorization.
49
- # @option options [String] :password (nil) The password to be used if server or the pipeline requires authorization.
50
- # @option options [String] :pipeline_name The name of the pipeline that should be fetched.
51
- # @option options [String] :latest_atom_entry_id (nil) The id of the last atom feed entry
52
- def runs(options={})
53
- options = ({:ssl => false, :host => 'localhost', :port => 8153, :username => nil, :password => nil, :latest_atom_entry_id => nil}).merge(options)
54
-
55
- http_fetcher = GoApiClient::HttpFetcher.new(:username => options[:username], :password => options[:password])
56
-
57
- pipeline_name = options[:pipeline_name] || "defaultPipeline"
58
- feed_url = "#{options[:ssl] ? 'https' : 'http'}://#{options[:host]}:#{options[:port]}/go/api/pipelines/#{pipeline_name}/stages.xml"
59
- feed = GoApiClient::Atom::Feed.new(feed_url, options[:latest_atom_entry_id])
60
- feed.fetch!(http_fetcher)
61
- return construct_last_run(feed, http_fetcher, options[:latest_atom_entry_id])
62
- end
63
-
64
- def all_runs(options={})
65
- options = ({:ssl => false, :host => 'localhost', :port => 8153, :username => nil, :password => nil}).merge(options)
66
- http_fetcher = GoApiClient::HttpFetcher.new(:username => options[:username], :password => options[:password])
67
- feed_url = "#{options[:ssl] ? 'https' : 'http'}://#{options[:host]}:#{options[:port]}/go/api/pipelines.xml"
68
- feed = GoApiClient::Atom::Feed.new(feed_url, nil)
69
- feed = feed.fetch_all!(http_fetcher)
70
- feed.inject({}) do |memo, (href, entries)|
71
- memo[href] = construct_last_run(entries, http_fetcher, nil)
72
- memo
73
- end
74
- end
75
-
76
- # Answers if a build is in progress. For the list of supported connection options see {GoApiClient.runs #runs}
77
- # @see .build_finished?
78
- def build_in_progress?(options={})
79
- raise ArgumentError("Hostname is mandatory") unless options[:host]
80
- options = ({:ssl => false, :port => 8153, :username => nil, :password => nil, :pipeline_name => 'defaultPipeline'}).merge(options)
81
- http_fetcher = GoApiClient::HttpFetcher.new(:username => options[:username], :password => options[:password])
82
- url = "#{options[:ssl] ? 'https' : 'http'}://#{options[:host]}:#{options[:port]}/go/cctray.xml"
83
- doc = Nokogiri::XML(http_fetcher.get!(url))
84
- doc.css("Project[activity='Building'][name^='#{options[:pipeline_name]} ::']").count > 0
85
- end
86
-
87
- # Answers if a build is in completed. For the list of supported connection options see {GoApiClient.runs #runs}
88
- # @see .build_in_progress?
89
- def build_finished?(options)
90
- !build_in_progress?(options)
91
- end
92
-
93
- # Schedule a particular pipeline with the latest available materials.
94
- def schedule_pipeline(options)
95
- raise ArgumentError("Hostname is mandatory") unless options[:host]
96
- options = ({:ssl => false, :port => 8153, :username => nil, :password => nil, :pipeline_name => 'defaultPipeline'}).merge(options)
97
-
98
- uri = "#{options[:ssl] ? 'https' : 'http'}://#{options[:host]}:#{options[:port]}/go/api/pipelines/#{options[:pipeline_name]}/schedule"
99
- GoApiClient::HttpFetcher.new.post!(uri)
21
+ module Domain
22
+ autoload :Author, 'go_api_client/domain/author'
23
+ autoload :Artifact, 'go_api_client/domain/artifact'
24
+ autoload :Changeset, 'go_api_client/domain/changeset'
25
+ autoload :Entry, 'go_api_client/domain/entry'
26
+ autoload :Feed, 'go_api_client/domain/feed'
27
+ autoload :InternalCache, 'go_api_client/domain/internal_cache'
28
+ autoload :Job, 'go_api_client/domain/job'
29
+ autoload :ScheduledJob, 'go_api_client/domain/scheduled_job'
30
+ autoload :Pipeline, 'go_api_client/domain/pipeline'
31
+ autoload :Stage, 'go_api_client/domain/stage'
32
+ autoload :Material, 'go_api_client/domain/material'
33
+ autoload :Project, 'go_api_client/domain/project'
34
+ autoload :User, 'go_api_client/domain/user'
35
+
36
+ module Config
37
+ autoload :Pipeline, 'go_api_client/domain/config/pipeline'
38
+ autoload :Stage, 'go_api_client/domain/config/stage'
39
+ autoload :Job, 'go_api_client/domain/config/job'
100
40
  end
41
+ end
101
42
 
102
- private
103
-
104
- def construct_last_run(feed, http_fetcher, last_atom_entry_id)
105
- pipelines = {}
106
- stages = feed.entries.collect do |entry|
107
- Stage.from(entry.stage_href, :authors => entry.authors, :pipeline_cache => pipelines, :http_fetcher => http_fetcher)
108
- end
109
-
110
- pipelines.values.each do |p|
111
- p.stages = p.stages.sort_by {|s| s.completed_at }
112
- end
113
-
114
- pipelines = pipelines.values.sort_by {|p| p.counter}
115
- latest_atom_entry_id = stages.empty? ? last_atom_entry_id : feed.entries.first.id
116
- return LastRun.new(pipelines, latest_atom_entry_id)
43
+ module Parsers
44
+ autoload :Author, 'go_api_client/parsers/author_parser'
45
+ autoload :Artifact, 'go_api_client/parsers/artifact_parser'
46
+ autoload :Changeset, 'go_api_client/parsers/changeset'
47
+ autoload :Material, 'go_api_client/parsers/material_parser'
48
+ autoload :Job, 'go_api_client/parsers/job_parser'
49
+ autoload :ScheduledJob, 'go_api_client/parsers/scheduled_job_parser'
50
+ autoload :Helper, 'go_api_client/parsers/parser_helper'
51
+ autoload :Pipeline, 'go_api_client/parsers/pipeline_parser'
52
+ autoload :Stage, 'go_api_client/parsers/stage_parser'
53
+ autoload :Author, 'go_api_client/parsers/author_parser'
54
+ autoload :Entry, 'go_api_client/parsers/entry_parser'
55
+ autoload :Feed, 'go_api_client/parsers/feed_parser'
56
+ autoload :Project, 'go_api_client/parsers/project_parser'
57
+ autoload :User, 'go_api_client/parsers/user_parser'
58
+
59
+ module Config
60
+ autoload :Pipeline, 'go_api_client/parsers/config/pipeline_parser'
61
+ autoload :Stage, 'go_api_client/parsers/config/stage_parser'
62
+ autoload :Job, 'go_api_client/parsers/config/job_parser'
117
63
  end
118
64
  end
119
- end
65
+ end
@@ -1,15 +1,15 @@
1
- require "test_helper"
1
+ require 'test_helper'
2
2
 
3
3
  module GoApiClient
4
4
  class ArtifactTest < Test::Unit::TestCase
5
- test "should construct the artifacts from the job xml" do
6
- stub_request(:get, "http://localhost:8153/go/api/jobs/3.xml").to_return(:body => file_contents("jobs_3.xml"))
5
+ test 'should construct the artifacts from the job xml' do
6
+ link = 'http://localhost:8153/go/api/jobs/3.xml'
7
+ stub_request(:get, link).to_return(:body => file_contents('jobs_3.xml'))
7
8
 
8
- link = "http://localhost:8153/go/api/jobs/3.xml"
9
- job = GoApiClient::Job.from(link)
10
- assert_equal 2, job.artifacts.count
11
- assert_equal "https://ci.snap-ci.com/go/files/Go-SaaS-Rails/898/Dist/1/rpm/tmp.zip", job.artifacts.first.as_zip_file_url
12
- assert_equal "https://ci.snap-ci.com/go/files/Go-SaaS-Rails/898/Dist/1/rpm/log.zip", job.artifacts.last.as_zip_file_url
9
+ job = GoApiClient::Client.new.api(:job).job({:job_uri => link})
10
+ assert_equal 2, job.parsed_artifacts.count
11
+ assert_equal 'https://ci.snap-ci.com/go/files/Go-SaaS-Rails/898/Dist/1/rpm/tmp.zip', job.parsed_artifacts.first.as_zip_file_url
12
+ assert_equal 'https://ci.snap-ci.com/go/files/Go-SaaS-Rails/898/Dist/1/rpm/log.zip', job.parsed_artifacts.last.as_zip_file_url
13
13
  end
14
14
  end
15
15
  end
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ module GoApiClient
4
+ module Atom
5
+ class AuthorTest < Test::Unit::TestCase
6
+
7
+ test 'should be able to parse author:s info' do
8
+ doc = Nokogiri::XML('<author xmlns="http://www.w3.org/2005/Atom"><name><![CDATA[oogabooga <twgosaas@gmail.com>]]></name><uri>http://oogabooga.example.com<uri></author>')
9
+ author = GoApiClient::Parsers::Author.parse(doc.root)
10
+ assert_equal GoApiClient::Domain::Author.new({:name => 'oogabooga', :email => 'twgosaas@gmail.com', :uri => 'http://oogabooga.example.com'}), author
11
+ end
12
+
13
+ test 'should be able to parse author xml with no email and uri' do
14
+ doc = Nokogiri::XML('<author xmlns="http://www.w3.org/2005/Atom"><name><![CDATA[oogabooga]]></name></author>')
15
+ author = GoApiClient::Parsers::Author.parse(doc.root)
16
+ assert_equal GoApiClient::Domain::Author.new({:name => 'oogabooga'}), author
17
+ end
18
+
19
+ test 'should be able to parse author xml with email specified in the name tag' do
20
+ doc = Nokogiri::XML('<author xmlns="http://www.w3.org/2005/Atom"><name><![CDATA[oogabooga <twgosaas@gmail.com>]]></name></author>')
21
+ author = GoApiClient::Parsers::Author.parse(doc.root)
22
+ assert_equal GoApiClient::Domain::Author.new({:name => 'oogabooga', :email => 'twgosaas@gmail.com'}), author
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -1,10 +1,10 @@
1
- require "test_helper"
1
+ require 'test_helper'
2
2
 
3
3
  module GoApiClient
4
4
  class BuildingTest < Test::Unit::TestCase
5
5
 
6
- test "should report that Go is building if atleast 1 stage in specified pipeline is building" do
7
- feed = %Q{
6
+ test 'should report that Go is building if atleast 1 stage in specified pipeline is building' do
7
+ feed = '
8
8
  <?xml version="1.0" encoding="utf-8"?>
9
9
  <Projects>
10
10
  <Project name="defaultPipeline :: RailsTests" activity="Building" lastBuildStatus="Success" lastBuildLabel="4" lastBuildTime="2012-07-19T10:03:04" webUrl="http://go-server.2.project:8153/go/pipelines/defaultPipeline/5/RailsTests/1" />
@@ -13,15 +13,16 @@ module GoApiClient
13
13
  <Project name="anotherPipeline :: RailsTests" activity="Sleeping" lastBuildStatus="Success" lastBuildLabel="4" lastBuildTime="2012-07-19T10:03:04" webUrl="http://go-server.2.project:8153/go/pipelines/defaultPipeline/5/RailsTests/1" />
14
14
  <Project name="anotherPipeline :: SmokeTests" activity="Sleeping" lastBuildStatus="Success" lastBuildLabel="4" lastBuildTime="2012-07-19T10:03:04" webUrl="http://go-server.2.project:8153/go/pipelines/defaultPipeline/5/RailsTests/1" />
15
15
  </Projects>
16
- }
17
- stub_request(:get, "http://go-server.2.project:8153/go/cctray.xml").
18
- to_return(:body => feed)
19
- assert GoApiClient.build_in_progress?(:host => 'go-server.2.project', :pipeline_name => 'defaultPipeline')
20
- assert_false GoApiClient.build_in_progress?(:host => 'go-server.2.project', :pipeline_name => 'anotherPipeline')
16
+ '
17
+ stub_request(:get, 'http://go-server.2.project:8153/go/cctray.xml').to_return(:body => feed)
18
+
19
+ cctray_api = GoApiClient::Client.new({:host => 'go-server.2.project'}).api(:cctray)
20
+ assert_false cctray_api.projects({:pipeline_name => 'defaultPipeline', :activity => 'Building'}).empty?
21
+ assert cctray_api.projects({:pipeline_name => 'anotherPipeline', :activity => 'Building'}).empty?
21
22
  end
22
23
 
23
- test "should report that Go is sleeping if all stages in specified pipeline are sleeping" do
24
- feed = %Q{
24
+ test 'should report that Go is sleeping if all stages in specified pipeline are sleeping' do
25
+ feed = '
25
26
  <?xml version="1.0" encoding="utf-8"?>
26
27
  <Projects>
27
28
  <Project name="defaultPipeline :: RailsTests" activity="Sleeping" lastBuildStatus="Success" lastBuildLabel="4" lastBuildTime="2012-07-19T10:03:04" webUrl="http://go-server.2.project:8153/go/pipelines/defaultPipeline/5/RailsTests/1" />
@@ -30,17 +31,18 @@ module GoApiClient
30
31
  <Project name="anotherPipeline :: RailsTests" activity="Building" lastBuildStatus="Success" lastBuildLabel="4" lastBuildTime="2012-07-19T10:03:04" webUrl="http://go-server.2.project:8153/go/pipelines/defaultPipeline/5/RailsTests/1" />
31
32
  <Project name="anotherPipeline :: SmokeTests" activity="Sleeping" lastBuildStatus="Success" lastBuildLabel="4" lastBuildTime="2012-07-19T10:03:04" webUrl="http://go-server.2.project:8153/go/pipelines/defaultPipeline/5/RailsTests/1" />
32
33
  </Projects>
33
- }
34
- stub_request(:get, "http://go-server.2.project:8153/go/cctray.xml").
35
- to_return(:body => feed)
36
- assert GoApiClient.build_finished?(:host => 'go-server.2.project', :pipeline_name => 'defaultPipeline')
37
- assert_false GoApiClient.build_finished?(:host => 'go-server.2.project', :pipeline_name => 'anotherPipeline')
34
+ '
35
+ stub_request(:get, 'http://go-server.2.project:8153/go/cctray.xml').to_return(:body => feed)
36
+
37
+ cctray_api = GoApiClient::Client.new({:host => 'go-server.2.project'}).api(:cctray)
38
+ assert_false cctray_api.projects({:pipeline_name => 'anotherPipeline', :activity => 'Building'}).empty?
39
+ assert cctray_api.projects({:pipeline_name => 'defaultPipeline', :activity => 'Building'}).empty?
38
40
  end
39
41
 
40
- test "should handle empty feeds" do
41
- stub_request(:get, "http://go-server.2.project:8153/go/cctray.xml").
42
- to_return(:body => nil)
43
- assert_false GoApiClient.build_in_progress?(:host => 'go-server.2.project')
42
+ test 'should handle empty feeds' do
43
+ stub_request(:get, 'http://go-server.2.project:8153/go/cctray.xml').to_return(:body => nil)
44
+ cctray_api = GoApiClient::Client.new({:host => 'go-server.2.project'}).api(:cctray)
45
+ assert cctray_api.projects({:pipeline_name => 'defaultPipeline', :activity => 'Building'}).empty?
44
46
  end
45
47
 
46
48
  end