go_api_client 0.0.8 → 0.3.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 (78) hide show
  1. data/.gitignore +7 -39
  2. data/.rvmrc +1 -0
  3. data/Gemfile.lock +12 -2
  4. data/Rakefile +8 -9
  5. data/go_api_client.gemspec +5 -2
  6. data/lib/go_api_client/atom/author.rb +25 -1
  7. data/lib/go_api_client/atom/entry.rb +9 -3
  8. data/lib/go_api_client/atom/feed.rb +19 -14
  9. data/lib/go_api_client/atom/feed_page.rb +49 -0
  10. data/lib/go_api_client/atom.rb +1 -0
  11. data/lib/go_api_client/commit.rb +30 -0
  12. data/lib/go_api_client/helpers/simple_attribute_support.rb +11 -0
  13. data/lib/go_api_client/helpers.rb +1 -0
  14. data/lib/go_api_client/http_fetcher.rb +41 -0
  15. data/lib/go_api_client/job.rb +56 -10
  16. data/lib/go_api_client/pipeline.rb +36 -12
  17. data/lib/go_api_client/stage.rb +43 -14
  18. data/lib/go_api_client/user.rb +36 -0
  19. data/lib/go_api_client/version.rb +7 -1
  20. data/lib/go_api_client.rb +45 -12
  21. data/test/fixtures/building/job_1.xml +41 -0
  22. data/test/fixtures/building/job_2.xml +43 -0
  23. data/test/fixtures/building/job_3.xml +40 -0
  24. data/test/fixtures/building/job_4.xml +40 -0
  25. data/test/fixtures/building/pipeline_1.xml +45 -0
  26. data/test/fixtures/building/pipeline_2.xml +39 -0
  27. data/test/fixtures/building/pipeline_3.xml +71 -0
  28. data/test/fixtures/building/stages.xml +180 -0
  29. data/test/fixtures/building/stages_1.xml +16 -0
  30. data/test/fixtures/building/stages_2.xml +16 -0
  31. data/test/fixtures/building/stages_3.xml +16 -0
  32. data/test/fixtures/building/stages_4.xml +16 -0
  33. data/test/fixtures/jobs_1.xml +3 -3
  34. data/test/fixtures/jobs_with_no_properties.xml +42 -0
  35. data/test/fixtures/ordering/go/api/jobs/1.xml +29 -0
  36. data/test/fixtures/ordering/go/api/jobs/10.xml +31 -0
  37. data/test/fixtures/ordering/go/api/jobs/2.xml +29 -0
  38. data/test/fixtures/ordering/go/api/jobs/3.xml +29 -0
  39. data/test/fixtures/ordering/go/api/jobs/4.xml +29 -0
  40. data/test/fixtures/ordering/go/api/jobs/5.xml +29 -0
  41. data/test/fixtures/ordering/go/api/jobs/6.xml +29 -0
  42. data/test/fixtures/ordering/go/api/jobs/7.xml +31 -0
  43. data/test/fixtures/ordering/go/api/jobs/8.xml +31 -0
  44. data/test/fixtures/ordering/go/api/jobs/9.xml +31 -0
  45. data/test/fixtures/ordering/go/api/pipelines/defaultPipeline/1.xml +31 -0
  46. data/test/fixtures/ordering/go/api/pipelines/defaultPipeline/2.xml +26 -0
  47. data/test/fixtures/ordering/go/api/pipelines/defaultPipeline/3.xml +26 -0
  48. data/test/fixtures/ordering/go/api/pipelines/defaultPipeline/4.xml +27 -0
  49. data/test/fixtures/ordering/go/api/pipelines/defaultPipeline/5.xml +33 -0
  50. data/test/fixtures/ordering/go/api/pipelines/defaultPipeline/stages.xml +255 -0
  51. data/test/fixtures/ordering/go/api/stages/1.xml +14 -0
  52. data/test/fixtures/ordering/go/api/stages/10.xml +14 -0
  53. data/test/fixtures/ordering/go/api/stages/2.xml +14 -0
  54. data/test/fixtures/ordering/go/api/stages/3.xml +14 -0
  55. data/test/fixtures/ordering/go/api/stages/4.xml +14 -0
  56. data/test/fixtures/ordering/go/api/stages/5.xml +14 -0
  57. data/test/fixtures/ordering/go/api/stages/6.xml +14 -0
  58. data/test/fixtures/ordering/go/api/stages/7.xml +14 -0
  59. data/test/fixtures/ordering/go/api/stages/8.xml +14 -0
  60. data/test/fixtures/ordering/go/api/stages/9.xml +14 -0
  61. data/test/fixtures/pagination/stages.xml +636 -0
  62. data/test/fixtures/pagination/stages_before_7916973.xml +615 -0
  63. data/test/fixtures/pagination/stages_before_7959831.xml +615 -0
  64. data/test/fixtures/pipelines_1.xml +8 -1
  65. data/test/fixtures/stages.xml +1 -1
  66. data/test/go_api_client/atom/author_test.rb +27 -0
  67. data/test/go_api_client/atom/entry_test.rb +27 -0
  68. data/test/go_api_client/atom/feed_page_test.rb +41 -0
  69. data/test/go_api_client/atom/feed_test.rb +25 -0
  70. data/test/go_api_client/building_test.rb +38 -0
  71. data/test/go_api_client/commit_test.rb +38 -0
  72. data/test/go_api_client/job_test.rb +42 -0
  73. data/test/go_api_client/pipeline_test.rb +63 -16
  74. data/test/go_api_client/stage_test.rb +48 -14
  75. data/test/go_api_client/user_test.rb +27 -0
  76. data/test/test_helper.rb +19 -3
  77. metadata +173 -10
  78. data/bin/go_api_client +0 -3
@@ -1,6 +1,6 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
 
3
- <pipeline name="defaultPipeline" counter="1" label="1">
3
+ <pipeline name="defaultPipeline" counter="99" label="1">
4
4
  <link rel="self" href="http://localhost:8153/go/api/pipelines/defaultPipeline/1.xml"/>
5
5
  <id><![CDATA[urn:x-go.studios.thoughtworks.com:job-id:defaultPipeline:1]]></id>
6
6
  <scheduleTime>2012-02-23T17:16:15+05:30</scheduleTime>
@@ -14,6 +14,13 @@
14
14
  <message><![CDATA[Update README]]></message>
15
15
  <file name="README" action="modified"/>
16
16
  </changeset>
17
+ <changeset changesetUri="http://localhost:8153/go/api/materials/1/changeset/ded20c6210172daee9c100364679e65bded20c6210172daee9c10036467.xml">
18
+ <user><![CDATA[Ketan Padegaonkar <KetanPadegaonkar@gmail.com>]]></user>
19
+ <checkinTime>2012-02-23T15:42:10+05:30</checkinTime>
20
+ <revision><![CDATA[ded20c6210172daee9c100364679e65bded20c6210172daee9c10036467]]></revision>
21
+ <message><![CDATA[Fixed build]]></message>
22
+ <file name="Rakefile" action="modified"/>
23
+ </changeset>
17
24
  </modifications>
18
25
  </material>
19
26
  </materials>
@@ -8,7 +8,7 @@
8
8
  <link rel="self" href="http://localhost:8153/go/api/pipelines/defaultPipeline/stages.xml"/>
9
9
 
10
10
 
11
- <link rel="next" href="http://localhost:8153/go/api/pipelines/defaultPipeline/stages.xml?before=6"/>
11
+ <!-- <link rel="next" href="http://localhost:8153/go/api/pipelines/defaultPipeline/stages.xml?before=6"/> -->
12
12
 
13
13
 
14
14
 
@@ -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(%Q{<author xmlns="http://www.w3.org/2005/Atom"><name><![CDATA[oogabooga <twgosaas@gmail.com>]]></name><uri>http://oogabooga.example.com<uri></author>})
9
+ author = Author.new(doc.root).parse!
10
+ assert_equal Author.new(nil, :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(%Q{<author xmlns="http://www.w3.org/2005/Atom"><name><![CDATA[oogabooga]]></name></author>})
15
+ author = Author.new(doc.root).parse!
16
+ assert_equal Author.new(nil, :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(%Q{<author xmlns="http://www.w3.org/2005/Atom"><name><![CDATA[oogabooga <twgosaas@gmail.com>]]></name></author>})
21
+ author = Author.new(doc.root).parse!
22
+ assert_equal Author.new(nil, :name => 'oogabooga', :email => 'twgosaas@gmail.com'), author
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ require "test_helper"
2
+
3
+ module GoApiClient
4
+ module Atom
5
+ class EntryTest < Test::Unit::TestCase
6
+ setup do
7
+ doc = Nokogiri::XML(file_contents('pagination/stages.xml'))
8
+ @root = doc.root
9
+ @entry_node = @root.xpath('./xmlns:entry')[12]
10
+ end
11
+
12
+ test "should parse entry node" do
13
+ entry = Entry.new(@entry_node).parse!
14
+ assert_equal 'https://go-server.example.com/go/pipelines/tlb/177/ant_count_go/1', entry.id
15
+ assert_equal Time.parse('2012-01-22 11:32:57 UTC'), entry.updated_at
16
+ assert_equal 'tlb(177) stage ant_count_go(1) Passed', entry.title
17
+ assert_equal 'https://go-server.example.com/go/api/stages/210161.xml', entry.stage_href
18
+ expected_authors = [
19
+ Author.new(nil, :name => 'Pavan', :email => 'itspanzi@gmail.com'),
20
+ Author.new(nil, :name => 'Pavan Sudarshan', :email => 'itspanzi@gmail.com')
21
+ ]
22
+
23
+ assert_equal expected_authors, entry.authors
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,41 @@
1
+ require "test_helper"
2
+
3
+ module GoApiClient
4
+ module Atom
5
+ class FeedPageTest < Test::Unit::TestCase
6
+
7
+ setup do
8
+ doc = Nokogiri::XML(file_contents("pagination/stages.xml"))
9
+ @feed_page = FeedPage.new(doc.root).parse!
10
+ end
11
+
12
+ test "should be able to parse one page of the paginated Go atom feed" do
13
+ assert_equal 25, @feed_page.entries.count
14
+ assert_equal 'https://go-server.example.com/go/api/pipelines/tlb/stages.xml', @feed_page.url
15
+ assert_equal 'https://go-server.example.com/go/api/pipelines/tlb/stages.xml?before=7959831', @feed_page.next_page
16
+ assert_equal Time.parse('2012-04-17 10:56:53 UTC'), @feed_page.updated_at
17
+ end
18
+
19
+ test "should answer if an entry id is present in the feed page" do
20
+ assert @feed_page.contains_entry?(@feed_page.entries[5].id)
21
+ assert_false @feed_page.contains_entry?("foo")
22
+ end
23
+
24
+ test "should answer if an entry object is present in the feed page" do
25
+ assert @feed_page.contains_entry?(@feed_page.entries[5])
26
+ assert_false @feed_page.contains_entry?(Entry.new(nil))
27
+ end
28
+
29
+ test "should return entries after a particular entry (top entries in feed)" do
30
+ entry = @feed_page.entries[5]
31
+
32
+ assert_equal @feed_page.entries_after(entry.id), @feed_page.entries_after(entry)
33
+
34
+ assert_equal 5, @feed_page.entries_after(entry.id).count
35
+ assert_equal 5, @feed_page.entries_after(entry).count
36
+
37
+ assert_false @feed_page.entries_after(entry).include?(entry)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,25 @@
1
+ require "test_helper"
2
+
3
+ module GoApiClient
4
+ module Atom
5
+ class FeedTest < Test::Unit::TestCase
6
+ setup do
7
+ stub_request(:get, "https://go-server.example.com/go/api/pipelines/tlb/stages.xml").to_return(:body => file_contents("pagination/stages.xml"))
8
+ stub_request(:get, "https://go-server.example.com/go/api/pipelines/tlb/stages.xml?before=7959831").to_return(:body => file_contents("pagination/stages_before_7959831.xml"))
9
+ end
10
+
11
+ test "should stop at last seen atom entry id" do
12
+ feed = GoApiClient::Atom::Feed.new('https://go-server.example.com/go/api/pipelines/tlb/stages.xml', 'https://go-server.example.com/go/pipelines/tlb/175/ant_count_tlb/1').fetch!
13
+ assert_equal (25+4), feed.entries.count
14
+ end
15
+
16
+ test "should stop at first page if entry id not specified" do
17
+ stub_request(:get, "https://go-server.example.com/go/api/pipelines/tlb/stages.xml?before=7916973").to_return(:body => file_contents("pagination/stages_before_7916973.xml"))
18
+
19
+ feed = GoApiClient::Atom::Feed.new('https://go-server.example.com/go/api/pipelines/tlb/stages.xml').fetch!
20
+ assert_equal 25*3, feed.entries.count
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,38 @@
1
+ require "test_helper"
2
+
3
+ module GoApiClient
4
+ class BuildingTest < Test::Unit::TestCase
5
+
6
+ test "should report that Go is building if atleast 1 project is building" do
7
+ feed = %Q{
8
+ <?xml version="1.0" encoding="utf-8"?>
9
+ <Projects>
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" />
11
+ <Project name="defaultPipeline :: RailsTests :: Test" activity="Sleeping" lastBuildStatus="Success" lastBuildLabel="4" lastBuildTime="2012-07-19T10:03:04" webUrl="http://go-server.2.project:8153/go/tab/build/detail/defaultPipeline/5/RailsTests/1/Test" />
12
+ </Projects>
13
+ }
14
+ stub_request(:get, "http://go-server.2.project:8153/go/cctray.xml").
15
+ to_return(:body => feed)
16
+ assert GoApiClient.build_in_progress?(:host => 'go-server.2.project')
17
+ end
18
+
19
+ test "should report that Go is sleeping if all projects are sleeping" do
20
+ feed = %Q{
21
+ <?xml version="1.0" encoding="utf-8"?>
22
+ <Projects>
23
+ <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" />
24
+ <Project name="defaultPipeline :: RailsTests :: Test" activity="Sleeping" lastBuildStatus="Success" lastBuildLabel="4" lastBuildTime="2012-07-19T10:03:04" webUrl="http://go-server.2.project:8153/go/tab/build/detail/defaultPipeline/5/RailsTests/1/Test" />
25
+ </Projects>
26
+ }
27
+ stub_request(:get, "http://go-server.2.project:8153/go/cctray.xml").
28
+ to_return(:body => feed)
29
+ assert_false GoApiClient.build_in_progress?(:host => 'go-server.2.project')
30
+ end
31
+
32
+ test "should handle empty feeds" do
33
+ stub_request(:get, "http://go-server.2.project:8153/go/cctray.xml").
34
+ to_return(:body => nil)
35
+ assert_false GoApiClient.build_in_progress?(:host => 'go-server.2.project')
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ require "test_helper"
2
+
3
+ module GoApiClient
4
+ class CommitTest < Test::Unit::TestCase
5
+
6
+ test "should parse a changeset xml node" do
7
+ doc = Nokogiri::XML.parse %q{<changeset changesetUri="http://localhost:8153/go/api/materials/1/changeset/9f77888d7a594699894a17f4d61fc9dfac3cfb74.xml">
8
+ <bar>
9
+ <revision>jhgasdfjkhgads</revision>
10
+ <message>some message</message>
11
+ <checkinTime>unparsable cruft</checkinTime>
12
+ <user>unparsable cruft</user>
13
+ </bar>
14
+
15
+ <user><![CDATA[oogabooga <twgosaas@gmail.com>]]></user>
16
+ <checkinTime>2012-02-21T15:41:30+05:30</checkinTime>
17
+ <revision><![CDATA[9f77888d7a594699894a17f4d61fc9dfac3cfb74]]></revision>
18
+ <message><![CDATA[Update README]]></message>
19
+ <file name="README" action="modified"/>
20
+ <foo>
21
+ <revision>jhgasdfjkhgads</revision>
22
+ <message>some message</message>
23
+ <checkinTime>unparsable cruft</checkinTime>
24
+ <user>unparsable cruft</user>
25
+ </foo>
26
+ </changeset>
27
+ }
28
+
29
+ commit = Commit.new(doc.root).parse!
30
+
31
+ assert_equal '9f77888d7a594699894a17f4d61fc9dfac3cfb74', commit.revision
32
+ assert_equal 'Update README', commit.message
33
+ assert_equal Time.parse("2012-02-21 10:11:30 UTC"), commit.time
34
+ assert_equal User.parse("oogabooga <twgosaas@gmail.com>"), commit.user
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,42 @@
1
+ require "test_helper"
2
+
3
+ module GoApiClient
4
+ class JobTest < Test::Unit::TestCase
5
+ test "should fetch the job xml and populate itself" do
6
+ stub_request(:get, "http://localhost:8153/go/api/jobs/1.xml").to_return(:body => file_contents("jobs_1.xml"))
7
+
8
+ link = "http://localhost:8153/go/api/jobs/1.xml"
9
+ job = GoApiClient::Job.from(link)
10
+
11
+ assert_equal 'http://localhost:8153/go/api/jobs/1.xml', job.url
12
+ assert_equal 'http://localhost:8153/go/files/defaultPipeline/1/Units/1/Test', job.artifacts_uri
13
+ assert_equal 'http://localhost:8153/go/files/defaultPipeline/1/Units/1/Test/cruise-output/console.log', job.console_log_url
14
+
15
+
16
+ assert_equal 'urn:x-go.studios.thoughtworks.com:job-id:defaultPipeline:1:Units:1:Test', job.identifier
17
+
18
+ assert_equal 900, job.duration
19
+ assert_equal "Test", job.name
20
+ assert_equal "Failed", job.result
21
+ assert_equal Time.parse('2012-02-23 11:46:15 UTC'), job.scheduled
22
+ assert_equal Time.parse('2012-02-23 11:46:27 UTC'), job.assigned
23
+ assert_equal Time.parse('2012-02-23 11:46:37 UTC'), job.preparing
24
+ assert_equal Time.parse('2012-02-23 11:46:41 UTC'), job.building
25
+ assert_equal Time.parse('2012-02-23 11:46:42 UTC'), job.completing
26
+ assert_equal Time.parse('2012-02-23 11:46:45 UTC'), job.completed
27
+ end
28
+
29
+ test "should parse job even when some properties are missing" do
30
+ stub_request(:get, "http://go-server.1.project:8153/go/api/jobs/1.xml").to_return(:body => file_contents("jobs_with_no_properties.xml"))
31
+ link = "http://go-server.1.project:8153/go/api/jobs/1.xml"
32
+ job = GoApiClient::Job.from(link)
33
+
34
+ assert_equal 80, job.duration
35
+ assert_equal "Failed", job.result
36
+ %w(scheduled assigned preparing building completing completed).each do |property|
37
+ assert_nil job.send(property)
38
+ end
39
+ end
40
+
41
+ end
42
+ end
@@ -7,30 +7,77 @@ module GoApiClient
7
7
  stub_request(:get, "http://localhost:8153/go/api/pipelines/defaultPipeline/1.xml").to_return(:body => file_contents("pipelines_1.xml"))
8
8
  end
9
9
 
10
- def test_fetch_populates_necessary_fields
10
+ test "should fetch the pipeline xml and populate itself" do
11
11
  link = "http://localhost:8153/go/api/pipelines/defaultPipeline/1.xml"
12
- pipeline = GoApiClient::Pipeline.new(link)
13
- pipeline.fetch
12
+ pipeline = GoApiClient::Pipeline.from(link)
14
13
 
15
14
  assert_equal "1", pipeline.label
16
- assert_equal ["Update README"], pipeline.commit_messages
15
+ assert_equal 99, pipeline.counter
16
+ assert_equal "defaultPipeline", pipeline.name
17
+ assert_equal "http://localhost:8153/go/api/pipelines/defaultPipeline/1.xml", pipeline.url
18
+ assert_equal ["Update README", "Fixed build"], pipeline.commits.collect(&:message)
19
+ assert_equal "urn:x-go.studios.thoughtworks.com:job-id:defaultPipeline:1", pipeline.identifier
20
+ assert_equal Time.parse('2012-02-23 11:46:15 UTC'), pipeline.schedule_time
17
21
  end
18
22
 
19
- def test_should_return_string_delimited_list_of_authors
23
+ test "should return a list of authors from the first stage" do
20
24
  link = "http://localhost:8153/go/api/pipelines/defaultPipeline/1.xml"
21
- pipeline = GoApiClient::Pipeline.new(link).fetch
22
- author_foo = Atom::Author.new(nil)
23
- author_foo.name = 'foo'
24
- author_foo.email = 'foo@example.com'
25
- author_foo.uri = 'http://foo.example.com'
26
-
27
- author_bar = Atom::Author.new(nil)
28
- author_bar.name = 'bar'
29
- author_bar.email = 'bar@example.com'
30
- author_bar.uri = 'http://bar.example.com'
25
+ pipeline = GoApiClient::Pipeline.from(link)
26
+ author_foo = Atom::Author.new(nil, :name => 'foo', :email => 'foo@example.com', :uri => 'http://foo.example.com')
27
+ author_bar = Atom::Author.new(nil, :name => 'bar', :email => 'bar@example.com', :uri => 'http://bar.example.com')
31
28
 
32
29
  pipeline.stages << OpenStruct.new(:authors => [author_foo, author_bar])
33
- assert_equal 'foo, bar', pipeline.authors
30
+ assert_equal [author_foo, author_bar], pipeline.authors
31
+ end
32
+
33
+ test "should only parse materials with type=GitMaterial" do
34
+ doc = Nokogiri::XML.parse %q{<?xml version="1.0" encoding="UTF-8"?>
35
+
36
+ <pipeline name="GreenInstallers" counter="286" label="286">
37
+ <link rel="self" href="https://go.example.com/go/api/pipelines/GreenInstallers/122316.xml"/>
38
+ <id><![CDATA[urn:x-go.studios.thoughtworks.com:job-id:GreenInstallers:286]]></id>
39
+ <link rel="insertedBefore" href="https://go.example.com/go/api/pipelines/GreenInstallers/122309.xml"/>
40
+ <link rel="insertedAfter" href="https://go.example.com/go/api/pipelines/GreenInstallers/122286.xml"/>
41
+ <scheduleTime>2013-02-08T20:34:12-08:00</scheduleTime>
42
+ <materials>
43
+ <material materialUri="https://go.example.com/go/api/materials/5185.xml" type="GitMaterial" url="git@github.com:test-repo.git" branch="master">
44
+ <modifications>
45
+ <changeset changesetUri="https://go.example.com/go/api/materials/5185/changeset/bc9cc9401b816d753f267227934e535affcb4028.xml">
46
+ <user><![CDATA[wdephill <wdephill@thoughtworks.com>]]></user>
47
+ <checkinTime>2013-02-08T16:19:18-08:00</checkinTime>
48
+ <revision><![CDATA[bc9cc9401b816d753f267227934e535affcb4028]]></revision>
49
+ <message><![CDATA[ #14163 - [WYSIWYG] Column layout. Use plugin onchange to ensure that there is an empty p at the end of the doc so that you can get out of the column.]]></message>
50
+ <file name="public/javascripts/ckeditor/config.js" action="modified"/>
51
+ <file name="public/javascripts/ckeditor/plugins/onchange/docs/install.html" action="added"/>
52
+ <file name="public/javascripts/ckeditor/plugins/onchange/docs/styles.css" action="added"/>
53
+ <file name="public/javascripts/ckeditor/plugins/onchange/plugin.js" action="added"/>
54
+ </changeset>
55
+ </modifications>
56
+ </material>
57
+ <material materialUri="https://go.example.com/go/api/materials/30536.xml" type="DependencyMaterial" pipelineName="IE8-PostgreSQL9" stageName="Acceptances">
58
+ <modifications>
59
+ <changeset changesetUri="https://go.example.com/go/api/stages/264242.xml">
60
+ <checkinTime>2013-02-08T20:33:45-08:00</checkinTime>
61
+ <revision>IE8-PostgreSQL9/942/Acceptances/1</revision>
62
+ </changeset>
63
+ </modifications>
64
+ </material>
65
+ </materials>
66
+ <stages>
67
+ <stage href="https://go.example.com/go/api/stages/264258.xml"/>
68
+ <stage href="https://go.example.com/go/api/stages/264271.xml"/>
69
+ </stages>
70
+ <approvedBy><![CDATA[changes]]></approvedBy>
71
+ </pipeline>
72
+ }
73
+
74
+ pipeline = GoApiClient::Pipeline.new(doc.root).parse!
75
+ assert_equal 1, pipeline.commits.count
76
+ commit = pipeline.commits.first
77
+
78
+ assert_equal 'bc9cc9401b816d753f267227934e535affcb4028', commit.revision
79
+ assert_equal User.new('wdephill', 'wdephill@thoughtworks.com'), commit.user
80
+ assert_equal Time.parse("2013-02-09 00:19:18 UTC"), commit.time
34
81
  end
35
82
 
36
83
  end
@@ -3,39 +3,73 @@ require "test_helper"
3
3
  module GoApiClient
4
4
  class StageTest < Test::Unit::TestCase
5
5
 
6
- def setup
6
+ test "should return stages in order" do
7
+ stub_request(:any, /.*go-server.2.project.*/).
8
+ to_return(
9
+ lambda do |request|
10
+ { :body => file_contents("ordering/#{request.uri.path}")}
11
+ end
12
+ ).times(9999)
13
+
14
+ runs = GoApiClient.runs(:host => 'go-server.2.project')
15
+
16
+ assert_equal runs[:pipelines].collect(&:counter).sort, runs[:pipelines].collect(&:counter)
17
+
18
+ runs[:pipelines].each do |pipeline|
19
+ assert_equal pipeline.stages.collect(&:completed_at).sort, pipeline.stages.collect(&:completed_at)
20
+ end
21
+ end
22
+
23
+ test "should parse stage" do
7
24
  stub_request(:get, "http://localhost:8153/go/api/pipelines/defaultPipeline/1.xml").to_return(:body => file_contents("pipelines_1.xml"))
8
25
  stub_request(:get, "http://localhost:8153/go/api/stages/1.xml").to_return(:body => file_contents("stages_1.xml"))
9
26
  stub_request(:get, "http://localhost:8153/go/api/stages/2.xml").to_return(:body => file_contents("stages_2.xml"))
10
27
  stub_request(:get, "http://localhost:8153/go/api/jobs/1.xml").to_return(:body => file_contents("jobs_1.xml"))
11
28
  stub_request(:get, "http://localhost:8153/go/api/jobs/2.xml").to_return(:body => file_contents("jobs_2.xml"))
12
- end
13
29
 
14
- def test_stage_parsing
15
30
  stub_request(:get, "http://localhost:8153/go/api/pipelines/defaultPipeline/stages.xml").to_return(:body => file_contents("stages.xml"))
16
- pipelines = GoApiClient.runs("localhost:8153")
31
+ runs = GoApiClient.runs(:host => "localhost", :port => 8153)
32
+ pipelines = runs[:pipelines]
33
+ assert_equal "http://localhost:8153/go/pipelines/defaultPipeline/1/Acceptance/1", runs[:latest_atom_entry_id]
17
34
  stages = pipelines.first.stages
18
35
 
19
36
  assert_equal 1, pipelines.count
20
37
  assert_equal 2, stages.count
21
- assert_equal "oogabooga <twgosaas@gmail.com>", pipelines.first.authors
38
+
39
+ assert_equal "http://localhost:8153/go/api/stages/1.xml", stages.first.url
40
+ assert_equal "http://localhost:8153/go/api/stages/2.xml", stages.last.url
41
+
42
+ assert_equal 1, stages.first.counter
43
+ assert_equal 1, stages.last.counter
44
+
45
+ assert_equal [Time.parse("2012-02-23T17:16:41+05:30").utc, Time.parse("2012-02-23T17:19:31+05:30").utc], stages.collect(&:completed_at)
46
+
47
+ assert_equal [Atom::Author.new(nil, :name => 'oogabooga', :email => 'twgosaas@gmail.com')], pipelines.first.authors
48
+
22
49
  stages.each do |stage|
23
- assert_equal "oogabooga <twgosaas@gmail.com>", stage.authors.first.name
50
+ assert_equal Atom::Author.new(nil, :name => 'oogabooga', :email => 'twgosaas@gmail.com'), stage.authors.first
24
51
  assert_equal "Failed", stage.result
52
+ assert stage.failed?
53
+ assert false == stage.passed?
25
54
  end
26
- assert_equal "Acceptance", stages.first.name
27
- assert_equal "Units", stages.last.name
28
- assert_equal ["Update README"], pipelines.first.commit_messages
29
55
 
30
- assert_equal "http://localhost:8153/go/files/defaultPipeline/1/Acceptance/1/Test/cruise-output/console.log", stages.first.jobs.first.console_log_url
31
- assert_equal "http://localhost:8153/go/files/defaultPipeline/1/Units/1/Test/cruise-output/console.log", stages.last.jobs.first.console_log_url
56
+ assert_equal "Units", stages.first.name
57
+ assert_equal "Acceptance", stages.last.name
58
+
59
+ assert_equal ["Update README", "Fixed build"], pipelines.first.commits.collect(&:message)
60
+
61
+ assert_equal "http://localhost:8153/go/files/defaultPipeline/1/Units/1/Test/cruise-output/console.log", stages.first.jobs.first.console_log_url
62
+ assert_equal "http://localhost:8153/go/files/defaultPipeline/1/Acceptance/1/Test/cruise-output/console.log", stages.last.jobs.first.console_log_url
63
+
64
+ assert_equal 'urn:x-go.studios.thoughtworks.com:stage-id:defaultPipeline:1:Units:1', stages.first.identifier
65
+ assert_equal 'urn:x-go.studios.thoughtworks.com:stage-id:defaultPipeline:1:Acceptance:1', stages.last.identifier
32
66
  end
33
67
 
34
- def test_empty_atom_feed_should_not_throw_up
68
+ test "empty atom feed should not throw up" do
35
69
  stub_request(:get, "http://localhost:8153/go/api/pipelines/defaultPipeline/stages.xml").to_return(:body => file_contents("stages_empty.xml"))
36
- pipelines = GoApiClient.runs("localhost:8153")
70
+ runs = GoApiClient.runs(:host => "localhost", :port => 8153)
37
71
 
38
- assert pipelines.empty?
72
+ assert runs[:pipelines].empty?
39
73
  end
40
74
  end
41
75
  end
@@ -0,0 +1,27 @@
1
+ require "test_helper"
2
+
3
+ module GoApiClient
4
+ class UserTest < Test::Unit::TestCase
5
+
6
+ test "should parse user name and email address" do
7
+ user = User.parse("foobar <foo@example.com>")
8
+ assert_equal 'foobar', user.name
9
+ assert_equal 'foo@example.com', user.email
10
+ end
11
+
12
+ test "should strip name and email when parsing" do
13
+ user = User.parse("foobar1 <foo1@example.com>")
14
+ assert_equal 'foobar1', user.name
15
+ assert_equal 'foo1@example.com', user.email
16
+ end
17
+
18
+ test "equality" do
19
+ assert_equal User.parse("foobar <foo@example.com>"), User.parse("foobar <foo@example.com>")
20
+ end
21
+
22
+ test "hashcode" do
23
+ assert_equal User.parse("foobar <foo@example.com>").hash, User.parse("foobar <foo@example.com>").hash
24
+ assert_not_equal User.parse("bar <bar@example.com>").hash, User.parse("foo <foo@example.com>").hash
25
+ end
26
+ end
27
+ end
data/test/test_helper.rb CHANGED
@@ -1,11 +1,27 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'simplecov'
4
+ SimpleCov.start do
5
+ add_filter "/.bundle/"
6
+ add_filter "/bundle/"
7
+ add_filter "/test/"
8
+ end
9
+
10
+ Bundler.require
1
11
  require 'test/unit'
2
12
  require 'go_api_client'
3
13
  require 'ostruct'
4
- Dir["go_api_client/**/*.rb"].each {|f| require f}
5
14
  require 'webmock/test_unit'
6
15
 
7
- def file_contents(file_name)
8
- File.read(File.expand_path("../../test/fixtures/#{file_name}", __FILE__))
16
+ module WebMock
17
+ class RequestStub
18
+ attr_accessor :responses_sequences
19
+ end
20
+ end
21
+ class Test::Unit::TestCase
22
+ def file_contents(file_name)
23
+ File.read(File.expand_path("../../test/fixtures/#{file_name}", __FILE__))
24
+ end
9
25
  end
10
26
 
11
27
  module Test::Unit::Assertions