taketo 0.0.10 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +14 -30
- data/README.md +4 -0
- data/Rakefile +4 -8
- data/VERSION +1 -1
- data/bin/taketo +5 -5
- data/lib/taketo/config_printer_visitor.rb +6 -22
- data/lib/taketo/config_traverser.rb +4 -33
- data/lib/taketo/config_validator.rb +1 -1
- data/lib/taketo/config_visitor.rb +15 -1
- data/lib/taketo/constructs/base_construct.rb +30 -6
- data/lib/taketo/constructs/config.rb +5 -0
- data/lib/taketo/constructs/environment.rb +6 -3
- data/lib/taketo/constructs/project.rb +3 -3
- data/lib/taketo/constructs/server.rb +3 -4
- data/lib/taketo/constructs.rb +6 -1
- data/lib/taketo/destination_resolver.rb +37 -52
- data/lib/taketo/dsl.rb +6 -3
- data/lib/taketo/printer.rb +29 -0
- data/lib/taketo/ssh_config_generator_visitor.rb +8 -22
- data/spec/acceptance/command_spec.rb +20 -0
- data/spec/acceptance/config_dsl_spec.rb +277 -0
- data/spec/acceptance/config_validation_spec.rb +109 -0
- data/spec/acceptance/connect_to_server_spec.rb +60 -0
- data/spec/acceptance/error_handling_spec.rb +31 -0
- data/spec/acceptance/generate_ssh_config_spec.rb +44 -0
- data/spec/acceptance/help_spec.rb +74 -0
- data/spec/acceptance/location_spec.rb +21 -0
- data/spec/acceptance_spec_helper.rb +71 -0
- data/spec/lib/taketo/config_traverser_spec.rb +20 -33
- data/spec/lib/taketo/config_validator_spec.rb +4 -4
- data/spec/lib/taketo/config_visitor_spec.rb +0 -4
- data/spec/lib/taketo/constructs/base_construct_spec.rb +37 -5
- data/spec/lib/taketo/constructs/environment_spec.rb +1 -1
- data/spec/lib/taketo/constructs/project_spec.rb +0 -6
- data/spec/lib/taketo/constructs/server_spec.rb +1 -3
- data/spec/lib/taketo/destination_resolver_spec.rb +21 -54
- data/spec/lib/taketo/dsl_spec.rb +46 -44
- data/spec/spec_helper.rb +1 -1
- data/spec/support/helpers/construct_spec_helper.rb +29 -0
- metadata +94 -82
- data/features/commands.feature +0 -36
- data/features/config.feature +0 -177
- data/features/config_validation.feature +0 -43
- data/features/connect_to_server.feature +0 -87
- data/features/default_server_config.feature +0 -41
- data/features/error_handling.feature +0 -29
- data/features/generate_ssh_config.feature +0 -44
- data/features/help.feature +0 -76
- data/features/step_definitions/main_steps.rb +0 -16
- data/features/support/env.rb +0 -14
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'acceptance_spec_helper'
|
2
|
+
|
3
|
+
feature "Run explicit command on remote host" do
|
4
|
+
scenario "Run explicit command on remote" do
|
5
|
+
create_config <<-CONFIG
|
6
|
+
project :slots do
|
7
|
+
environment :staging do
|
8
|
+
server do
|
9
|
+
host "1.2.3.4"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
CONFIG
|
14
|
+
|
15
|
+
run "taketo --dry-run --command 'TERM=xterm-256color bash'"
|
16
|
+
exit_status.should be_success
|
17
|
+
stdout.should == %Q{ssh -t 1.2.3.4 "RAILS_ENV=staging TERM=xterm-256color bash"}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,277 @@
|
|
1
|
+
require 'acceptance_spec_helper'
|
2
|
+
|
3
|
+
feature "Config DSL" do
|
4
|
+
scenario "Reopen config scopes" do
|
5
|
+
create_config <<-CONFIG
|
6
|
+
project :slots do
|
7
|
+
environment :staging do
|
8
|
+
server do
|
9
|
+
host "1.2.3.4"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
project :slots do
|
15
|
+
environment :staging do
|
16
|
+
server do
|
17
|
+
env :FOO => "bar"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
CONFIG
|
22
|
+
|
23
|
+
run "taketo slots:staging --dry-run"
|
24
|
+
exit_status.should be_success
|
25
|
+
stdout.should =~ %r{ssh -t 1.2.3.4 "(RAILS_ENV=staging FOO=bar|FOO=bar RAILS_ENV=staging) bash"}
|
26
|
+
end
|
27
|
+
|
28
|
+
scenario "Command" do
|
29
|
+
create_config <<-CONFIG
|
30
|
+
project :slots do
|
31
|
+
environment :staging do
|
32
|
+
server do
|
33
|
+
host "1.2.3.4"
|
34
|
+
location "/var/apps/slots"
|
35
|
+
command :console do
|
36
|
+
execute "rails c"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
CONFIG
|
42
|
+
|
43
|
+
run "taketo slots:staging --dry-run --command console"
|
44
|
+
exit_status.should be_success
|
45
|
+
stdout.should == %Q{ssh -t 1.2.3.4 "cd /var/apps/slots; RAILS_ENV=staging rails c"}
|
46
|
+
end
|
47
|
+
|
48
|
+
context "Default command" do
|
49
|
+
background { config_exists <<-CONFIG }
|
50
|
+
project :slots do
|
51
|
+
environment :staging do
|
52
|
+
server :s1 do
|
53
|
+
host "1.2.3.4"
|
54
|
+
|
55
|
+
default_command :console
|
56
|
+
|
57
|
+
command :console do
|
58
|
+
execute "rails c"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
server :s2 do
|
63
|
+
host "2.3.4.5"
|
64
|
+
|
65
|
+
default_command "tmux attach || tmux new-session"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
CONFIG
|
70
|
+
|
71
|
+
scenario "Explicit default command" do
|
72
|
+
run "taketo slots:staging:s1 --dry-run"
|
73
|
+
exit_status.should be_success
|
74
|
+
stdout.should == %q{ssh -t 1.2.3.4 "RAILS_ENV=staging rails c"}
|
75
|
+
end
|
76
|
+
|
77
|
+
scenario "Default command defined in config" do
|
78
|
+
run "taketo slots:staging:s2 --dry-run"
|
79
|
+
exit_status.should be_success
|
80
|
+
stdout.should == %q{ssh -t 2.3.4.5 "RAILS_ENV=staging tmux attach || tmux new-session"}
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
scenario "Default location on server" do
|
85
|
+
create_config <<-CONFIG
|
86
|
+
project :slots do
|
87
|
+
environment :staging do
|
88
|
+
server do
|
89
|
+
location '/var/foo'
|
90
|
+
host "1.2.3.4"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
CONFIG
|
95
|
+
|
96
|
+
run "taketo --dry-run"
|
97
|
+
exit_status.should be_success
|
98
|
+
stdout.should == %q{ssh -t 1.2.3.4 "cd /var/foo; RAILS_ENV=staging bash"}
|
99
|
+
end
|
100
|
+
|
101
|
+
context "Per-Scope default server config" do
|
102
|
+
background { config_exists <<-CONFIG }
|
103
|
+
default_server_config do
|
104
|
+
env :FOO => 'bar'
|
105
|
+
end
|
106
|
+
|
107
|
+
project :slots do
|
108
|
+
default_server_config do
|
109
|
+
location '/mnt/apps'
|
110
|
+
end
|
111
|
+
|
112
|
+
environment :staging do
|
113
|
+
server :s1 do
|
114
|
+
host "1.2.3.4"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
project :shoes do
|
120
|
+
environment :production do
|
121
|
+
server do
|
122
|
+
host "2.3.4.5"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
CONFIG
|
127
|
+
|
128
|
+
scenario "Global default server config" do
|
129
|
+
run "taketo shoes --dry-run"
|
130
|
+
exit_status.should be_success
|
131
|
+
stdout.should =~ /ssh -t 2\.3\.4\.5 "(RAILS_ENV=production FOO=bar|FOO=bar RAILS_ENV=production) bash"/
|
132
|
+
end
|
133
|
+
|
134
|
+
scenario "Project default server config" do
|
135
|
+
run "taketo slots --dry-run"
|
136
|
+
stdout.should =~ /ssh -t 1\.2\.3\.4 "cd .mnt.apps; (RAILS_ENV=staging FOO=bar|FOO=bar RAILS_ENV=staging) bash"/
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context "Shared server config" do
|
141
|
+
scenario "Simple shared server config" do
|
142
|
+
create_config <<-CONFIG
|
143
|
+
shared_server_config :sc1 do
|
144
|
+
port 9999 #can contain any server config options
|
145
|
+
end
|
146
|
+
|
147
|
+
shared_server_config :sc2 do
|
148
|
+
location "/var/qux"
|
149
|
+
end
|
150
|
+
|
151
|
+
project :slots do
|
152
|
+
environment :staging do
|
153
|
+
server(:s1) { host "1.2.3.4"; include_shared_server_config(:sc1, :sc2) }
|
154
|
+
end
|
155
|
+
end
|
156
|
+
CONFIG
|
157
|
+
|
158
|
+
run "taketo slots:staging:s1 --dry-run"
|
159
|
+
exit_status.should be_success
|
160
|
+
stdout.should == %q{ssh -t -p 9999 1.2.3.4 "cd /var/qux; RAILS_ENV=staging bash"}
|
161
|
+
end
|
162
|
+
|
163
|
+
scenario "Shared server config with arguments" do
|
164
|
+
create_config <<-CONFIG
|
165
|
+
shared_server_config :sc_args1 do |port_num|
|
166
|
+
port port_num
|
167
|
+
end
|
168
|
+
|
169
|
+
shared_server_config :sc_args2 do |projects_root_folder, project_folder|
|
170
|
+
location File.join(projects_root_folder, project_folder)
|
171
|
+
end
|
172
|
+
|
173
|
+
project :slots do
|
174
|
+
environment :staging do
|
175
|
+
server(:s1) do
|
176
|
+
host "1.2.3.4"
|
177
|
+
include_shared_server_config(:sc_args1 => 9999, :sc_args2 => ['/var', 'qux'])
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
CONFIG
|
182
|
+
|
183
|
+
run "taketo slots:staging:s1 --dry-run"
|
184
|
+
exit_status.should be_success
|
185
|
+
stdout.should == %q{ssh -t -p 9999 1.2.3.4 "cd /var/qux; RAILS_ENV=staging bash"}
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
scenario "Environment variables" do
|
190
|
+
create_config <<-CONFIG
|
191
|
+
project :slots do
|
192
|
+
environment :staging do
|
193
|
+
server do
|
194
|
+
host "1.2.3.4"
|
195
|
+
location "/var/apps/slots"
|
196
|
+
env :FOO => "the value"
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
CONFIG
|
201
|
+
|
202
|
+
run "taketo --dry-run"
|
203
|
+
exit_status.should be_success
|
204
|
+
stdout.should =~ %r{ssh -t 1.2.3.4 "cd /var/apps/slots; (RAILS_ENV=staging FOO=the\\ value|FOO=the\\ value RAILS_ENV=staging) bash"}
|
205
|
+
end
|
206
|
+
|
207
|
+
scenario "Unique server alias" do
|
208
|
+
create_config <<-CONFIG
|
209
|
+
project :slots do
|
210
|
+
environment :staging do
|
211
|
+
server :s1 do
|
212
|
+
host "1.2.3.4"
|
213
|
+
end
|
214
|
+
|
215
|
+
server :s2 do
|
216
|
+
global_alias :ss2
|
217
|
+
host "2.3.4.5"
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
CONFIG
|
222
|
+
|
223
|
+
run "taketo ss2 --dry-run"
|
224
|
+
exit_status.should be_success
|
225
|
+
stdout.should == %q{ssh -t 2.3.4.5 "RAILS_ENV=staging bash"}
|
226
|
+
end
|
227
|
+
|
228
|
+
scenario "Default destination" do
|
229
|
+
create_config <<-CONFIG
|
230
|
+
default_destination "slots:staging:s2"
|
231
|
+
project :slots do
|
232
|
+
environment :staging do
|
233
|
+
server :s1 do
|
234
|
+
host "1.2.3.4"
|
235
|
+
end
|
236
|
+
server :s2 do
|
237
|
+
host "2.3.4.5"
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
CONFIG
|
242
|
+
|
243
|
+
run "taketo --dry-run"
|
244
|
+
exit_status.should be_success
|
245
|
+
stdout.should == %Q{ssh -t 2.3.4.5 "RAILS_ENV=staging bash"}
|
246
|
+
end
|
247
|
+
|
248
|
+
scenario "ssh identity file" do
|
249
|
+
create_config <<-CONFIG
|
250
|
+
project :slots do
|
251
|
+
environment :staging do
|
252
|
+
server do
|
253
|
+
identity_file "/home/gor/.ssh/foo bar"
|
254
|
+
host "2.3.4.5"
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
CONFIG
|
259
|
+
|
260
|
+
run "taketo --dry-run"
|
261
|
+
exit_status.should be_success
|
262
|
+
stdout.should == %q{ssh -t -i /home/gor/.ssh/foo\ bar 2.3.4.5 "RAILS_ENV=staging bash"}
|
263
|
+
end
|
264
|
+
|
265
|
+
scenario "server outside project" do
|
266
|
+
create_config <<-CONFIG
|
267
|
+
server :my_server do
|
268
|
+
host "1.2.3.4"
|
269
|
+
end
|
270
|
+
CONFIG
|
271
|
+
|
272
|
+
run "taketo my_server --dry-run"
|
273
|
+
exit_status.should be_success
|
274
|
+
stdout.should == %q{ssh -t 1.2.3.4 "bash"}
|
275
|
+
end
|
276
|
+
|
277
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'acceptance_spec_helper'
|
2
|
+
|
3
|
+
feature "Config validation" do
|
4
|
+
scenario "No servers defined" do
|
5
|
+
create_config <<-CONFIG
|
6
|
+
CONFIG
|
7
|
+
|
8
|
+
run "taketo"
|
9
|
+
exit_status.should_not be_success
|
10
|
+
stderr.should include("There are no servers. Add some to your config (~/.taketo.rc.rb by default)")
|
11
|
+
end
|
12
|
+
|
13
|
+
scenario "Project has no environments" do
|
14
|
+
create_config <<-CONFIG
|
15
|
+
project :foo do
|
16
|
+
end
|
17
|
+
|
18
|
+
project :bar do
|
19
|
+
environment :baz do
|
20
|
+
server :qux do
|
21
|
+
host '1.2.3.4'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
CONFIG
|
26
|
+
|
27
|
+
run "taketo"
|
28
|
+
exit_status.should_not be_success
|
29
|
+
stderr.should include("Project foo: no environments")
|
30
|
+
end
|
31
|
+
|
32
|
+
scenario "Environment has no servers" do
|
33
|
+
create_config <<-CONFIG
|
34
|
+
project :foo do
|
35
|
+
environment :bar do
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
project :bar do
|
40
|
+
environment :baz do
|
41
|
+
server :qux do
|
42
|
+
host '1.2.3.4'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
CONFIG
|
47
|
+
|
48
|
+
run "taketo"
|
49
|
+
exit_status.should_not be_success
|
50
|
+
stderr.should include("Environment foo:bar: no servers")
|
51
|
+
end
|
52
|
+
|
53
|
+
scenario "Server has no host defined" do
|
54
|
+
create_config <<-CONFIG
|
55
|
+
project :foo do
|
56
|
+
environment :bar do
|
57
|
+
server do
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
CONFIG
|
62
|
+
|
63
|
+
run "taketo"
|
64
|
+
exit_status.should_not be_success
|
65
|
+
stderr.should include("Server foo:bar:default: host is not defined")
|
66
|
+
end
|
67
|
+
|
68
|
+
scenario "Duplicate global server alias" do
|
69
|
+
create_config <<-CONFIG
|
70
|
+
project :foo do
|
71
|
+
environment :bar do
|
72
|
+
server :s1 do
|
73
|
+
host "1.2.3.4"
|
74
|
+
global_alias :a1
|
75
|
+
end
|
76
|
+
|
77
|
+
server :s2 do
|
78
|
+
host "2.3.4.5"
|
79
|
+
global_alias :a1
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
CONFIG
|
84
|
+
|
85
|
+
run "taketo"
|
86
|
+
exit_status.should_not be_success
|
87
|
+
stderr.should include("Server foo:bar:s2: global alias 'a1' has already been taken by server foo:bar:s1")
|
88
|
+
end
|
89
|
+
|
90
|
+
scenario "Command without definition" do
|
91
|
+
create_config <<-CONFIG
|
92
|
+
project :foo do
|
93
|
+
environment :bar do
|
94
|
+
server do
|
95
|
+
host "1.2.3.4"
|
96
|
+
|
97
|
+
command :qux do
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
CONFIG
|
103
|
+
|
104
|
+
run "taketo"
|
105
|
+
exit_status.should_not be_success
|
106
|
+
stderr.should include("Don't know what to execute on command qux")
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'acceptance_spec_helper'
|
2
|
+
|
3
|
+
feature "connect to server" do
|
4
|
+
scenario "reach server via ssh" do
|
5
|
+
create_config <<-CONFIG
|
6
|
+
project :slots do
|
7
|
+
environment :staging do
|
8
|
+
server :s1 do
|
9
|
+
host "1.2.3.4"
|
10
|
+
user "deployer"
|
11
|
+
location "/var/apps/slots"
|
12
|
+
end
|
13
|
+
|
14
|
+
server :s2 do
|
15
|
+
host "2.3.4.5"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
CONFIG
|
20
|
+
|
21
|
+
run "taketo slots:staging:s1 --dry-run"
|
22
|
+
exit_status.should be_success
|
23
|
+
stdout.should == %Q{ssh -t deployer@1.2.3.4 "cd /var/apps/slots; RAILS_ENV=staging bash"}
|
24
|
+
end
|
25
|
+
|
26
|
+
scenario "ssh to the only server" do
|
27
|
+
create_config <<-CONFIG
|
28
|
+
project :slots do
|
29
|
+
environment :staging do
|
30
|
+
server do
|
31
|
+
host "1.2.3.4"
|
32
|
+
location "/var/apps/slots"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
CONFIG
|
37
|
+
|
38
|
+
run "taketo --dry-run"
|
39
|
+
exit_status.should be_success
|
40
|
+
stdout.should == %Q{ssh -t 1.2.3.4 "cd /var/apps/slots; RAILS_ENV=staging bash"}
|
41
|
+
end
|
42
|
+
|
43
|
+
scenario "ssh without password" do
|
44
|
+
create_config <<-CONFIG
|
45
|
+
project :slots do
|
46
|
+
environment :staging do
|
47
|
+
server do
|
48
|
+
identity_file "/home/gor/.ssh/foo bar"
|
49
|
+
host "2.3.4.5"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
CONFIG
|
54
|
+
|
55
|
+
run "taketo --dry-run"
|
56
|
+
exit_status.should be_success
|
57
|
+
stdout.should == %q{ssh -t -i /home/gor/.ssh/foo\ bar 2.3.4.5 "RAILS_ENV=staging bash"}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'acceptance_spec_helper'
|
2
|
+
|
3
|
+
feature "Resolve host error handling" do
|
4
|
+
background { config_exists <<-CONFIG }
|
5
|
+
default_destination "slots:staging:s2"
|
6
|
+
project :slots do
|
7
|
+
environment :staging do
|
8
|
+
server :s1 do
|
9
|
+
host "1.2.3.4"
|
10
|
+
end
|
11
|
+
|
12
|
+
server :s2 do
|
13
|
+
host "2.3.4.5"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
CONFIG
|
18
|
+
|
19
|
+
scenario "Non-existent location" do
|
20
|
+
run "taketo slots:staging:qqq --dry-run"
|
21
|
+
exit_status.should_not be_success
|
22
|
+
stderr.should include("Can't find server for path slots:staging:qqq")
|
23
|
+
end
|
24
|
+
|
25
|
+
scenario "Ambiguous location" do
|
26
|
+
run "taketo slots:staging --dry-run"
|
27
|
+
exit_status.should_not be_success
|
28
|
+
stderr.should include("There are multiple possible destinations: slots:staging:s1, slots:staging:s2")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'acceptance_spec_helper'
|
2
|
+
|
3
|
+
feature "Generate SSH config" do
|
4
|
+
background { config_exists <<-CONFIG }
|
5
|
+
project :foo do
|
6
|
+
environment :bar do
|
7
|
+
server do
|
8
|
+
host "bar.foo.com"
|
9
|
+
port 5678
|
10
|
+
user "pivo"
|
11
|
+
identity_file "~/.ssh/id_rsa"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
project :baz do
|
17
|
+
environment :qux do
|
18
|
+
server :bart do
|
19
|
+
global_alias :bazqux
|
20
|
+
host "2.3.4.5"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
CONFIG
|
25
|
+
|
26
|
+
scenario "Generate ssh config" do
|
27
|
+
run "taketo --generate-ssh-config"
|
28
|
+
exit_status.should be_success
|
29
|
+
stdout.should == <<-SSH_CONFIG.chomp
|
30
|
+
Host bar.foo.com
|
31
|
+
Hostname bar.foo.com
|
32
|
+
Port 5678
|
33
|
+
User pivo
|
34
|
+
IdentityFile ~/.ssh/id_rsa
|
35
|
+
|
36
|
+
Host bazqux
|
37
|
+
Hostname 2.3.4.5
|
38
|
+
|
39
|
+
Host 2.3.4.5
|
40
|
+
Hostname 2.3.4.5
|
41
|
+
SSH_CONFIG
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'acceptance_spec_helper'
|
2
|
+
|
3
|
+
feature "Global server alias" do
|
4
|
+
background { config_exists <<-CONFIG }
|
5
|
+
project :foo do
|
6
|
+
environment :bar do
|
7
|
+
server do
|
8
|
+
host "1.2.3.4"
|
9
|
+
port 5678
|
10
|
+
user "pivo"
|
11
|
+
location "/var/apps/vodka"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
project :baz do
|
17
|
+
environment :qux do
|
18
|
+
server :bart do
|
19
|
+
host "2.3.4.5"
|
20
|
+
default_command :console
|
21
|
+
command :console do
|
22
|
+
execute "rails c"
|
23
|
+
end
|
24
|
+
command :killall do
|
25
|
+
execute "killall humans"
|
26
|
+
desc "Kill ALL humans"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
CONFIG
|
32
|
+
|
33
|
+
scenario "Unique server alias" do
|
34
|
+
run "taketo --view"
|
35
|
+
exit_status.should be_success
|
36
|
+
stdout.should == <<-CONFIG_OUTLINE.chomp
|
37
|
+
|
38
|
+
Project: foo
|
39
|
+
Environment: bar
|
40
|
+
Server: default
|
41
|
+
Host: 1.2.3.4
|
42
|
+
Port: 5678
|
43
|
+
User: pivo
|
44
|
+
Default location: /var/apps/vodka
|
45
|
+
Default command: bash
|
46
|
+
Environment: RAILS_ENV=bar
|
47
|
+
|
48
|
+
Project: baz
|
49
|
+
Environment: qux
|
50
|
+
Server: bart
|
51
|
+
Host: 2.3.4.5
|
52
|
+
Default command: rails c
|
53
|
+
Environment: RAILS_ENV=qux
|
54
|
+
Commands:
|
55
|
+
console
|
56
|
+
killall - Kill ALL humans
|
57
|
+
CONFIG_OUTLINE
|
58
|
+
end
|
59
|
+
|
60
|
+
scenario "View particular server config" do
|
61
|
+
run "taketo foo:bar:default --view"
|
62
|
+
exit_status.should be_success
|
63
|
+
stdout.should == <<-CONFIG_OUTLINE.chomp
|
64
|
+
Server: default
|
65
|
+
Host: 1.2.3.4
|
66
|
+
Port: 5678
|
67
|
+
User: pivo
|
68
|
+
Default location: /var/apps/vodka
|
69
|
+
Default command: bash
|
70
|
+
Environment: RAILS_ENV=bar
|
71
|
+
CONFIG_OUTLINE
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'acceptance_spec_helper'
|
2
|
+
|
3
|
+
feature "Location on remote host" do
|
4
|
+
scenario "Override default location for server through --directory flag" do
|
5
|
+
create_config <<-CONFIG
|
6
|
+
project :slots do
|
7
|
+
environment :staging do
|
8
|
+
server do
|
9
|
+
location '/var/foo'
|
10
|
+
host "1.2.3.4"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
CONFIG
|
15
|
+
|
16
|
+
run "taketo slots:staging --dry-run --directory /var/www"
|
17
|
+
exit_status.should be_success
|
18
|
+
stdout.should == %q{ssh -t 1.2.3.4 "cd /var/www; RAILS_ENV=staging bash"}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'open4'
|
3
|
+
|
4
|
+
ENV['PATH'] = "#{File.expand_path('../../bin', __FILE__)}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
|
5
|
+
ENV['RUBYOPT'] = '-Ilib'
|
6
|
+
|
7
|
+
module AcceptanceSpecDSL
|
8
|
+
module Feature
|
9
|
+
def self.extended(base)
|
10
|
+
base.instance_eval do
|
11
|
+
alias :feature :describe
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.included(base)
|
17
|
+
base.instance_eval do
|
18
|
+
alias :background :before
|
19
|
+
alias :scenario :it
|
20
|
+
alias :xscenario :xit
|
21
|
+
alias :given :let
|
22
|
+
alias :given! :let!
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module TaketoAcceptanceSpec
|
28
|
+
DEFAULT_TEST_CONFIG_PATH = "/tmp/taketo_test_cfg.rb".freeze
|
29
|
+
|
30
|
+
attr_reader :stdout, :stderr, :exit_status
|
31
|
+
|
32
|
+
def create_config(config)
|
33
|
+
File.open(DEFAULT_TEST_CONFIG_PATH, "w") do |f|
|
34
|
+
f.write(config)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
alias :config_exists :create_config
|
38
|
+
|
39
|
+
def remove_config
|
40
|
+
if File.exist?(DEFAULT_TEST_CONFIG_PATH)
|
41
|
+
FileUtils.rm(DEFAULT_TEST_CONFIG_PATH)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def run(command)
|
46
|
+
pid, stdin, stdout, stderr = Open4.popen4("#{command} --config #{DEFAULT_TEST_CONFIG_PATH} --debug")
|
47
|
+
@stdout = stdout.read.chomp.freeze
|
48
|
+
@stderr = stderr.read.chomp.freeze
|
49
|
+
_, @exit_status = Process.waitpid2(pid)
|
50
|
+
ensure
|
51
|
+
stdin.close if stdin
|
52
|
+
stdout.close if stdout
|
53
|
+
stderr.close if stderr
|
54
|
+
end
|
55
|
+
|
56
|
+
RSpec.configure do |config|
|
57
|
+
config.after(:each) do
|
58
|
+
@stdout = nil
|
59
|
+
@stderr = nil
|
60
|
+
@exit_status = nil
|
61
|
+
remove_config
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
extend AcceptanceSpecDSL::Feature
|
67
|
+
|
68
|
+
RSpec.configure do |c|
|
69
|
+
c.include AcceptanceSpecDSL
|
70
|
+
c.include TaketoAcceptanceSpec
|
71
|
+
end
|