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
@@ -1,18 +1,17 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require 'boxen/postflight/web_hook'
|
1
|
+
require "boxen/test"
|
2
|
+
require "boxen/hook/web"
|
4
3
|
|
5
4
|
class Boxen::Config
|
6
5
|
attr_writer :api
|
7
6
|
end
|
8
7
|
|
9
|
-
class
|
8
|
+
class BoxenHookWebTest < Boxen::Test
|
10
9
|
def setup
|
11
10
|
@config = Boxen::Config.new
|
12
11
|
@checkout = Boxen::Checkout.new(@config)
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@hook.checkout
|
12
|
+
@puppet = mock 'puppeteer'
|
13
|
+
@result = stub 'result', :success? => true
|
14
|
+
@hook = Boxen::Hook::Web.new @config, @checkout, @puppet, @result
|
16
15
|
end
|
17
16
|
|
18
17
|
def test_enabled
|
@@ -30,18 +29,18 @@ class BoxenPostflightWebHookTest < Boxen::Test
|
|
30
29
|
ENV['BOXEN_WEB_HOOK_URL'] = original
|
31
30
|
end
|
32
31
|
|
33
|
-
def
|
32
|
+
def test_perform
|
34
33
|
@hook.stubs(:enabled?).returns(false)
|
35
|
-
|
34
|
+
refute @hook.perform?
|
36
35
|
|
37
36
|
@hook.stubs(:enabled?).returns(true)
|
38
|
-
|
37
|
+
assert @hook.perform?
|
39
38
|
end
|
40
39
|
|
41
40
|
def test_run
|
42
41
|
@config.stubs(:user).returns('fred')
|
43
42
|
@checkout.stubs(:sha).returns('87dbag3')
|
44
|
-
@
|
43
|
+
@result.stubs(:success?).returns(false)
|
45
44
|
now = Time.now
|
46
45
|
Time.stubs(:now).returns(now)
|
47
46
|
|
@@ -56,4 +55,4 @@ class BoxenPostflightWebHookTest < Boxen::Test
|
|
56
55
|
|
57
56
|
@hook.run
|
58
57
|
end
|
59
|
-
end
|
58
|
+
end
|
@@ -3,7 +3,7 @@ require "boxen/postflight"
|
|
3
3
|
|
4
4
|
class BoxenPostflightActiveTest < Boxen::Test
|
5
5
|
def setup
|
6
|
-
@check = Boxen::Postflight::Active.new :config
|
6
|
+
@check = Boxen::Postflight::Active.new :config
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_ok?
|
@@ -18,9 +18,9 @@ class BoxenPostflightActiveTest < Boxen::Test
|
|
18
18
|
|
19
19
|
def test_run
|
20
20
|
config = stub :envfile => "foo"
|
21
|
-
@check = Boxen::Postflight::Active.new config
|
21
|
+
@check = Boxen::Postflight::Active.new config
|
22
22
|
|
23
|
-
|
23
|
+
stdout, stderr = capture_io do
|
24
24
|
@check.run
|
25
25
|
end
|
26
26
|
|
File without changes
|
@@ -0,0 +1,177 @@
|
|
1
|
+
require 'boxen/test'
|
2
|
+
require 'boxen/config'
|
3
|
+
require 'boxen/preflight/creds'
|
4
|
+
|
5
|
+
class BoxenPreflightCredsTest < Boxen::Test
|
6
|
+
# Make a struct to use for stubbing out authorization objects.
|
7
|
+
Struct.new("Authorization", :id, :note, :fingerprint, :token)
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@config = Boxen::Config.new do |c|
|
11
|
+
c.user = 'mojombo'
|
12
|
+
c.token = 'sekr3t!'
|
13
|
+
end
|
14
|
+
ENV.delete("BOXEN_GITHUB_LOGIN")
|
15
|
+
ENV.delete("BOXEN_GITHUB_PASSWORD")
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_basic
|
19
|
+
preflight = Boxen::Preflight::Creds.new @config
|
20
|
+
|
21
|
+
error = Octokit::Unauthorized.new
|
22
|
+
@config.api.stubs(:user).raises(error)
|
23
|
+
|
24
|
+
refute preflight.ok?
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_basic_with_otp_challenge
|
28
|
+
preflight = Boxen::Preflight::Creds.new @config
|
29
|
+
|
30
|
+
blank_opt = {:headers => {}}
|
31
|
+
good_otp = {:headers => {"X-GitHub-OTP" => "123456"}}
|
32
|
+
|
33
|
+
error = Octokit::OneTimePasswordRequired.new
|
34
|
+
error.stubs(:message).returns("OTP")
|
35
|
+
|
36
|
+
preflight.tmp_api.expects(:authorizations).with(blank_opt).raises(error)
|
37
|
+
preflight.tmp_api.expects(:authorizations).with(good_otp).returns([])
|
38
|
+
preflight.tmp_api.expects(:create_authorization).raises(error)
|
39
|
+
|
40
|
+
preflight.expects(:warn)
|
41
|
+
HighLine.any_instance.expects(:ask).returns("123456")
|
42
|
+
|
43
|
+
preflight.get_tokens
|
44
|
+
assert_equal "123456", preflight.otp
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_fetch_login_and_password_when_nothing_is_given_in_env
|
48
|
+
# fetches login and password by asking
|
49
|
+
preflight = Boxen::Preflight::Creds.new @config
|
50
|
+
HighLine.any_instance.expects(:ask).with("GitHub login: ").returns "l"
|
51
|
+
HighLine.any_instance.expects(:ask).with("GitHub password: ").returns "p"
|
52
|
+
preflight.send(:fetch_login_and_password)
|
53
|
+
|
54
|
+
assert_equal "l", @config.login
|
55
|
+
assert_equal "p", preflight.instance_variable_get(:@password)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_fetch_password_when_login_is_given_in_env
|
59
|
+
# fetches only password by asking
|
60
|
+
ENV["BOXEN_GITHUB_LOGIN"] = "l"
|
61
|
+
preflight = Boxen::Preflight::Creds.new @config
|
62
|
+
preflight.expects(:warn)
|
63
|
+
HighLine.any_instance.expects(:ask).with("GitHub login: ").never
|
64
|
+
HighLine.any_instance.expects(:ask).with("GitHub password: ").returns "p"
|
65
|
+
preflight.send(:fetch_login_and_password)
|
66
|
+
|
67
|
+
assert_equal "l", @config.login
|
68
|
+
assert_equal "p", preflight.instance_variable_get(:@password)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_fetch_login_when_password_is_given_in_env
|
72
|
+
# fetches only login by asking
|
73
|
+
ENV["BOXEN_GITHUB_PASSWORD"] = "p"
|
74
|
+
preflight = Boxen::Preflight::Creds.new @config
|
75
|
+
preflight.expects(:warn)
|
76
|
+
HighLine.any_instance.expects(:ask).with("GitHub login: ").returns "l"
|
77
|
+
HighLine.any_instance.expects(:ask).with("GitHub password: ").never
|
78
|
+
preflight.send(:fetch_login_and_password)
|
79
|
+
|
80
|
+
assert_equal "l", @config.login
|
81
|
+
assert_equal "p", preflight.instance_variable_get(:@password)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_run_with_existing_token
|
85
|
+
preflight = Boxen::Preflight::Creds.new @config
|
86
|
+
note = "App1"
|
87
|
+
fingerprint = "Fingerprint1"
|
88
|
+
existing_token = Struct::Authorization.new(1, note, fingerprint, "Token1")
|
89
|
+
|
90
|
+
preflight.stubs(:fetch_login_and_password).returns("")
|
91
|
+
preflight.stubs(:get_tokens).returns([existing_token])
|
92
|
+
preflight.stubs(:note).returns(note)
|
93
|
+
preflight.stubs(:fingerprint).returns(fingerprint)
|
94
|
+
preflight.stubs(:ok?).returns(true)
|
95
|
+
preflight.tmp_api.expects(:delete_authorization).with(existing_token.id, :headers => {})
|
96
|
+
preflight.tmp_api.expects(:create_authorization).with(
|
97
|
+
:note => note,
|
98
|
+
:fingerprint => fingerprint,
|
99
|
+
:scopes => %w(repo user),
|
100
|
+
:headers => {}
|
101
|
+
).returns(existing_token)
|
102
|
+
|
103
|
+
preflight.run
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_run_with_no_existing_token
|
107
|
+
preflight = Boxen::Preflight::Creds.new @config
|
108
|
+
note = "App1"
|
109
|
+
fingerprint = "Fingerprint1"
|
110
|
+
new_token = Struct::Authorization.new(1, note, fingerprint, "Token1")
|
111
|
+
|
112
|
+
preflight.stubs(:fetch_login_and_password).returns("")
|
113
|
+
preflight.stubs(:get_tokens).returns([])
|
114
|
+
preflight.stubs(:note).returns(note)
|
115
|
+
preflight.stubs(:fingerprint).returns(fingerprint)
|
116
|
+
preflight.stubs(:ok?).returns(true)
|
117
|
+
preflight.tmp_api.expects(:delete_authorization).never
|
118
|
+
preflight.tmp_api.expects(:create_authorization).with(
|
119
|
+
:note => note,
|
120
|
+
:fingerprint => fingerprint,
|
121
|
+
:scopes => %w(repo user),
|
122
|
+
:headers => {}
|
123
|
+
).returns(new_token)
|
124
|
+
|
125
|
+
preflight.run
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_run_does_not_delete_unrelated_tokens
|
129
|
+
preflight = Boxen::Preflight::Creds.new @config
|
130
|
+
note = "App1"
|
131
|
+
fingerprint = "Fingerprint1"
|
132
|
+
new_token = Struct::Authorization.new(1, note, fingerprint, "Token1")
|
133
|
+
unrelated_token = Struct::Authorization.new(2, "App2", fingerprint, "Token2")
|
134
|
+
unrelated_token_with_fingerprint = Struct::Authorization.new(3, "App3", "Fingerprint3", "Token3")
|
135
|
+
|
136
|
+
preflight.stubs(:fetch_login_and_password).returns("")
|
137
|
+
preflight.stubs(:get_tokens).returns(
|
138
|
+
[unrelated_token, unrelated_token_with_fingerprint]
|
139
|
+
)
|
140
|
+
preflight.stubs(:note).returns(note)
|
141
|
+
preflight.stubs(:fingerprint).returns(fingerprint)
|
142
|
+
preflight.stubs(:ok?).returns(true)
|
143
|
+
preflight.tmp_api.expects(:delete_authorization).never
|
144
|
+
preflight.tmp_api.expects(:create_authorization).with(
|
145
|
+
:note => note,
|
146
|
+
:fingerprint => fingerprint,
|
147
|
+
:scopes => %w(repo user),
|
148
|
+
:headers => {}
|
149
|
+
).returns(new_token)
|
150
|
+
|
151
|
+
preflight.run
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_run_does_delete_legacy_token
|
155
|
+
preflight = Boxen::Preflight::Creds.new @config
|
156
|
+
note = "App1"
|
157
|
+
fingerprint = "Fingerprint1"
|
158
|
+
existing_token = Struct::Authorization.new(1, note, fingerprint, "Token1")
|
159
|
+
legacy_token = Struct::Authorization.new(2, "Boxen", nil, "Token2")
|
160
|
+
|
161
|
+
preflight.stubs(:fetch_login_and_password).returns("")
|
162
|
+
preflight.stubs(:get_tokens).returns([existing_token, legacy_token])
|
163
|
+
preflight.stubs(:note).returns(note)
|
164
|
+
preflight.stubs(:fingerprint).returns(fingerprint)
|
165
|
+
preflight.stubs(:ok?).returns(true)
|
166
|
+
preflight.tmp_api.expects(:delete_authorization).with(2, :headers => {})
|
167
|
+
preflight.tmp_api.expects(:delete_authorization).with(1, :headers => {})
|
168
|
+
preflight.tmp_api.expects(:create_authorization).with(
|
169
|
+
:note => note,
|
170
|
+
:fingerprint => fingerprint,
|
171
|
+
:scopes => %w(repo user),
|
172
|
+
:headers => {}
|
173
|
+
).returns(existing_token)
|
174
|
+
|
175
|
+
preflight.run
|
176
|
+
end
|
177
|
+
end
|
data/test/{preflight/boxen_preflight_etc_my_cnf_test.rb → boxen_preflight_etc_my_cnf_test.rb}
RENAMED
@@ -3,7 +3,7 @@ require 'boxen/preflight/etc_my_cnf'
|
|
3
3
|
|
4
4
|
class BoxenPreflightEtcMyCnfTest < Boxen::Test
|
5
5
|
def test_file_check
|
6
|
-
preflight = Boxen::Preflight::EtcMyCnf.new(mock('config')
|
6
|
+
preflight = Boxen::Preflight::EtcMyCnf.new(mock('config'))
|
7
7
|
File.expects(:file?).with("/etc/my.cnf").returns(false)
|
8
8
|
assert preflight.ok?
|
9
9
|
end
|
@@ -3,7 +3,7 @@ require 'boxen/preflight/rvm'
|
|
3
3
|
|
4
4
|
class BoxenPreflightRVMTest < Boxen::Test
|
5
5
|
def test_directory_check
|
6
|
-
preflight = Boxen::Preflight::RVM.new(mock('config')
|
6
|
+
preflight = Boxen::Preflight::RVM.new(mock('config'))
|
7
7
|
File.expects(:exist?).with("#{ENV['HOME']}/.rvm").returns(false)
|
8
8
|
assert preflight.ok?
|
9
9
|
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require "boxen/test"
|
2
|
+
require "boxen/puppeteer"
|
3
|
+
|
4
|
+
class BoxenPuppeteerTest < Boxen::Test
|
5
|
+
def test_initialize
|
6
|
+
puppet = Boxen::Puppeteer.new :config
|
7
|
+
assert_equal :config, puppet.config
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_flags
|
11
|
+
config = stub do
|
12
|
+
stubs(:homedir).returns "homedir"
|
13
|
+
stubs(:logfile).returns "logfile"
|
14
|
+
stubs(:profile?).returns true
|
15
|
+
stubs(:future_parser?).returns true
|
16
|
+
stubs(:puppetdir).returns "puppetdir"
|
17
|
+
stubs(:repodir).returns "repodir"
|
18
|
+
stubs(:debug?).returns true
|
19
|
+
stubs(:pretend?).returns true
|
20
|
+
stubs(:report?).returns false
|
21
|
+
stubs(:graph?).returns false
|
22
|
+
stubs(:color?).returns false
|
23
|
+
end
|
24
|
+
|
25
|
+
puppet = Boxen::Puppeteer.new config
|
26
|
+
flags = puppet.flags
|
27
|
+
|
28
|
+
assert_flag "--debug", flags
|
29
|
+
assert_flag "--detailed-exitcodes", flags
|
30
|
+
assert_flag "--evaltrace", flags
|
31
|
+
assert_flag "--no-report", flags
|
32
|
+
assert_flag "--noop", flags
|
33
|
+
assert_flag "--summarize", flags
|
34
|
+
assert_flag "--color=false", flags
|
35
|
+
assert_flag "--parser=future", flags
|
36
|
+
|
37
|
+
assert_flag_value "--confdir", :anything, flags
|
38
|
+
assert_flag_value "--group", "admin", flags
|
39
|
+
assert_flag_value "--vardir", :anything, flags
|
40
|
+
assert_flag_value "--libdir", :anything, flags
|
41
|
+
assert_flag_value "--manifestdir", :anything, flags
|
42
|
+
assert_flag_value "--modulepath", :anything, flags
|
43
|
+
|
44
|
+
assert_flag_value "--hiera_config", "/dev/null", flags
|
45
|
+
|
46
|
+
assert_flag_value "--logdest", "logfile", flags
|
47
|
+
assert_flag_value "--logdest", "console", flags
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_run
|
51
|
+
config = stub do
|
52
|
+
stubs(:debug?).returns false
|
53
|
+
stubs(:homedir).returns "homedir"
|
54
|
+
stubs(:logfile).returns "logfile"
|
55
|
+
stubs(:pretend?).returns false
|
56
|
+
stubs(:profile?).returns false
|
57
|
+
stubs(:future_parser?).returns false
|
58
|
+
stubs(:report?).returns false
|
59
|
+
stubs(:graph?).returns false
|
60
|
+
stubs(:puppetdir).returns "puppetdir"
|
61
|
+
stubs(:repodir).returns "test/fixtures/repo"
|
62
|
+
stubs(:color?).returns true
|
63
|
+
end
|
64
|
+
|
65
|
+
puppet = Boxen::Puppeteer.new config
|
66
|
+
|
67
|
+
FileUtils.expects(:rm_f).with config.logfile
|
68
|
+
FileUtils.expects(:touch).with config.logfile
|
69
|
+
FileUtils.expects(:mkdir_p).with File.dirname(config.logfile)
|
70
|
+
FileUtils.expects(:mkdir_p).with config.puppetdir
|
71
|
+
Boxen::Util.expects(:sudo).with *puppet.command
|
72
|
+
|
73
|
+
puppet.run
|
74
|
+
end
|
75
|
+
|
76
|
+
def assert_flag(flag, flags)
|
77
|
+
assert flags.include?(flag), "Flags must include #{flag}."
|
78
|
+
end
|
79
|
+
|
80
|
+
def assert_flag_value(flag, value, flags)
|
81
|
+
pair = [flag, value]
|
82
|
+
|
83
|
+
found = (0..flags.size).detect do |i|
|
84
|
+
candidate = flags[i, pair.size]
|
85
|
+
value == :anything ? candidate.size == pair.size : candidate == pair
|
86
|
+
end
|
87
|
+
|
88
|
+
assert found, "Flags must include #{flag} #{value}."
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_status
|
92
|
+
status = Boxen::Puppeteer::Status.new(0)
|
93
|
+
assert status.success?
|
94
|
+
|
95
|
+
status = Boxen::Puppeteer::Status.new(2)
|
96
|
+
assert status.success?
|
97
|
+
|
98
|
+
status = Boxen::Puppeteer::Status.new(1)
|
99
|
+
refute status.success?
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,171 @@
|
|
1
|
+
require "boxen/test"
|
2
|
+
require "boxen/runner"
|
3
|
+
|
4
|
+
class BoxenRunnerTest < Boxen::Test
|
5
|
+
def setup
|
6
|
+
@config = Boxen::Config.new
|
7
|
+
@flags = Boxen::Flags.new
|
8
|
+
@runner = Boxen::Runner.new(@config, @flags)
|
9
|
+
|
10
|
+
$stdout.stubs(:puts).returns(true)
|
11
|
+
$stdout.stubs(:write).returns(true)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_initialize
|
15
|
+
config = Boxen::Config.new
|
16
|
+
flags = Boxen::Flags.new
|
17
|
+
|
18
|
+
runner = Boxen::Runner.new(config, flags)
|
19
|
+
|
20
|
+
assert_equal config, runner.config
|
21
|
+
assert_equal flags, runner.flags
|
22
|
+
assert_equal config, runner.puppet.config
|
23
|
+
end
|
24
|
+
|
25
|
+
HookYes = Struct.new(:config, :checkout, :puppet, :result)
|
26
|
+
HookNo = Struct.new(:config, :checkout, :puppet, :result)
|
27
|
+
def test_report
|
28
|
+
runner = Boxen::Runner.new(@config, @flags)
|
29
|
+
runner.stubs(:hooks).returns([HookYes, HookNo])
|
30
|
+
|
31
|
+
hook_yes = stub('HookYes')
|
32
|
+
hook_no = stub('HookNo')
|
33
|
+
|
34
|
+
HookYes.stubs(:new).returns(hook_yes)
|
35
|
+
HookNo.stubs(:new).returns(hook_no)
|
36
|
+
|
37
|
+
hook_yes.expects(:run).once
|
38
|
+
hook_no.expects(:run).once
|
39
|
+
|
40
|
+
runner.report(stub('result'))
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_disable_service
|
44
|
+
config = Boxen::Config.new
|
45
|
+
flags = Boxen::Flags.new('--disable-service', 'test')
|
46
|
+
runner = Boxen::Runner.new config, flags
|
47
|
+
|
48
|
+
service = mock('service', :disable => true)
|
49
|
+
Boxen::Service.stubs(:new).returns(service)
|
50
|
+
|
51
|
+
assert_raises(SystemExit) do
|
52
|
+
runner.process
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_enable_service
|
57
|
+
config = Boxen::Config.new
|
58
|
+
flags = Boxen::Flags.new('--enable-service', 'test')
|
59
|
+
runner = Boxen::Runner.new config, flags
|
60
|
+
|
61
|
+
service = mock('service', :enable => true)
|
62
|
+
Boxen::Service.stubs(:new).returns(service)
|
63
|
+
|
64
|
+
assert_raises(SystemExit) do
|
65
|
+
runner.process
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_restart_service
|
70
|
+
config = Boxen::Config.new
|
71
|
+
flags = Boxen::Flags.new('--restart-service', 'test')
|
72
|
+
runner = Boxen::Runner.new config, flags
|
73
|
+
|
74
|
+
service = mock('service')
|
75
|
+
service.expects(:disable).once
|
76
|
+
service.expects(:enable).once
|
77
|
+
|
78
|
+
Boxen::Service.stubs(:new).returns(service)
|
79
|
+
|
80
|
+
assert_raises(SystemExit) do
|
81
|
+
runner.process
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_disable_services
|
86
|
+
config = Boxen::Config.new
|
87
|
+
flags = Boxen::Flags.new('--disable-services')
|
88
|
+
runner = Boxen::Runner.new config, flags
|
89
|
+
|
90
|
+
services = Array.new(3) { mock('service', :disable => true) }
|
91
|
+
Boxen::Service.stubs(:list).returns(services)
|
92
|
+
|
93
|
+
assert_raises(SystemExit) do
|
94
|
+
runner.process
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_enable_services
|
99
|
+
config = Boxen::Config.new
|
100
|
+
flags = Boxen::Flags.new('--enable-services')
|
101
|
+
runner = Boxen::Runner.new config, flags
|
102
|
+
|
103
|
+
services = Array.new(3) { mock('service', :enable => true) }
|
104
|
+
Boxen::Service.stubs(:list).returns(services)
|
105
|
+
|
106
|
+
assert_raises(SystemExit) do
|
107
|
+
runner.process
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_restart_services
|
112
|
+
config = Boxen::Config.new
|
113
|
+
flags = Boxen::Flags.new('--restart-services')
|
114
|
+
runner = Boxen::Runner.new config, flags
|
115
|
+
|
116
|
+
services = Array.new(3) { mock('service') }
|
117
|
+
services.each do |service|
|
118
|
+
service.expects(:disable).once
|
119
|
+
service.expects(:enable).once
|
120
|
+
end
|
121
|
+
Boxen::Service.stubs(:list_enabled).returns(services)
|
122
|
+
|
123
|
+
assert_raises(SystemExit) do
|
124
|
+
runner.process
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_list_services
|
129
|
+
config = Boxen::Config.new
|
130
|
+
flags = Boxen::Flags.new('--list-services')
|
131
|
+
runner = Boxen::Runner.new config, flags
|
132
|
+
|
133
|
+
Boxen::Service.expects(:list).returns(%w[a list of services])
|
134
|
+
|
135
|
+
assert_raises(SystemExit) do
|
136
|
+
runner.process
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_specify_project
|
141
|
+
skip "busted and probably due to be replaced if @jbarnette can fix it"
|
142
|
+
fact = 'cli_boxen_projects'
|
143
|
+
refute Facter.value(fact)
|
144
|
+
|
145
|
+
project = 'some_project'
|
146
|
+
flags = Boxen::Flags.new(project)
|
147
|
+
|
148
|
+
runner = Boxen::Runner.new(@config, flags)
|
149
|
+
runner.puppet.expects(:run).with().returns(true)
|
150
|
+
runner.process
|
151
|
+
assert_equal project, Facter.value(fact)
|
152
|
+
|
153
|
+
|
154
|
+
project = 'other_project'
|
155
|
+
flags = Boxen::Flags.new('--debug', project)
|
156
|
+
|
157
|
+
runner = Boxen::Runner.new(@config, flags)
|
158
|
+
runner.puppet.expects(:run).with().returns(true)
|
159
|
+
runner.process
|
160
|
+
assert_equal project, Facter.value(fact)
|
161
|
+
|
162
|
+
|
163
|
+
projects = %w[my cool projects]
|
164
|
+
flags = Boxen::Flags.new('--noop', *projects)
|
165
|
+
|
166
|
+
runner = Boxen::Runner.new(@config, flags)
|
167
|
+
runner.puppet.expects(:run).with().returns(true)
|
168
|
+
runner.process
|
169
|
+
assert_equal projects.join(','), Facter.value(fact)
|
170
|
+
end
|
171
|
+
end
|