boxen 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ module Boxen
2
+ module Util
3
+
4
+ # Is Boxen active?
5
+
6
+ def self.active?
7
+ ENV.include? "BOXEN_HOME"
8
+ end
9
+
10
+
11
+ # Run `args` as a system command with sudo if necessary.
12
+
13
+ def self.sudo *args
14
+ system "sudo", "-p", "Password for sudo: ", *args
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ #!/bin/sh
2
+ # Make sure local dependencies are satisfied.
3
+
4
+ cd "$(dirname $0)"/..
5
+
6
+ rm -f .bundle/config
7
+
8
+ (bundle check --path .bundle > /dev/null 2>&1 && [ -d bin ]) ||
9
+ bundle install --binstubs bin --path .bundle
@@ -0,0 +1,10 @@
1
+ #!/bin/sh
2
+ # Run the unit tests.
3
+
4
+ cd "$(dirname $0)"/..
5
+
6
+ script/bootstrap &&
7
+ ruby -rubygems -Ilib:test \
8
+ -e 'require "bundler/setup"' \
9
+ -e 'tests = ARGV.empty? ? Dir["test/**/*_test.rb"] : ARGV' \
10
+ -e 'tests.each { |f| load f }' "$@"
@@ -0,0 +1,7 @@
1
+ require "minitest/autorun"
2
+ require "mocha"
3
+
4
+ module Boxen
5
+ class Test < MiniTest::Unit::TestCase
6
+ end
7
+ end
@@ -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
@@ -0,0 +1,15 @@
1
+ require "boxen/test"
2
+ require "boxen/cli"
3
+
4
+ class BoxenCLITest < Boxen::Test
5
+ def test_initialize
6
+ config = mock
7
+ flags = mock
8
+
9
+ cli = Boxen::CLI.new config, flags
10
+
11
+ assert_equal config, cli.config
12
+ assert_equal flags, cli.flags
13
+ assert_equal config, cli.puppet.config
14
+ end
15
+ end
@@ -0,0 +1,157 @@
1
+ require "boxen/test"
2
+ require "boxen/config"
3
+
4
+ class BoxenConfigTest < Boxen::Test
5
+ def setup
6
+ @config = Boxen::Config.new
7
+ end
8
+
9
+ def test_debug?
10
+ refute @config.debug?
11
+
12
+ @config.debug = true
13
+ assert @config.debug?
14
+ end
15
+
16
+ def test_email
17
+ assert_nil @config.email
18
+
19
+ @config.email = "foo"
20
+ assert_equal "foo", @config.email
21
+ end
22
+
23
+ def test_fde?
24
+ assert @config.fde?
25
+
26
+ @config.fde = false
27
+ refute @config.fde?
28
+ end
29
+
30
+ def test_fde_env_var
31
+ ENV.expects(:[]).with("BOXEN_NO_FDE").returns "1"
32
+ refute @config.fde?
33
+ end
34
+
35
+ def test_homedir
36
+ assert_equal "/opt/boxen", @config.homedir
37
+
38
+ @config.homedir = "foo"
39
+ assert_equal "foo", @config.homedir
40
+ end
41
+
42
+ def test_homedir_env_var_boxen_home
43
+ ENV.expects(:[]).with("BOXEN_HOME").returns "foo"
44
+ assert_equal "foo", @config.homedir
45
+ end
46
+
47
+ def test_initialize
48
+ config = Boxen::Config.new do |c|
49
+ c.homedir = "foo"
50
+ end
51
+
52
+ assert_equal "foo", config.homedir
53
+ end
54
+
55
+ def test_logfile
56
+ assert_equal "#{@config.repodir}/log/boxen.log", @config.logfile
57
+
58
+ @config.logfile = "foo"
59
+ assert_equal "foo", @config.logfile
60
+ end
61
+
62
+ def test_logfile_env_var
63
+ ENV.expects(:[]).with("BOXEN_LOG_FILE").returns "foo"
64
+ assert_equal "foo", @config.logfile
65
+ end
66
+
67
+ def test_login
68
+ assert_nil @config.login
69
+
70
+ @config.login = "foo"
71
+ assert_equal "foo", @config.login
72
+ end
73
+
74
+ def test_name
75
+ assert_nil @config.name
76
+
77
+ @config.name = "foo"
78
+ assert_equal "foo", @config.name
79
+ end
80
+
81
+ def test_password
82
+ assert_nil @config.password
83
+
84
+ @config.password = "foo"
85
+ assert_equal "foo", @config.password
86
+ end
87
+
88
+ def test_pretend?
89
+ refute @config.pretend?
90
+
91
+ @config.pretend = true
92
+ assert @config.pretend?
93
+ end
94
+
95
+ def test_profile?
96
+ refute @config.profile?
97
+
98
+ @config.profile = true
99
+ assert @config.profile?
100
+ end
101
+
102
+ def test_projects
103
+ @config.repodir = "test/fixtures/repo"
104
+
105
+ files = Dir["#{@config.repodir}/modules/projects/manifests/*.pp"]
106
+ assert_equal files.size, @config.projects.size
107
+ end
108
+
109
+ def test_puppetdir
110
+ assert_equal "/tmp/boxen/puppet", @config.puppetdir
111
+ end
112
+
113
+ def test_puppetdir_env_var
114
+ ENV.expects(:[]).with("BOXEN_PUPPET_DIR").returns "foo"
115
+ assert_equal "foo", @config.puppetdir
116
+ end
117
+
118
+ def test_repodir
119
+ assert_equal Dir.pwd, @config.repodir
120
+
121
+ @config.repodir = "foo"
122
+ assert_equal "foo", @config.repodir
123
+ end
124
+
125
+ def test_repodir_env_var
126
+ ENV.expects(:[]).with("BOXEN_REPO_DIR").returns "foo"
127
+ assert_equal "foo", @config.repodir
128
+ end
129
+
130
+ def test_srcdir
131
+ @config.expects(:user).returns "foo"
132
+ assert_equal "/Users/foo/src", @config.srcdir
133
+
134
+ @config.srcdir = "elsewhere"
135
+ assert_equal "elsewhere", @config.srcdir
136
+ end
137
+
138
+ def test_stealth?
139
+ refute @config.stealth?
140
+
141
+ @config.stealth = true
142
+ assert @config.stealth?
143
+ end
144
+
145
+ def test_stealth_env_var
146
+ ENV.expects(:[]).with("BOXEN_NO_ISSUE").returns "1"
147
+ assert @config.stealth?
148
+ end
149
+
150
+ def test_user
151
+ ENV.expects(:[]).with("USER").returns "foo"
152
+ assert_equal "foo", @config.user
153
+
154
+ @config.user = "bar"
155
+ assert_equal "bar", @config.user
156
+ end
157
+ end
@@ -0,0 +1,182 @@
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(:password=).with "password"
16
+ expects(:pretend=).with true
17
+ expects(:profile=).with true
18
+ expects(:srcdir=).with "srcdir"
19
+ expects(:stealth=).with true
20
+ expects(:user=).with "user"
21
+ end
22
+
23
+ # Do our best to frob every switch.
24
+
25
+ flags = Boxen::Flags.new "--debug", "--help", "--login", "login",
26
+ "--no-fde", "--no-pull", "--no-issue", "--noop", "--password", "password",
27
+ "--pretend", "--profile", "--projects", "--user", "user", "--homedir",
28
+ "homedir", "--srcdir", "srcdir", "--logfile", "logfile"
29
+
30
+ assert_same config, flags.apply(config)
31
+ end
32
+
33
+ def test_args
34
+ config = flags "--debug", "foo"
35
+ assert_equal %w(foo), config.args
36
+ end
37
+
38
+ def test_debug
39
+ refute flags.debug?
40
+ assert flags("--debug").debug?
41
+ end
42
+
43
+ def test_env?
44
+ refute flags.env?
45
+ assert flags("--env").env?
46
+ end
47
+
48
+ def test_help
49
+ refute flags.help?
50
+
51
+ %w(--help -h -?).each do |flag|
52
+ assert flags(flag).help?
53
+ end
54
+ end
55
+
56
+ def test_homedir
57
+ assert_nil flags.homedir
58
+ assert_equal "foo", flags("--homedir", "foo").homedir
59
+ end
60
+
61
+ def test_initialize_bad_option
62
+ ex = assert_raises Boxen::Error do
63
+ flags "--bad-option"
64
+ end
65
+
66
+ assert_match "invalid option", ex.message
67
+ assert_match "--bad-option", ex.message
68
+ end
69
+
70
+ def test_initialize_dups
71
+ args = %w(foo)
72
+ config = flags args
73
+
74
+ assert_equal args, config.args
75
+ refute_same args, config.args
76
+ end
77
+
78
+ def test_initialize_empty
79
+ config = flags
80
+ assert_equal [], config.args
81
+ end
82
+
83
+ def test_initialize_flattens
84
+ config = flags "foo", ["bar"]
85
+ assert_equal %w(foo bar), config.args
86
+ end
87
+
88
+ def test_initialize_nils
89
+ config = flags "foo", nil, "bar"
90
+ assert_equal %w(foo bar), config.args
91
+ end
92
+
93
+ def test_initialize_strings
94
+ config = flags :foo, [:bar]
95
+ assert_equal %w(foo bar), config.args
96
+ end
97
+
98
+ def test_logfile
99
+ assert_nil flags.logfile
100
+ assert_equal "foo", flags("--logfile", "foo").logfile
101
+ end
102
+
103
+ def test_login
104
+ assert_nil flags.login
105
+ assert_equal "jbarnette", flags("--login", "jbarnette").login
106
+ end
107
+
108
+ def test_no_fde
109
+ assert flags.fde?
110
+ refute flags("--no-fde").fde?
111
+ end
112
+
113
+ def test_no_pull_is_a_noop
114
+ flags "--no-pull"
115
+ end
116
+
117
+ def test_parse
118
+ config = flags
119
+ config.parse "--debug", "foo"
120
+
121
+ assert config.debug?
122
+ assert_equal %w(foo), config.args
123
+ end
124
+
125
+ def test_password
126
+ assert_nil flags.password
127
+ assert_equal "foo", flags("--password", "foo").password
128
+ end
129
+
130
+ def test_password_missing_value
131
+ ex = assert_raises Boxen::Error do
132
+ flags "--password"
133
+ end
134
+
135
+ assert_match "missing argument", ex.message
136
+ end
137
+
138
+ def test_pretend
139
+ refute flags.pretend?
140
+ assert flags("--noop").pretend?
141
+ assert flags("--pretend").pretend?
142
+ end
143
+
144
+ def test_profile
145
+ refute flags.profile?
146
+ assert flags("--profile").profile?
147
+ end
148
+
149
+ def test_projects
150
+ refute flags.projects?
151
+ assert flags("--projects").projects?
152
+ end
153
+
154
+ def test_srcdir
155
+ assert_nil flags.srcdir
156
+ assert_equal "foo", flags("--srcdir", "foo").srcdir
157
+ end
158
+
159
+ def test_stealth
160
+ refute flags.stealth?
161
+ assert flags("--no-issue").stealth?
162
+ assert flags("--stealth").stealth?
163
+ end
164
+
165
+ def test_user
166
+ assert_equal "jbarnette", flags("--user", "jbarnette").user
167
+ end
168
+
169
+ def test_user_missing_value
170
+ ex = assert_raises Boxen::Error do
171
+ flags "--user"
172
+ end
173
+
174
+ assert_match "missing argument", ex.message
175
+ end
176
+
177
+ # Create an instance of Boxen::Flags with optional `args`.
178
+
179
+ def flags(*args)
180
+ Boxen::Flags.new *args
181
+ end
182
+ end