bpci 0.0.1

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.
@@ -0,0 +1,28 @@
1
+ require 'helper'
2
+
3
+ class TestBPCIQueue < Test::Unit::TestCase
4
+ def test_a_disabled_queue
5
+ subject = BPCI::Queue.new(false)
6
+ subject.append_unless_already_exists("test")
7
+ assert_equal false, subject.waiting?
8
+ end
9
+
10
+ def test_adding_two_items_to_a_queue
11
+ subject = BPCI::Queue.new(true)
12
+ subject.append_unless_already_exists("test")
13
+ subject.append_unless_already_exists(nil)
14
+ assert_equal true, subject.waiting?
15
+ assert_equal "test", subject.next_branch_to_build
16
+ assert_equal nil, subject.next_branch_to_build
17
+ assert_equal false, subject.waiting?
18
+ end
19
+
20
+ def test_adding_two_duplicate_items_to_a_queue
21
+ subject = BPCI::Queue.new(true)
22
+ subject.append_unless_already_exists("test")
23
+ subject.append_unless_already_exists("test")
24
+ assert_equal true, subject.waiting?
25
+ assert_equal "test", subject.next_branch_to_build
26
+ assert_equal false, subject.waiting?
27
+ end
28
+ end
@@ -0,0 +1,128 @@
1
+ require "helper"
2
+ require "rack/test"
3
+ require "bpci/server"
4
+
5
+ class TestBPCIServer < Test::Unit::TestCase
6
+ include Rack::Test::Methods
7
+
8
+ class ::BPCI
9
+ attr_writer :current_build, :last_build
10
+ end
11
+
12
+ attr_accessor :app
13
+
14
+ def setup
15
+ @app = BPCI::Server.new
16
+ bpci = @app.bpci
17
+
18
+ # make Build#restore a no-op so we don't overwrite our current/last
19
+ # build attributes set from tests.
20
+ def bpci.restore
21
+ end
22
+
23
+ # make BPCI#build! and BPCI#git_update a no-op so we don't overwrite our local changes
24
+ # or local commits nor should we run tests.
25
+ def bpci.build!
26
+ end
27
+ end
28
+
29
+ def test_ping
30
+ app.bpci.last_build = build :worked
31
+ assert !app.bpci.building?, "have a last build, but not a current"
32
+
33
+ get "/ping"
34
+ assert_equal 200, last_response.status
35
+ assert_equal app.bpci.last_build.sha, last_response.body
36
+ end
37
+
38
+ def test_ping_building
39
+ app.bpci.current_build = build :building
40
+ assert app.bpci.building?, "buildin' a awsum project"
41
+
42
+ get "/ping"
43
+ assert_equal 412, last_response.status
44
+ assert_equal "building", last_response.body
45
+ end
46
+
47
+ def test_ping_building_with_a_previous_build
48
+ app.bpci.last_build = build :worked
49
+ app.bpci.current_build = build :building
50
+ assert app.bpci.building?, "buildin' a awsum project"
51
+
52
+ get "/ping"
53
+ assert_equal 412, last_response.status
54
+ assert_equal "building", last_response.body
55
+ end
56
+
57
+ def test_ping_failed
58
+ app.bpci.last_build = build :failed
59
+
60
+ get "/ping"
61
+ assert_equal 412, last_response.status
62
+ assert_equal app.bpci.last_build.sha, last_response.body
63
+ end
64
+
65
+ def test_ping_should_not_reset_current_build_in_tests
66
+ current_build = build :building
67
+ app.bpci.current_build = current_build
68
+ assert app.bpci.building?
69
+ get "/ping"
70
+ assert_equal current_build, app.bpci.current_build
71
+ end
72
+
73
+ def test_post_with_json_works
74
+ post '/', :payload => File.read("#{Dir.pwd}/test/fixtures/payload.json")
75
+ assert app.bpci.building?
76
+ assert_equal 302, last_response.status
77
+ end
78
+
79
+ def test_post_does_not_build_on_branch_mismatch
80
+ post "/", :payload => {"ref" => "refs/heads/dont_build"}.to_json
81
+ assert !app.bpci.building?
82
+ assert_equal 302, last_response.status
83
+ end
84
+
85
+ def test_post_builds_specific_branch
86
+ app.bpci.expects(:build!).with("branchname")
87
+ post "/?branch=branchname", :payload => {"ref" => "refs/heads/master"}.to_json
88
+ assert app.bpci.building?
89
+ assert_equal 302, last_response.status
90
+ end
91
+
92
+ def test_post_does_build_on_branch_match
93
+ post "/", :payload => {"ref" => "refs/heads/master"}.to_json
94
+ assert app.bpci.building?
95
+ assert_equal 302, last_response.status
96
+ end
97
+
98
+ def test_post_does_build_when_build_button_is_used
99
+ post "/", :rebuild => true
100
+ assert app.bpci.building?
101
+ assert_equal 302, last_response.status
102
+ end
103
+
104
+ def test_jsonp_should_return_plain_json_without_param
105
+ app.bpci.last_build = build :failed
106
+ get "/api/json"
107
+ assert_equal 200, last_response.status
108
+ assert_equal 'application/json', last_response.content_type
109
+ end
110
+
111
+ def test_jsonp_should_return_jsonp_with_param
112
+ app.bpci.last_build = build :failed
113
+ get "/api/json?jsonp=fooberz"
114
+ assert_equal 200, last_response.status
115
+ assert_equal 'application/json', last_response.content_type
116
+ assert_match /^fooberz\(/, last_response.body
117
+ end
118
+
119
+ def test_should_not_barf_when_no_build
120
+ end
121
+
122
+ # Create a new, fake build. All we care about is status.
123
+
124
+ def build status
125
+ BPCI::Build.new "path", "user", "project", Time.now, Time.now,
126
+ "deadbeef", status, "output", nil
127
+ end
128
+ end
@@ -0,0 +1,81 @@
1
+ require 'helper'
2
+
3
+ # mock files to true
4
+ class File
5
+ class << self
6
+ alias orig_exists? exists?
7
+ alias orig_executable? executable?
8
+
9
+ def exists?(f)
10
+ return true if $hook_override
11
+ orig_exists? f
12
+ end
13
+ def executable?(f)
14
+ return true if $hook_override
15
+ orig_executable? f
16
+ end
17
+ end
18
+ end
19
+
20
+ # #mock file to be the file I want
21
+ class BPCI
22
+ attr_writer :last_build
23
+ alias orig_path_in_project path_in_project
24
+ alias orig_git_user_and_project git_user_and_project
25
+
26
+ def path_in_project(f)
27
+ return '/tmp/test' if $hook_override
28
+ orig_path_in_project
29
+ end
30
+
31
+ def git_user_and_project
32
+ return ['mine','yours'] if $hook_override
33
+ orig_git_user_and_project
34
+ end
35
+ end
36
+
37
+ class BPCI::Commit
38
+ attr_writer :raw_commit
39
+ end
40
+
41
+
42
+
43
+ class TestHooks < Test::Unit::TestCase
44
+ def teardown
45
+ $hook_override = nil
46
+ end
47
+
48
+ def setup
49
+ $hook_override = true
50
+ open("/tmp/test",'w') do |file|
51
+ file.write "echo $test\n"
52
+ file.write "echo $AUTHOR\n"
53
+ file.write "export test=foo\n"
54
+ end
55
+ File.chmod(0777,'/tmp/test')
56
+
57
+ @bpci = BPCI.new('/tmp')
58
+ @bpci.last_build = BPCI::Build.new "path", "user", "project", Time.now, Time.now,
59
+ "deadbeef", :failed, "output", nil
60
+ @bpci.last_build.commit.raw_commit = "Author: commit author\nDate: now"
61
+ end
62
+
63
+ def test_leave_env_intact
64
+ ENV['AUTHOR'] = 'foo'
65
+ @bpci.run_hook("/tmp/test")
66
+ assert ENV.size != 0, 'ENV is empty but should not be'
67
+ assert ENV['AUTHOR'] == 'foo', 'ENV munged a value'
68
+ end
69
+
70
+ def test_empty_hook_env
71
+ ENV["test"] = 'should not be shown'
72
+ output = @bpci.run_hook("/tmp/test")
73
+ assert_equal "\ncommit author\n", output
74
+ end
75
+
76
+ def test_hook_munge_env
77
+ ENV['test'] = 'bar'
78
+ output = @bpci.run_hook("/tmp/test")
79
+ assert ENV['test'] == 'bar'
80
+ end
81
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bpci
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ricky Elrod
9
+ - Chris Wanstrath
10
+ - Josh Owens
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2012-04-09 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: choice
18
+ requirement: &6656920 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *6656920
27
+ - !ruby/object:Gem::Dependency
28
+ name: sinatra
29
+ requirement: &6656240 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *6656240
38
+ - !ruby/object:Gem::Dependency
39
+ name: json
40
+ requirement: &6655520 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: *6655520
49
+ - !ruby/object:Gem::Dependency
50
+ name: tinder
51
+ requirement: &6654800 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: 1.4.0
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: *6654800
60
+ - !ruby/object:Gem::Dependency
61
+ name: rack-test
62
+ requirement: &6654280 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *6654280
71
+ - !ruby/object:Gem::Dependency
72
+ name: mocha
73
+ requirement: &6653680 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *6653680
82
+ description: ! " *** bpci is a *fork* of cijoe (https://github.com/defunkt/cijoe/).
83
+ ***\n\n cijoe is a sinatra-based continuous integration server. It's like an\n
84
+ \ old rusty pickup truck: it might be smelly and gross, but it gets the\n job done.\n"
85
+ email: ricky@elrod.me
86
+ executables:
87
+ - bpci
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - README.md
92
+ - Rakefile
93
+ - LICENSE
94
+ - lib/bpci/irc.rb~
95
+ - lib/bpci/irc.rb
96
+ - lib/bpci/queue.rb
97
+ - lib/bpci/#config.rb#
98
+ - lib/bpci/config.rb
99
+ - lib/bpci/commit.rb
100
+ - lib/bpci/version.rb
101
+ - lib/bpci/views/json.erb
102
+ - lib/bpci/views/template.erb
103
+ - lib/bpci/build.rb
104
+ - lib/bpci/public/bootstrap/img/glyphicons-halflings.png
105
+ - lib/bpci/public/bootstrap/img/glyphicons-halflings-white.png
106
+ - lib/bpci/public/bootstrap/js/bootstrap.min.js
107
+ - lib/bpci/public/bootstrap/css/bootstrap-responsive.min.css
108
+ - lib/bpci/public/bootstrap/css/bootstrap.min.css
109
+ - lib/bpci/public/favicon.ico
110
+ - lib/bpci/server.rb
111
+ - lib/bpci.rb
112
+ - bin/bpci
113
+ - test/test_cijoe.rb
114
+ - test/helper.rb
115
+ - test/test_cijoe_queue.rb
116
+ - test/test_hooks.rb
117
+ - test/fixtures/payload.json
118
+ - test/test_cijoe_server.rb
119
+ homepage: http://github.com/breakpoint-eval/bpci
120
+ licenses: []
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 1.8.17
140
+ signing_key:
141
+ specification_version: 3
142
+ summary: The CI system used for Breakpoint Eval, forked from defunkt/cijoe.
143
+ test_files: []