boxen-linux 2.7.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.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.travis.yml +7 -0
- data/Gemfile +2 -0
- data/LICENSE +20 -0
- data/README.md +50 -0
- data/boxen.gemspec +26 -0
- data/lib/boxen/check.rb +72 -0
- data/lib/boxen/checkout.rb +25 -0
- data/lib/boxen/cli.rb +63 -0
- data/lib/boxen/config.rb +330 -0
- data/lib/boxen/error.rb +4 -0
- data/lib/boxen/flags.rb +272 -0
- data/lib/boxen/hook.rb +47 -0
- data/lib/boxen/hook/github_issue.rb +120 -0
- data/lib/boxen/hook/web.rb +56 -0
- data/lib/boxen/keychain.rb +63 -0
- data/lib/boxen/postflight.rb +13 -0
- data/lib/boxen/postflight/active.rb +16 -0
- data/lib/boxen/postflight/env.rb +34 -0
- data/lib/boxen/preflight.rb +13 -0
- data/lib/boxen/preflight/creds.rb +108 -0
- data/lib/boxen/preflight/directories.rb +32 -0
- data/lib/boxen/preflight/etc_my_cnf.rb +12 -0
- data/lib/boxen/preflight/homebrew.rb +13 -0
- data/lib/boxen/preflight/identity.rb +16 -0
- data/lib/boxen/preflight/os.rb +33 -0
- data/lib/boxen/preflight/rbenv.rb +12 -0
- data/lib/boxen/preflight/rvm.rb +12 -0
- data/lib/boxen/project.rb +20 -0
- data/lib/boxen/puppeteer.rb +122 -0
- data/lib/boxen/runner.rb +149 -0
- data/lib/boxen/service.rb +58 -0
- data/lib/boxen/util.rb +17 -0
- data/lib/facter/boxen.rb +34 -0
- data/lib/system_timer.rb +13 -0
- data/script/Boxen +0 -0
- data/script/Boxen-linux +0 -0
- data/script/bootstrap +7 -0
- data/script/build-keychain-helper +6 -0
- data/script/build-keyring-helper +9 -0
- data/script/release +38 -0
- data/script/tests +10 -0
- data/src/keychain-helper.c +85 -0
- data/src/keyring-helper.c +86 -0
- data/test/boxen/test.rb +7 -0
- data/test/boxen_check_test.rb +55 -0
- data/test/boxen_checkout_test.rb +42 -0
- data/test/boxen_cli_test.rb +39 -0
- data/test/boxen_config_test.rb +393 -0
- data/test/boxen_directories_test.rb +40 -0
- data/test/boxen_flags_test.rb +217 -0
- data/test/boxen_hook_github_issue_test.rb +294 -0
- data/test/boxen_hook_web_test.rb +58 -0
- data/test/boxen_keychain_test.rb +24 -0
- data/test/boxen_postflight_active_test.rb +29 -0
- data/test/boxen_postflight_env_test.rb +6 -0
- data/test/boxen_preflight_creds_test.rb +80 -0
- data/test/boxen_preflight_etc_my_cnf_test.rb +10 -0
- data/test/boxen_preflight_homebrew_test.rb +10 -0
- data/test/boxen_preflight_rvm_test.rb +10 -0
- data/test/boxen_project_test.rb +14 -0
- data/test/boxen_puppeteer_test.rb +101 -0
- data/test/boxen_runner_test.rb +171 -0
- data/test/boxen_service_test.rb +39 -0
- data/test/boxen_util_test.rb +21 -0
- data/test/fixtures/repo/modules/projects/manifests/first-project.pp +0 -0
- data/test/fixtures/repo/modules/projects/manifests/second-project.pp +0 -0
- data/test/system_timer.rb +10 -0
- metadata +279 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'boxen/test'
|
2
|
+
require 'boxen/preflight/directories'
|
3
|
+
|
4
|
+
class BoxenPreflightDirectoriesTest < Boxen::Test
|
5
|
+
class TestConfig
|
6
|
+
def user; "foobar"; end
|
7
|
+
def homedir; "foobar"; end
|
8
|
+
end
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@config = TestConfig.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_not_okay_if_homedir_group_wrong
|
15
|
+
directories = Boxen::Preflight::Directories.new(@config)
|
16
|
+
directories.stubs(:homedir_group).returns(false)
|
17
|
+
refute directories.ok?
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_not_okay_if_homedir_owner_wrong
|
21
|
+
directories = Boxen::Preflight::Directories.new(@config)
|
22
|
+
directories.stubs(:homedir_owner).returns(false)
|
23
|
+
refute directories.ok?
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_not_okay_unless_homedir_exists
|
27
|
+
directories = Boxen::Preflight::Directories.new(@config)
|
28
|
+
directories.stubs(:homedir_directory_exists?).returns(false)
|
29
|
+
refute directories.ok?
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_okay_if_allchecks_fine
|
33
|
+
directories = Boxen::Preflight::Directories.new(@config)
|
34
|
+
directories.stubs(:homedir_directory_exists?).returns(true)
|
35
|
+
directories.stubs(:homedir_owner).returns("foobar")
|
36
|
+
directories.stubs(:homedir_group).returns("staff")
|
37
|
+
|
38
|
+
assert directories.ok?
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,217 @@
|
|
1
|
+
require "boxen/test"
|
2
|
+
require "boxen/flags"
|
3
|
+
|
4
|
+
class BoxenFlagsTest < Boxen::Test
|
5
|
+
def test_apply
|
6
|
+
config = mock do
|
7
|
+
expects(:debug=).with true
|
8
|
+
|
9
|
+
stubs(:fde?).returns true
|
10
|
+
expects(:fde=).with false
|
11
|
+
|
12
|
+
expects(:homedir=).with "homedir"
|
13
|
+
expects(:logfile=).with "logfile"
|
14
|
+
expects(:login=).with "login"
|
15
|
+
expects(:token=).with "token"
|
16
|
+
expects(:pretend=).with true
|
17
|
+
expects(:profile=).with true
|
18
|
+
expects(:future_parser=).with true
|
19
|
+
expects(:report=).with true
|
20
|
+
expects(:graph=).with true
|
21
|
+
expects(:srcdir=).with "srcdir"
|
22
|
+
expects(:stealth=).with true
|
23
|
+
expects(:user=).with "user"
|
24
|
+
expects(:color=).with true
|
25
|
+
end
|
26
|
+
|
27
|
+
# Do our best to frob every switch.
|
28
|
+
|
29
|
+
flags = Boxen::Flags.new "--debug", "--help", "--login", "login",
|
30
|
+
"--no-fde", "--no-pull", "--no-issue", "--noop",
|
31
|
+
"--pretend", "--profile", "--future-parser", "--report", "--graph", "--projects",
|
32
|
+
"--user", "user", "--homedir", "homedir", "--srcdir", "srcdir",
|
33
|
+
"--logfile", "logfile", "--token", "token"
|
34
|
+
|
35
|
+
assert_same config, flags.apply(config)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_args
|
39
|
+
config = flags "--debug", "foo"
|
40
|
+
assert_equal %w(foo), config.args
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_debug
|
44
|
+
refute flags.debug?
|
45
|
+
assert flags("--debug").debug?
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_env?
|
49
|
+
refute flags.env?
|
50
|
+
assert flags("--env").env?
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_help
|
54
|
+
refute flags.help?
|
55
|
+
|
56
|
+
%w(--help -h -?).each do |flag|
|
57
|
+
assert flags(flag).help?
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_disable_services?
|
62
|
+
refute flags.disable_services?
|
63
|
+
assert flags("--disable-services").disable_services?
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_enable_services?
|
67
|
+
refute flags.enable_services?
|
68
|
+
assert flags("--enable-services").enable_services?
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_list_services?
|
72
|
+
refute flags.list_services?
|
73
|
+
assert flags("--list-services").list_services?
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_homedir
|
77
|
+
assert_nil flags.homedir
|
78
|
+
assert_equal "foo", flags("--homedir", "foo").homedir
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_initialize_bad_option
|
82
|
+
ex = assert_raises Boxen::Error do
|
83
|
+
flags "--bad-option"
|
84
|
+
end
|
85
|
+
|
86
|
+
assert_match "invalid option", ex.message
|
87
|
+
assert_match "--bad-option", ex.message
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_initialize_dups
|
91
|
+
args = %w(foo)
|
92
|
+
config = flags args
|
93
|
+
|
94
|
+
assert_equal args, config.args
|
95
|
+
refute_same args, config.args
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_initialize_empty
|
99
|
+
config = flags
|
100
|
+
assert_equal [], config.args
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_initialize_flattens
|
104
|
+
config = flags "foo", ["bar"]
|
105
|
+
assert_equal %w(foo bar), config.args
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_initialize_nils
|
109
|
+
config = flags "foo", nil, "bar"
|
110
|
+
assert_equal %w(foo bar), config.args
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_initialize_strings
|
114
|
+
config = flags :foo, [:bar]
|
115
|
+
assert_equal %w(foo bar), config.args
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_logfile
|
119
|
+
assert_nil flags.logfile
|
120
|
+
assert_equal "foo", flags("--logfile", "foo").logfile
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_login
|
124
|
+
assert_nil flags.login
|
125
|
+
assert_equal "jbarnette", flags("--login", "jbarnette").login
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_no_fde
|
129
|
+
assert flags.fde?
|
130
|
+
refute flags("--no-fde").fde?
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_no_pull_is_a_noop
|
134
|
+
flags "--no-pull"
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_parse
|
138
|
+
config = flags
|
139
|
+
config.parse "--debug", "foo"
|
140
|
+
|
141
|
+
assert config.debug?
|
142
|
+
assert_equal %w(foo), config.args
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_token
|
146
|
+
assert_nil flags.token
|
147
|
+
assert_equal "foo", flags("--token", "foo").token
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_token_missing_value
|
151
|
+
ex = assert_raises Boxen::Error do
|
152
|
+
flags "--token"
|
153
|
+
end
|
154
|
+
|
155
|
+
assert_match "missing argument", ex.message
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_pretend
|
159
|
+
refute flags.pretend?
|
160
|
+
assert flags("--noop").pretend?
|
161
|
+
assert flags("--pretend").pretend?
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_profile
|
165
|
+
refute flags.profile?
|
166
|
+
assert flags("--profile").profile?
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_future_parser
|
170
|
+
refute flags.future_parser?
|
171
|
+
assert flags("--future-parser").future_parser?
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_report
|
175
|
+
refute flags.report?
|
176
|
+
assert flags("--report").report?
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_graph
|
180
|
+
refute flags.graph?
|
181
|
+
assert flags("--graph").graph?
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_projects
|
185
|
+
refute flags.projects?
|
186
|
+
assert flags("--projects").projects?
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_srcdir
|
190
|
+
assert_nil flags.srcdir
|
191
|
+
assert_equal "foo", flags("--srcdir", "foo").srcdir
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_stealth
|
195
|
+
refute flags.stealth?
|
196
|
+
assert flags("--no-issue").stealth?
|
197
|
+
assert flags("--stealth").stealth?
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_user
|
201
|
+
assert_equal "jbarnette", flags("--user", "jbarnette").user
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_user_missing_value
|
205
|
+
ex = assert_raises Boxen::Error do
|
206
|
+
flags "--user"
|
207
|
+
end
|
208
|
+
|
209
|
+
assert_match "missing argument", ex.message
|
210
|
+
end
|
211
|
+
|
212
|
+
# Create an instance of Boxen::Flags with optional `args`.
|
213
|
+
|
214
|
+
def flags(*args)
|
215
|
+
Boxen::Flags.new *args
|
216
|
+
end
|
217
|
+
end
|
@@ -0,0 +1,294 @@
|
|
1
|
+
require "boxen/test"
|
2
|
+
require "boxen/hook/github_issue"
|
3
|
+
|
4
|
+
class Boxen::Config
|
5
|
+
attr_writer :api
|
6
|
+
end
|
7
|
+
|
8
|
+
class BoxenHookGitHubIssueTest < Boxen::Test
|
9
|
+
def setup
|
10
|
+
@config = Boxen::Config.new
|
11
|
+
@checkout = Boxen::Checkout.new(@config)
|
12
|
+
@puppet = mock 'puppeteer'
|
13
|
+
@result = stub 'result', :success? => true
|
14
|
+
@hook = Boxen::Hook::GitHubIssue.new @config, @checkout, @puppet, @result
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_enabled
|
18
|
+
original = ENV['BOXEN_ISSUES_ENABLED']
|
19
|
+
|
20
|
+
ENV['BOXEN_ISSUES_ENABLED'] = nil
|
21
|
+
refute @hook.enabled?
|
22
|
+
|
23
|
+
ENV['BOXEN_ISSUES_ENABLED'] = 'duh'
|
24
|
+
assert @hook.enabled?
|
25
|
+
|
26
|
+
ENV['BOXEN_ISSUES_ENABLED'] = original
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_perform
|
30
|
+
@hook.stubs(:enabled?).returns(false)
|
31
|
+
@config.stubs(:stealth?).returns(true)
|
32
|
+
@config.stubs(:pretend?).returns(true)
|
33
|
+
@checkout.stubs(:master?).returns(false)
|
34
|
+
@config.stubs(:login).returns(nil)
|
35
|
+
|
36
|
+
refute @hook.perform?
|
37
|
+
|
38
|
+
@hook.stubs(:enabled?).returns(true)
|
39
|
+
refute @hook.perform?
|
40
|
+
|
41
|
+
@config.stubs(:stealth?).returns(false)
|
42
|
+
refute @hook.perform?
|
43
|
+
|
44
|
+
@config.stubs(:pretend?).returns(false)
|
45
|
+
refute @hook.perform?
|
46
|
+
|
47
|
+
@checkout.stubs(:master?).returns(true)
|
48
|
+
refute @hook.perform?
|
49
|
+
|
50
|
+
@config.stubs(:login).returns('')
|
51
|
+
refute @hook.perform?
|
52
|
+
|
53
|
+
@config.stubs(:login).returns('somelogin')
|
54
|
+
assert @hook.perform?
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_compare_url
|
58
|
+
@config.reponame = repo = 'org/repo'
|
59
|
+
sha = 'deadbeef'
|
60
|
+
@checkout.expects(:sha).returns(sha)
|
61
|
+
|
62
|
+
expected = "https://github.com/#{repo}/compare/#{sha}...master"
|
63
|
+
assert_equal expected, @hook.compare_url
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_compare_url_ghurl
|
67
|
+
@config.reponame = repo = 'org/repo'
|
68
|
+
@config.ghurl = 'https://git.foo.com'
|
69
|
+
sha = 'deadbeef'
|
70
|
+
@checkout.expects(:sha).returns(sha)
|
71
|
+
|
72
|
+
expected = "https://git.foo.com/#{repo}/compare/#{sha}...master"
|
73
|
+
assert_equal expected, @hook.compare_url
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_hostname
|
77
|
+
@hook.expects(:"`").with("hostname").returns "whatevs.local\n"
|
78
|
+
assert_equal "whatevs.local", @hook.hostname
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_initialize
|
82
|
+
hook = Boxen::Hook::GitHubIssue.new :config, :checkout, :puppet, :result
|
83
|
+
assert_equal :config, hook.config
|
84
|
+
assert_equal :checkout, hook.checkout
|
85
|
+
assert_equal :puppet, hook.puppet
|
86
|
+
assert_equal :result, hook.result
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_os
|
90
|
+
@hook.expects(:"`").with("sw_vers -productVersion").returns "11.1.1\n"
|
91
|
+
assert_equal "11.1.1", @hook.os
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_shell
|
95
|
+
val = ENV['SHELL']
|
96
|
+
|
97
|
+
ENV['SHELL'] = '/bin/crush'
|
98
|
+
assert_equal "/bin/crush", @hook.shell
|
99
|
+
|
100
|
+
ENV['SHELL'] = val
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_record_failure
|
104
|
+
@hook.stubs(:issues?).returns(true)
|
105
|
+
|
106
|
+
details = 'Everything went wrong.'
|
107
|
+
@hook.stubs(:failure_details).returns(details)
|
108
|
+
|
109
|
+
@config.reponame = repo = 'some/repo'
|
110
|
+
@config.user = user = 'hapless'
|
111
|
+
|
112
|
+
@hook.failure_label = label = 'boom'
|
113
|
+
|
114
|
+
@config.api = api = mock('api')
|
115
|
+
api.expects(:create_issue).with(repo, "Failed for #{user}", details, :labels => [label])
|
116
|
+
|
117
|
+
@hook.record_failure
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_record_failure_no_issues
|
121
|
+
@hook.stubs(:issues?).returns(false)
|
122
|
+
|
123
|
+
@config.api = api = mock('api')
|
124
|
+
api.expects(:create_issue).never
|
125
|
+
|
126
|
+
@hook.record_failure
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_failure_label
|
130
|
+
default = 'failure'
|
131
|
+
assert_equal default, @hook.failure_label
|
132
|
+
|
133
|
+
@hook.failure_label = label = 'oops'
|
134
|
+
assert_equal label, @hook.failure_label
|
135
|
+
|
136
|
+
@hook.failure_label = nil
|
137
|
+
assert_equal default, @hook.failure_label
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_ongoing_label
|
141
|
+
default = 'ongoing'
|
142
|
+
assert_equal default, @hook.ongoing_label
|
143
|
+
|
144
|
+
@hook.ongoing_label = label = 'checkit'
|
145
|
+
assert_equal label, @hook.ongoing_label
|
146
|
+
|
147
|
+
@hook.ongoing_label = nil
|
148
|
+
assert_equal default, @hook.ongoing_label
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_failure_details
|
152
|
+
sha = 'decafbad'
|
153
|
+
@checkout.stubs(:sha).returns(sha)
|
154
|
+
hostname = 'cools.local'
|
155
|
+
@hook.stubs(:hostname).returns(hostname)
|
156
|
+
shell = '/bin/ksh'
|
157
|
+
@hook.stubs(:shell).returns(shell)
|
158
|
+
os = '11.1.1'
|
159
|
+
@hook.stubs(:os).returns(os)
|
160
|
+
log = "so\nmany\nthings\nto\nreport"
|
161
|
+
@hook.stubs(:log).returns(log)
|
162
|
+
|
163
|
+
@config.reponame = repo = 'some/repo'
|
164
|
+
compare = @hook.compare_url
|
165
|
+
changes = 'so many changes'
|
166
|
+
@checkout.stubs(:changes).returns(changes)
|
167
|
+
|
168
|
+
commands = %w[/path/to/puppet apply stuff_and_things]
|
169
|
+
@puppet.stubs(:command).returns(commands)
|
170
|
+
command = commands.join(' ')
|
171
|
+
|
172
|
+
@config.logfile = logfile = '/path/to/logfile.txt'
|
173
|
+
|
174
|
+
details = @hook.failure_details
|
175
|
+
|
176
|
+
assert_match sha, details
|
177
|
+
assert_match hostname, details
|
178
|
+
assert_match shell, details
|
179
|
+
assert_match os, details
|
180
|
+
assert_match compare, details
|
181
|
+
assert_match changes, details
|
182
|
+
assert_match command, details
|
183
|
+
assert_match logfile, details
|
184
|
+
assert_match log, details
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_log
|
188
|
+
@config.logfile = logfile = '/path/to/logfile.txt'
|
189
|
+
|
190
|
+
log = 'a bunch of log data'
|
191
|
+
File.expects(:read).with(logfile).returns(log)
|
192
|
+
|
193
|
+
assert_equal log, @hook.log
|
194
|
+
end
|
195
|
+
|
196
|
+
|
197
|
+
Issue = Struct.new(:number, :labels) do
|
198
|
+
def labels
|
199
|
+
self[:labels] || []
|
200
|
+
end
|
201
|
+
end
|
202
|
+
Label = Struct.new(:name)
|
203
|
+
|
204
|
+
def test_close_failures
|
205
|
+
@hook.stubs(:issues?).returns(true)
|
206
|
+
|
207
|
+
@config.reponame = repo = 'some/repo'
|
208
|
+
|
209
|
+
issues = Array.new(3) { |i| Issue.new(i*2 + 2) }
|
210
|
+
@hook.stubs(:failures).returns(issues)
|
211
|
+
|
212
|
+
sha = 'decafbad'
|
213
|
+
@checkout.stubs(:sha).returns(sha)
|
214
|
+
|
215
|
+
@config.api = api = mock('api')
|
216
|
+
issues.each do |issue|
|
217
|
+
api.expects(:add_comment).with(repo, issue.number, "Succeeded at version #{sha}.")
|
218
|
+
api.expects(:close_issue).with(repo, issue.number)
|
219
|
+
end
|
220
|
+
|
221
|
+
@hook.close_failures
|
222
|
+
end
|
223
|
+
|
224
|
+
def test_close_failures_no_issues
|
225
|
+
@hook.stubs(:issues?).returns(false)
|
226
|
+
|
227
|
+
@hook.expects(:failures).never
|
228
|
+
|
229
|
+
@config.api = api = mock('api')
|
230
|
+
api.expects(:add_comment).never
|
231
|
+
api.expects(:close_issue).never
|
232
|
+
|
233
|
+
@hook.close_failures
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_failures
|
237
|
+
@hook.stubs(:issues?).returns(true)
|
238
|
+
|
239
|
+
@config.reponame = repo = 'some/repo'
|
240
|
+
@config.login = user = 'hapless'
|
241
|
+
|
242
|
+
@hook.failure_label = fail_label = 'ouch'
|
243
|
+
@hook.ongoing_label = goon_label = 'goon'
|
244
|
+
|
245
|
+
fail_l = Label.new(fail_label)
|
246
|
+
goon_l = Label.new(goon_label)
|
247
|
+
pop_l = Label.new('popcorn')
|
248
|
+
|
249
|
+
issues = [
|
250
|
+
Issue.new(0, [fail_l]),
|
251
|
+
Issue.new(1, [fail_l, pop_l]),
|
252
|
+
Issue.new(2, [fail_l, goon_l]),
|
253
|
+
Issue.new(3, [fail_l, Label.new('bang')]),
|
254
|
+
Issue.new(4, [fail_l, goon_l, pop_l]),
|
255
|
+
]
|
256
|
+
|
257
|
+
@config.api = api = mock('api')
|
258
|
+
api.expects(:list_issues).with(repo, :state => 'open', :labels => fail_label, :creator => user).returns(issues)
|
259
|
+
|
260
|
+
assert_equal issues.values_at(0,1,3), @hook.failures
|
261
|
+
end
|
262
|
+
|
263
|
+
def test_failures_no_issues
|
264
|
+
@hook.stubs(:issues?).returns(false)
|
265
|
+
|
266
|
+
@config.api = api = mock('api')
|
267
|
+
api.expects(:list_issues).never
|
268
|
+
|
269
|
+
assert_equal [], @hook.failures
|
270
|
+
end
|
271
|
+
|
272
|
+
RepoInfo = Struct.new(:has_issues)
|
273
|
+
def test_issues?
|
274
|
+
@config.reponame = repo = 'some/repo'
|
275
|
+
|
276
|
+
repo_info = RepoInfo.new(true)
|
277
|
+
|
278
|
+
@config.api = api = mock('api')
|
279
|
+
api.stubs(:repository).with(repo).returns(repo_info)
|
280
|
+
assert @hook.issues?
|
281
|
+
|
282
|
+
repo_info = RepoInfo.new(false)
|
283
|
+
api.stubs(:repository).with(repo).returns(repo_info)
|
284
|
+
refute @hook.issues?
|
285
|
+
|
286
|
+
@config.stubs(:reponame) # to ensure the returned value is nil
|
287
|
+
api.stubs(:repository).returns(RepoInfo.new(true))
|
288
|
+
refute @hook.issues?
|
289
|
+
|
290
|
+
@config.stubs(:reponame).returns('boxen/our-boxen') # our main public repo
|
291
|
+
api.stubs(:repository).returns(RepoInfo.new(true))
|
292
|
+
refute @hook.issues?
|
293
|
+
end
|
294
|
+
end
|