boxen 3.0.0.beta1 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +0 -1
- data/README.md +1 -1
- data/boxen.gemspec +13 -13
- data/lib/boxen/check.rb +39 -8
- data/lib/boxen/cli.rb +45 -19
- data/lib/boxen/config.rb +61 -43
- data/lib/boxen/flags.rb +282 -0
- data/lib/boxen/hook.rb +8 -15
- data/lib/boxen/hook/github_issue.rb +120 -0
- data/lib/boxen/hook/web.rb +56 -0
- data/lib/boxen/keychain.rb +1 -1
- data/lib/boxen/postflight/env.rb +1 -1
- data/lib/boxen/preflight.rb +7 -4
- data/lib/boxen/preflight/creds.rb +47 -8
- data/lib/boxen/preflight/identity.rb +0 -2
- data/lib/boxen/preflight/os.rb +6 -2
- data/lib/boxen/puppeteer.rb +121 -0
- data/lib/boxen/runner.rb +149 -0
- data/script/bootstrap +1 -1
- data/script/tests +0 -1
- data/test/boxen/test.rb +1 -1
- data/test/boxen_check_test.rb +55 -0
- data/test/boxen_cli_test.rb +31 -8
- data/test/boxen_config_test.rb +31 -1
- data/test/boxen_directories_test.rb +4 -4
- data/test/boxen_flags_test.rb +217 -0
- data/test/{postflight/boxen_postflight_github_issue_test.rb → boxen_hook_github_issue_test.rb} +82 -72
- data/test/{postflight/boxen_postflight_web_hook_test.rb → boxen_hook_web_test.rb} +11 -12
- data/test/{postflight/boxen_postflight_active_test.rb → boxen_postflight_active_test.rb} +3 -3
- data/test/{postflight/boxen_postflight_env_test.rb → boxen_postflight_env_test.rb} +0 -0
- data/test/boxen_preflight_creds_test.rb +177 -0
- data/test/{preflight/boxen_preflight_etc_my_cnf_test.rb → boxen_preflight_etc_my_cnf_test.rb} +1 -1
- data/test/{preflight/boxen_preflight_rvm_test.rb → boxen_preflight_rvm_test.rb} +1 -1
- data/test/boxen_puppeteer_test.rb +101 -0
- data/test/boxen_runner_test.rb +171 -0
- metadata +172 -251
- data/lib/boxen/command.rb +0 -142
- data/lib/boxen/command/help.rb +0 -40
- data/lib/boxen/command/preflight.rb +0 -38
- data/lib/boxen/command/project.rb +0 -49
- data/lib/boxen/command/project/install.rb +0 -33
- data/lib/boxen/command/run.rb +0 -199
- data/lib/boxen/command/service.rb +0 -61
- data/lib/boxen/command/service/disable.rb +0 -15
- data/lib/boxen/command/service/enable.rb +0 -15
- data/lib/boxen/command/service/restart.rb +0 -24
- data/lib/boxen/command/version.rb +0 -29
- data/lib/boxen/command_status.rb +0 -15
- data/lib/boxen/postflight/github_issue.rb +0 -124
- data/lib/boxen/postflight/hooks.rb +0 -16
- data/lib/boxen/postflight/web_hook.rb +0 -63
- data/lib/boxen/preflight/facts.rb +0 -36
- data/lib/boxen/preflight/homebrew.rb +0 -13
- data/lib/boxen/preflight/offline.rb +0 -33
- data/lib/boxen/preflight/update.rb +0 -109
- data/lib/boxen/util/logging.rb +0 -59
- data/lib/boxen/version.rb +0 -3
- data/lib/system_timer.rb +0 -13
- data/test/boxen_command_test.rb +0 -93
- data/test/boxen_hook_test.rb +0 -25
- data/test/command/help_test.rb +0 -49
- data/test/command/project/install_test.rb +0 -34
- data/test/command/project_test.rb +0 -32
- data/test/command/run_test.rb +0 -21
- data/test/command/service/disable_test.rb +0 -49
- data/test/command/service/enable_test.rb +0 -49
- data/test/command/service/restart_test.rb +0 -53
- data/test/command/service_test.rb +0 -55
- data/test/command/version_test.rb +0 -15
- data/test/preflight/boxen_preflight_creds_test.rb +0 -82
- data/test/preflight/boxen_preflight_homebrew_test.rb +0 -10
- data/test/system_timer.rb +0 -10
data/script/bootstrap
CHANGED
data/script/tests
CHANGED
data/test/boxen/test.rb
CHANGED
@@ -0,0 +1,55 @@
|
|
1
|
+
require "boxen/test"
|
2
|
+
require "boxen/check"
|
3
|
+
|
4
|
+
class BoxenCheckTest < Boxen::Test
|
5
|
+
def test_initialize
|
6
|
+
check = Boxen::Check.new :config
|
7
|
+
assert_equal :config, check.config
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_ok?
|
11
|
+
ex = assert_raises RuntimeError do
|
12
|
+
Boxen::Check.new(:config).ok?
|
13
|
+
end
|
14
|
+
|
15
|
+
assert_match "must implement", ex.message
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_run
|
19
|
+
ex = assert_raises RuntimeError do
|
20
|
+
Boxen::Check.new(:config).run
|
21
|
+
end
|
22
|
+
|
23
|
+
assert_match "must implement", ex.message
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_self_checks
|
27
|
+
subclass = Class.new Boxen::Check
|
28
|
+
Boxen::Check.const_set :TestCheck, subclass
|
29
|
+
|
30
|
+
assert Boxen::Check.checks(:config).any? { |c| subclass === c },
|
31
|
+
"an instance of TestCheck exists in checks"
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_self_checks_subclasses
|
35
|
+
klass = Struct.new :config
|
36
|
+
Boxen::Check.const_set :TestBadCheck, klass
|
37
|
+
|
38
|
+
refute Boxen::Check.checks(:config).any? { |c| klass === c },
|
39
|
+
"checks are subclasses of Boxen::Check"
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_self_run
|
43
|
+
willrun = mock do
|
44
|
+
expects(:ok?).returns false
|
45
|
+
expects(:run)
|
46
|
+
end
|
47
|
+
|
48
|
+
wontrun = mock do
|
49
|
+
expects(:ok?).returns true
|
50
|
+
end
|
51
|
+
|
52
|
+
Boxen::Check.expects(:checks).with(:config).returns [willrun, wontrun]
|
53
|
+
Boxen::Check.run :config
|
54
|
+
end
|
55
|
+
end
|
data/test/boxen_cli_test.rb
CHANGED
@@ -1,16 +1,39 @@
|
|
1
|
+
require "boxen/test"
|
1
2
|
require "boxen/cli"
|
2
3
|
|
3
|
-
|
4
|
+
class BoxenCLITest < Boxen::Test
|
5
|
+
def setup
|
6
|
+
@config = Boxen::Config.new
|
7
|
+
@flags = Boxen::Flags.new
|
8
|
+
@cli = Boxen::CLI.new(@config, @flags)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_initialize
|
12
|
+
config = Boxen::Config.new
|
13
|
+
flags = Boxen::Flags.new
|
14
|
+
|
15
|
+
cli = Boxen::CLI.new config, flags
|
4
16
|
|
5
|
-
|
17
|
+
assert_equal config, cli.config
|
18
|
+
assert_equal flags, cli.flags
|
6
19
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
Boxen::Command.expects(:invoke).with("foo", config).
|
11
|
-
returns(Boxen::CommandStatus.new(0))
|
20
|
+
assert_equal config, cli.runner.config
|
21
|
+
assert_equal flags, cli.runner.flags
|
22
|
+
end
|
12
23
|
|
13
|
-
|
24
|
+
def test_run
|
25
|
+
@cli.runner.expects(:run)
|
26
|
+
@cli.run
|
14
27
|
end
|
15
28
|
|
29
|
+
def test_help
|
30
|
+
$stdout.stubs(:write)
|
31
|
+
|
32
|
+
flags = Boxen::Flags.new('--help')
|
33
|
+
cli = Boxen::CLI.new(@config, flags)
|
34
|
+
cli.runner.expects(:run).never
|
35
|
+
assert_raises SystemExit do
|
36
|
+
cli.run
|
37
|
+
end
|
38
|
+
end
|
16
39
|
end
|
data/test/boxen_config_test.rb
CHANGED
@@ -7,6 +7,13 @@ class BoxenConfigTest < Boxen::Test
|
|
7
7
|
@config.repodir = "test/fixtures/repo"
|
8
8
|
end
|
9
9
|
|
10
|
+
def test_debug?
|
11
|
+
refute @config.debug?
|
12
|
+
|
13
|
+
@config.debug = true
|
14
|
+
assert @config.debug?
|
15
|
+
end
|
16
|
+
|
10
17
|
def test_email
|
11
18
|
assert_nil @config.email
|
12
19
|
|
@@ -89,6 +96,27 @@ class BoxenConfigTest < Boxen::Test
|
|
89
96
|
assert_equal "foo", @config.name
|
90
97
|
end
|
91
98
|
|
99
|
+
def test_pretend?
|
100
|
+
refute @config.pretend?
|
101
|
+
|
102
|
+
@config.pretend = true
|
103
|
+
assert @config.pretend?
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_profile?
|
107
|
+
refute @config.profile?
|
108
|
+
|
109
|
+
@config.profile = true
|
110
|
+
assert @config.profile?
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_future_parser?
|
114
|
+
refute @config.future_parser?
|
115
|
+
|
116
|
+
@config.future_parser = true
|
117
|
+
assert @config.future_parser?
|
118
|
+
end
|
119
|
+
|
92
120
|
def test_projects
|
93
121
|
files = Dir["#{@config.repodir}/modules/projects/manifests/*.pp"]
|
94
122
|
assert_equal files.size, @config.projects.size
|
@@ -296,6 +324,8 @@ class BoxenConfigTest < Boxen::Test
|
|
296
324
|
end
|
297
325
|
|
298
326
|
def test_token
|
327
|
+
assert_nil @config.token
|
328
|
+
|
299
329
|
@config.token = "foo"
|
300
330
|
assert_equal "foo", @config.token
|
301
331
|
end
|
@@ -352,7 +382,7 @@ class BoxenConfigTest < Boxen::Test
|
|
352
382
|
ENV["BOXEN_S3_BUCKET"] = val
|
353
383
|
end
|
354
384
|
|
355
|
-
def
|
385
|
+
def test_s3host_env_var
|
356
386
|
val = ENV["BOXEN_S3_BUCKET"]
|
357
387
|
|
358
388
|
ENV["BOXEN_S3_BUCKET"] = "my-bucket"
|
@@ -12,25 +12,25 @@ class BoxenPreflightDirectoriesTest < Boxen::Test
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_not_okay_if_homedir_group_wrong
|
15
|
-
directories = Boxen::Preflight::Directories.new(@config
|
15
|
+
directories = Boxen::Preflight::Directories.new(@config)
|
16
16
|
directories.stubs(:homedir_group).returns(false)
|
17
17
|
refute directories.ok?
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_not_okay_if_homedir_owner_wrong
|
21
|
-
directories = Boxen::Preflight::Directories.new(@config
|
21
|
+
directories = Boxen::Preflight::Directories.new(@config)
|
22
22
|
directories.stubs(:homedir_owner).returns(false)
|
23
23
|
refute directories.ok?
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_not_okay_unless_homedir_exists
|
27
|
-
directories = Boxen::Preflight::Directories.new(@config
|
27
|
+
directories = Boxen::Preflight::Directories.new(@config)
|
28
28
|
directories.stubs(:homedir_directory_exists?).returns(false)
|
29
29
|
refute directories.ok?
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_okay_if_allchecks_fine
|
33
|
-
directories = Boxen::Preflight::Directories.new(@config
|
33
|
+
directories = Boxen::Preflight::Directories.new(@config)
|
34
34
|
directories.stubs(:homedir_directory_exists?).returns(true)
|
35
35
|
directories.stubs(:homedir_owner).returns("foobar")
|
36
36
|
directories.stubs(:homedir_group).returns("staff")
|
@@ -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
|
data/test/{postflight/boxen_postflight_github_issue_test.rb → boxen_hook_github_issue_test.rb}
RENAMED
@@ -1,54 +1,57 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require 'boxen/postflight/github_issue'
|
1
|
+
require "boxen/test"
|
2
|
+
require "boxen/hook/github_issue"
|
4
3
|
|
5
4
|
class Boxen::Config
|
6
5
|
attr_writer :api
|
7
6
|
end
|
8
7
|
|
9
|
-
class
|
10
|
-
attr_writer :checkout
|
11
|
-
end
|
12
|
-
|
13
|
-
class BoxenPostflightGithubIssueTest < Boxen::Test
|
8
|
+
class BoxenHookGitHubIssueTest < Boxen::Test
|
14
9
|
def setup
|
15
10
|
@config = Boxen::Config.new
|
16
11
|
@checkout = Boxen::Checkout.new(@config)
|
17
|
-
@
|
18
|
-
@
|
19
|
-
@
|
12
|
+
@puppet = mock 'puppeteer'
|
13
|
+
@result = stub 'result', :success? => true
|
14
|
+
@hook = Boxen::Hook::GitHubIssue.new @config, @checkout, @puppet, @result
|
20
15
|
end
|
21
16
|
|
22
17
|
def test_enabled
|
23
18
|
original = ENV['BOXEN_ISSUES_ENABLED']
|
24
19
|
|
25
20
|
ENV['BOXEN_ISSUES_ENABLED'] = nil
|
26
|
-
refute @
|
21
|
+
refute @hook.enabled?
|
27
22
|
|
28
23
|
ENV['BOXEN_ISSUES_ENABLED'] = 'duh'
|
29
|
-
assert @
|
24
|
+
assert @hook.enabled?
|
30
25
|
|
31
26
|
ENV['BOXEN_ISSUES_ENABLED'] = original
|
32
27
|
end
|
33
28
|
|
34
|
-
def
|
35
|
-
@
|
29
|
+
def test_perform
|
30
|
+
@hook.stubs(:enabled?).returns(false)
|
31
|
+
@config.stubs(:stealth?).returns(true)
|
32
|
+
@config.stubs(:pretend?).returns(true)
|
36
33
|
@checkout.stubs(:master?).returns(false)
|
37
34
|
@config.stubs(:login).returns(nil)
|
38
35
|
|
39
|
-
|
36
|
+
refute @hook.perform?
|
37
|
+
|
38
|
+
@hook.stubs(:enabled?).returns(true)
|
39
|
+
refute @hook.perform?
|
40
40
|
|
41
|
-
@
|
42
|
-
|
41
|
+
@config.stubs(:stealth?).returns(false)
|
42
|
+
refute @hook.perform?
|
43
|
+
|
44
|
+
@config.stubs(:pretend?).returns(false)
|
45
|
+
refute @hook.perform?
|
43
46
|
|
44
47
|
@checkout.stubs(:master?).returns(true)
|
45
|
-
|
48
|
+
refute @hook.perform?
|
46
49
|
|
47
50
|
@config.stubs(:login).returns('')
|
48
|
-
|
51
|
+
refute @hook.perform?
|
49
52
|
|
50
53
|
@config.stubs(:login).returns('somelogin')
|
51
|
-
|
54
|
+
assert @hook.perform?
|
52
55
|
end
|
53
56
|
|
54
57
|
def test_compare_url
|
@@ -57,7 +60,7 @@ class BoxenPostflightGithubIssueTest < Boxen::Test
|
|
57
60
|
@checkout.expects(:sha).returns(sha)
|
58
61
|
|
59
62
|
expected = "https://github.com/#{repo}/compare/#{sha}...master"
|
60
|
-
assert_equal expected, @
|
63
|
+
assert_equal expected, @hook.compare_url
|
61
64
|
end
|
62
65
|
|
63
66
|
def test_compare_url_ghurl
|
@@ -67,102 +70,108 @@ class BoxenPostflightGithubIssueTest < Boxen::Test
|
|
67
70
|
@checkout.expects(:sha).returns(sha)
|
68
71
|
|
69
72
|
expected = "https://git.foo.com/#{repo}/compare/#{sha}...master"
|
70
|
-
assert_equal expected, @
|
73
|
+
assert_equal expected, @hook.compare_url
|
71
74
|
end
|
72
75
|
|
73
76
|
def test_hostname
|
74
|
-
|
75
|
-
assert_equal "whatevs.local", @
|
77
|
+
@hook.expects(:"`").with("hostname").returns "whatevs.local\n"
|
78
|
+
assert_equal "whatevs.local", @hook.hostname
|
76
79
|
end
|
77
80
|
|
78
81
|
def test_initialize
|
79
|
-
|
80
|
-
assert_equal :config,
|
81
|
-
assert_equal :
|
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
|
82
87
|
end
|
83
88
|
|
84
89
|
def test_os
|
85
|
-
@
|
86
|
-
assert_equal "11.1.1", @
|
90
|
+
@hook.expects(:"`").with("sw_vers -productVersion").returns "11.1.1\n"
|
91
|
+
assert_equal "11.1.1", @hook.os
|
87
92
|
end
|
88
93
|
|
89
94
|
def test_shell
|
90
95
|
val = ENV['SHELL']
|
91
96
|
|
92
97
|
ENV['SHELL'] = '/bin/crush'
|
93
|
-
assert_equal "/bin/crush", @
|
98
|
+
assert_equal "/bin/crush", @hook.shell
|
94
99
|
|
95
100
|
ENV['SHELL'] = val
|
96
101
|
end
|
97
102
|
|
98
103
|
def test_record_failure
|
99
|
-
@
|
104
|
+
@hook.stubs(:issues?).returns(true)
|
100
105
|
|
101
106
|
details = 'Everything went wrong.'
|
102
|
-
@
|
107
|
+
@hook.stubs(:failure_details).returns(details)
|
103
108
|
|
104
109
|
@config.reponame = repo = 'some/repo'
|
105
110
|
@config.user = user = 'hapless'
|
106
111
|
|
107
|
-
@
|
112
|
+
@hook.failure_label = label = 'boom'
|
108
113
|
|
109
114
|
@config.api = api = mock('api')
|
110
115
|
api.expects(:create_issue).with(repo, "Failed for #{user}", details, :labels => [label])
|
111
116
|
|
112
|
-
@
|
117
|
+
@hook.record_failure
|
113
118
|
end
|
114
119
|
|
115
120
|
def test_record_failure_no_issues
|
116
|
-
@
|
121
|
+
@hook.stubs(:issues?).returns(false)
|
117
122
|
|
118
123
|
@config.api = api = mock('api')
|
119
124
|
api.expects(:create_issue).never
|
120
125
|
|
121
|
-
@
|
126
|
+
@hook.record_failure
|
122
127
|
end
|
123
128
|
|
124
129
|
def test_failure_label
|
125
130
|
default = 'failure'
|
126
|
-
assert_equal default, @
|
131
|
+
assert_equal default, @hook.failure_label
|
127
132
|
|
128
|
-
@
|
129
|
-
assert_equal label, @
|
133
|
+
@hook.failure_label = label = 'oops'
|
134
|
+
assert_equal label, @hook.failure_label
|
130
135
|
|
131
|
-
@
|
132
|
-
assert_equal default, @
|
136
|
+
@hook.failure_label = nil
|
137
|
+
assert_equal default, @hook.failure_label
|
133
138
|
end
|
134
139
|
|
135
140
|
def test_ongoing_label
|
136
141
|
default = 'ongoing'
|
137
|
-
assert_equal default, @
|
142
|
+
assert_equal default, @hook.ongoing_label
|
138
143
|
|
139
|
-
@
|
140
|
-
assert_equal label, @
|
144
|
+
@hook.ongoing_label = label = 'checkit'
|
145
|
+
assert_equal label, @hook.ongoing_label
|
141
146
|
|
142
|
-
@
|
143
|
-
assert_equal default, @
|
147
|
+
@hook.ongoing_label = nil
|
148
|
+
assert_equal default, @hook.ongoing_label
|
144
149
|
end
|
145
150
|
|
146
151
|
def test_failure_details
|
147
152
|
sha = 'decafbad'
|
148
153
|
@checkout.stubs(:sha).returns(sha)
|
149
154
|
hostname = 'cools.local'
|
150
|
-
@
|
155
|
+
@hook.stubs(:hostname).returns(hostname)
|
151
156
|
shell = '/bin/ksh'
|
152
|
-
@
|
157
|
+
@hook.stubs(:shell).returns(shell)
|
153
158
|
os = '11.1.1'
|
154
|
-
@
|
159
|
+
@hook.stubs(:os).returns(os)
|
155
160
|
log = "so\nmany\nthings\nto\nreport"
|
156
|
-
@
|
161
|
+
@hook.stubs(:log).returns(log)
|
157
162
|
|
158
|
-
@config.reponame = 'some/repo'
|
159
|
-
compare = @
|
163
|
+
@config.reponame = repo = 'some/repo'
|
164
|
+
compare = @hook.compare_url
|
160
165
|
changes = 'so many changes'
|
161
166
|
@checkout.stubs(:changes).returns(changes)
|
162
167
|
|
168
|
+
commands = %w[/path/to/puppet apply stuff_and_things]
|
169
|
+
@puppet.stubs(:command).returns(commands)
|
170
|
+
command = commands.join(' ')
|
171
|
+
|
163
172
|
@config.logfile = logfile = '/path/to/logfile.txt'
|
164
173
|
|
165
|
-
details = @
|
174
|
+
details = @hook.failure_details
|
166
175
|
|
167
176
|
assert_match sha, details
|
168
177
|
assert_match hostname, details
|
@@ -170,17 +179,18 @@ class BoxenPostflightGithubIssueTest < Boxen::Test
|
|
170
179
|
assert_match os, details
|
171
180
|
assert_match compare, details
|
172
181
|
assert_match changes, details
|
182
|
+
assert_match command, details
|
173
183
|
assert_match logfile, details
|
174
184
|
assert_match log, details
|
175
185
|
end
|
176
186
|
|
177
|
-
def
|
187
|
+
def test_log
|
178
188
|
@config.logfile = logfile = '/path/to/logfile.txt'
|
179
189
|
|
180
190
|
log = 'a bunch of log data'
|
181
191
|
File.expects(:read).with(logfile).returns(log)
|
182
192
|
|
183
|
-
assert_equal log, @
|
193
|
+
assert_equal log, @hook.log
|
184
194
|
end
|
185
195
|
|
186
196
|
|
@@ -192,12 +202,12 @@ class BoxenPostflightGithubIssueTest < Boxen::Test
|
|
192
202
|
Label = Struct.new(:name)
|
193
203
|
|
194
204
|
def test_close_failures
|
195
|
-
@
|
205
|
+
@hook.stubs(:issues?).returns(true)
|
196
206
|
|
197
207
|
@config.reponame = repo = 'some/repo'
|
198
208
|
|
199
209
|
issues = Array.new(3) { |i| Issue.new(i*2 + 2) }
|
200
|
-
@
|
210
|
+
@hook.stubs(:failures).returns(issues)
|
201
211
|
|
202
212
|
sha = 'decafbad'
|
203
213
|
@checkout.stubs(:sha).returns(sha)
|
@@ -208,29 +218,29 @@ class BoxenPostflightGithubIssueTest < Boxen::Test
|
|
208
218
|
api.expects(:close_issue).with(repo, issue.number)
|
209
219
|
end
|
210
220
|
|
211
|
-
@
|
221
|
+
@hook.close_failures
|
212
222
|
end
|
213
223
|
|
214
224
|
def test_close_failures_no_issues
|
215
|
-
@
|
225
|
+
@hook.stubs(:issues?).returns(false)
|
216
226
|
|
217
|
-
@
|
227
|
+
@hook.expects(:failures).never
|
218
228
|
|
219
229
|
@config.api = api = mock('api')
|
220
230
|
api.expects(:add_comment).never
|
221
231
|
api.expects(:close_issue).never
|
222
232
|
|
223
|
-
@
|
233
|
+
@hook.close_failures
|
224
234
|
end
|
225
235
|
|
226
236
|
def test_failures
|
227
|
-
@
|
237
|
+
@hook.stubs(:issues?).returns(true)
|
228
238
|
|
229
239
|
@config.reponame = repo = 'some/repo'
|
230
240
|
@config.login = user = 'hapless'
|
231
241
|
|
232
|
-
@
|
233
|
-
@
|
242
|
+
@hook.failure_label = fail_label = 'ouch'
|
243
|
+
@hook.ongoing_label = goon_label = 'goon'
|
234
244
|
|
235
245
|
fail_l = Label.new(fail_label)
|
236
246
|
goon_l = Label.new(goon_label)
|
@@ -247,16 +257,16 @@ class BoxenPostflightGithubIssueTest < Boxen::Test
|
|
247
257
|
@config.api = api = mock('api')
|
248
258
|
api.expects(:list_issues).with(repo, :state => 'open', :labels => fail_label, :creator => user).returns(issues)
|
249
259
|
|
250
|
-
assert_equal issues.values_at(0,1,3), @
|
260
|
+
assert_equal issues.values_at(0,1,3), @hook.failures
|
251
261
|
end
|
252
262
|
|
253
263
|
def test_failures_no_issues
|
254
|
-
@
|
264
|
+
@hook.stubs(:issues?).returns(false)
|
255
265
|
|
256
266
|
@config.api = api = mock('api')
|
257
267
|
api.expects(:list_issues).never
|
258
268
|
|
259
|
-
assert_equal [], @
|
269
|
+
assert_equal [], @hook.failures
|
260
270
|
end
|
261
271
|
|
262
272
|
RepoInfo = Struct.new(:has_issues)
|
@@ -267,18 +277,18 @@ class BoxenPostflightGithubIssueTest < Boxen::Test
|
|
267
277
|
|
268
278
|
@config.api = api = mock('api')
|
269
279
|
api.stubs(:repository).with(repo).returns(repo_info)
|
270
|
-
assert @
|
280
|
+
assert @hook.issues?
|
271
281
|
|
272
282
|
repo_info = RepoInfo.new(false)
|
273
283
|
api.stubs(:repository).with(repo).returns(repo_info)
|
274
|
-
refute @
|
284
|
+
refute @hook.issues?
|
275
285
|
|
276
286
|
@config.stubs(:reponame) # to ensure the returned value is nil
|
277
287
|
api.stubs(:repository).returns(RepoInfo.new(true))
|
278
|
-
refute @
|
288
|
+
refute @hook.issues?
|
279
289
|
|
280
290
|
@config.stubs(:reponame).returns('boxen/our-boxen') # our main public repo
|
281
291
|
api.stubs(:repository).returns(RepoInfo.new(true))
|
282
|
-
refute @
|
292
|
+
refute @hook.issues?
|
283
293
|
end
|
284
294
|
end
|