boxen23 3.1.3a

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 (63) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.travis.yml +6 -0
  4. data/Gemfile +2 -0
  5. data/LICENSE +20 -0
  6. data/README.md +50 -0
  7. data/boxen.gemspec +29 -0
  8. data/lib/boxen/check.rb +72 -0
  9. data/lib/boxen/checkout.rb +25 -0
  10. data/lib/boxen/cli.rb +61 -0
  11. data/lib/boxen/config.rb +345 -0
  12. data/lib/boxen/error.rb +4 -0
  13. data/lib/boxen/flags.rb +291 -0
  14. data/lib/boxen/hook.rb +47 -0
  15. data/lib/boxen/hook/github_issue.rb +120 -0
  16. data/lib/boxen/hook/web.rb +56 -0
  17. data/lib/boxen/keychain.rb +61 -0
  18. data/lib/boxen/postflight.rb +13 -0
  19. data/lib/boxen/postflight/active.rb +16 -0
  20. data/lib/boxen/postflight/env.rb +29 -0
  21. data/lib/boxen/preflight.rb +13 -0
  22. data/lib/boxen/preflight/creds.rb +149 -0
  23. data/lib/boxen/preflight/directories.rb +32 -0
  24. data/lib/boxen/preflight/etc_my_cnf.rb +12 -0
  25. data/lib/boxen/preflight/identity.rb +16 -0
  26. data/lib/boxen/preflight/os.rb +33 -0
  27. data/lib/boxen/preflight/rbenv.rb +12 -0
  28. data/lib/boxen/preflight/rvm.rb +12 -0
  29. data/lib/boxen/project.rb +20 -0
  30. data/lib/boxen/puppeteer.rb +122 -0
  31. data/lib/boxen/runner.rb +149 -0
  32. data/lib/boxen/service.rb +58 -0
  33. data/lib/boxen/util.rb +19 -0
  34. data/lib/facter/boxen.rb +34 -0
  35. data/script/Boxen +0 -0
  36. data/script/bootstrap +7 -0
  37. data/script/build-keychain-helper +6 -0
  38. data/script/release +38 -0
  39. data/script/tests +10 -0
  40. data/src/keychain-helper.c +85 -0
  41. data/test/boxen/test.rb +7 -0
  42. data/test/boxen_check_test.rb +55 -0
  43. data/test/boxen_checkout_test.rb +42 -0
  44. data/test/boxen_cli_test.rb +39 -0
  45. data/test/boxen_config_test.rb +400 -0
  46. data/test/boxen_directories_test.rb +40 -0
  47. data/test/boxen_flags_test.rb +223 -0
  48. data/test/boxen_hook_github_issue_test.rb +294 -0
  49. data/test/boxen_hook_web_test.rb +58 -0
  50. data/test/boxen_keychain_test.rb +21 -0
  51. data/test/boxen_postflight_active_test.rb +29 -0
  52. data/test/boxen_postflight_env_test.rb +6 -0
  53. data/test/boxen_preflight_creds_test.rb +177 -0
  54. data/test/boxen_preflight_etc_my_cnf_test.rb +10 -0
  55. data/test/boxen_preflight_rvm_test.rb +10 -0
  56. data/test/boxen_project_test.rb +14 -0
  57. data/test/boxen_puppeteer_test.rb +101 -0
  58. data/test/boxen_runner_test.rb +171 -0
  59. data/test/boxen_service_test.rb +39 -0
  60. data/test/boxen_util_test.rb +21 -0
  61. data/test/fixtures/repo/modules/projects/manifests/first-project.pp +0 -0
  62. data/test/fixtures/repo/modules/projects/manifests/second-project.pp +0 -0
  63. metadata +257 -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,223 @@
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(:skip_puppetfile=).with true
20
+ expects(:report=).with true
21
+ expects(:graph=).with true
22
+ expects(:srcdir=).with "srcdir"
23
+ expects(:stealth=).with true
24
+ expects(:user=).with "user"
25
+ expects(:color=).with true
26
+ end
27
+
28
+ # Do our best to frob every switch.
29
+
30
+ flags = Boxen::Flags.new "--debug", "--help", "--login", "login",
31
+ "--no-fde", "--no-pull", "--no-issue", "--noop",
32
+ "--pretend", "--profile", "--future-parser", "--skip-puppetfile", "--report", "--graph", "--projects",
33
+ "--user", "user", "--homedir", "homedir", "--srcdir", "srcdir",
34
+ "--logfile", "logfile", "--token", "token"
35
+
36
+ assert_same config, flags.apply(config)
37
+ end
38
+
39
+ def test_args
40
+ config = flags "--debug", "foo"
41
+ assert_equal %w(foo), config.args
42
+ end
43
+
44
+ def test_debug
45
+ refute flags.debug?
46
+ assert flags("--debug").debug?
47
+ end
48
+
49
+ def test_env?
50
+ refute flags.env?
51
+ assert flags("--env").env?
52
+ end
53
+
54
+ def test_help
55
+ refute flags.help?
56
+
57
+ %w(--help -h -?).each do |flag|
58
+ assert flags(flag).help?
59
+ end
60
+ end
61
+
62
+ def test_disable_services?
63
+ refute flags.disable_services?
64
+ assert flags("--disable-services").disable_services?
65
+ end
66
+
67
+ def test_enable_services?
68
+ refute flags.enable_services?
69
+ assert flags("--enable-services").enable_services?
70
+ end
71
+
72
+ def test_list_services?
73
+ refute flags.list_services?
74
+ assert flags("--list-services").list_services?
75
+ end
76
+
77
+ def test_homedir
78
+ assert_nil flags.homedir
79
+ assert_equal "foo", flags("--homedir", "foo").homedir
80
+ end
81
+
82
+ def test_initialize_bad_option
83
+ ex = assert_raises Boxen::Error do
84
+ flags "--bad-option"
85
+ end
86
+
87
+ assert_match "invalid option", ex.message
88
+ assert_match "--bad-option", ex.message
89
+ end
90
+
91
+ def test_initialize_dups
92
+ args = %w(foo)
93
+ config = flags args
94
+
95
+ assert_equal args, config.args
96
+ refute_same args, config.args
97
+ end
98
+
99
+ def test_initialize_empty
100
+ config = flags
101
+ assert_equal [], config.args
102
+ end
103
+
104
+ def test_initialize_flattens
105
+ config = flags "foo", ["bar"]
106
+ assert_equal %w(foo bar), config.args
107
+ end
108
+
109
+ def test_initialize_nils
110
+ config = flags "foo", nil, "bar"
111
+ assert_equal %w(foo bar), config.args
112
+ end
113
+
114
+ def test_initialize_strings
115
+ config = flags :foo, [:bar]
116
+ assert_equal %w(foo bar), config.args
117
+ end
118
+
119
+ def test_logfile
120
+ assert_nil flags.logfile
121
+ assert_equal "foo", flags("--logfile", "foo").logfile
122
+ end
123
+
124
+ def test_login
125
+ assert_nil flags.login
126
+ assert_equal "jbarnette", flags("--login", "jbarnette").login
127
+ end
128
+
129
+ def test_no_fde
130
+ assert flags.fde?
131
+ refute flags("--no-fde").fde?
132
+ end
133
+
134
+ def test_no_pull_is_a_noop
135
+ flags "--no-pull"
136
+ end
137
+
138
+ def test_parse
139
+ config = flags
140
+ config.parse "--debug", "foo"
141
+
142
+ assert config.debug?
143
+ assert_equal %w(foo), config.args
144
+ end
145
+
146
+ def test_token
147
+ assert_nil flags.token
148
+ assert_equal "foo", flags("--token", "foo").token
149
+ end
150
+
151
+ def test_token_missing_value
152
+ ex = assert_raises Boxen::Error do
153
+ flags "--token"
154
+ end
155
+
156
+ assert_match "missing argument", ex.message
157
+ end
158
+
159
+ def test_pretend
160
+ refute flags.pretend?
161
+ assert flags("--noop").pretend?
162
+ assert flags("--pretend").pretend?
163
+ end
164
+
165
+ def test_profile
166
+ refute flags.profile?
167
+ assert flags("--profile").profile?
168
+ end
169
+
170
+ def test_future_parser
171
+ refute flags.future_parser?
172
+ assert flags("--future-parser").future_parser?
173
+ end
174
+
175
+ def test_skip_puppetfile
176
+ refute flags.skip_puppetfile?
177
+ assert flags("--skip-puppetfile").skip_puppetfile?
178
+ end
179
+
180
+ def test_report
181
+ refute flags.report?
182
+ assert flags("--report").report?
183
+ end
184
+
185
+ def test_graph
186
+ refute flags.graph?
187
+ assert flags("--graph").graph?
188
+ end
189
+
190
+ def test_projects
191
+ refute flags.projects?
192
+ assert flags("--projects").projects?
193
+ end
194
+
195
+ def test_srcdir
196
+ assert_nil flags.srcdir
197
+ assert_equal "foo", flags("--srcdir", "foo").srcdir
198
+ end
199
+
200
+ def test_stealth
201
+ refute flags.stealth?
202
+ assert flags("--no-issue").stealth?
203
+ assert flags("--stealth").stealth?
204
+ end
205
+
206
+ def test_user
207
+ assert_equal "jbarnette", flags("--user", "jbarnette").user
208
+ end
209
+
210
+ def test_user_missing_value
211
+ ex = assert_raises Boxen::Error do
212
+ flags "--user"
213
+ end
214
+
215
+ assert_match "missing argument", ex.message
216
+ end
217
+
218
+ # Create an instance of Boxen::Flags with optional `args`.
219
+
220
+ def flags(*args)
221
+ Boxen::Flags.new *args
222
+ end
223
+ 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