shelly 0.0.37 → 0.0.38
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.
- data/lib/shelly.rb +4 -0
- data/lib/shelly/app.rb +14 -7
- data/lib/shelly/cli/backup.rb +3 -3
- data/lib/shelly/cli/command.rb +2 -0
- data/lib/shelly/cli/config.rb +8 -15
- data/lib/shelly/cli/deploys.rb +3 -3
- data/lib/shelly/cli/main.rb +7 -15
- data/lib/shelly/cli/runner.rb +2 -2
- data/lib/shelly/cli/user.rb +5 -5
- data/lib/shelly/client.rb +4 -4
- data/lib/shelly/helpers.rb +8 -1
- data/lib/shelly/version.rb +1 -1
- data/lib/thor/thor.rb +28 -0
- data/spec/helpers.rb +4 -0
- data/spec/shelly/app_spec.rb +24 -7
- data/spec/shelly/cli/backup_spec.rb +20 -17
- data/spec/shelly/cli/config_spec.rb +37 -36
- data/spec/shelly/cli/deploys_spec.rb +14 -11
- data/spec/shelly/cli/main_spec.rb +85 -107
- data/spec/shelly/cli/runner_spec.rb +9 -1
- data/spec/shelly/cli/user_spec.rb +25 -12
- data/spec/shelly/client_spec.rb +7 -6
- data/spec/shelly/cloudfile_spec.rb +11 -0
- metadata +151 -158
@@ -5,6 +5,7 @@ require "shelly/download_progress_bar"
|
|
5
5
|
describe Shelly::CLI::Backup do
|
6
6
|
before do
|
7
7
|
@backup = Shelly::CLI::Backup.new
|
8
|
+
Shelly::CLI::Backup.stub(:new).and_return(@backup)
|
8
9
|
@client = mock
|
9
10
|
@client.stub(:token).and_return("abc")
|
10
11
|
Shelly::Client.stub(:new).and_return(@client)
|
@@ -24,7 +25,7 @@ describe Shelly::CLI::Backup do
|
|
24
25
|
File.delete("Cloudfile")
|
25
26
|
$stdout.should_receive(:puts).with("\e[31mNo Cloudfile found\e[0m")
|
26
27
|
lambda {
|
27
|
-
@backup
|
28
|
+
invoke(@backup, :list)
|
28
29
|
}.should raise_error(SystemExit)
|
29
30
|
end
|
30
31
|
|
@@ -33,7 +34,7 @@ describe Shelly::CLI::Backup do
|
|
33
34
|
exception = Shelly::Client::APIError.new(response.to_json, 401)
|
34
35
|
@client.stub(:database_backups).and_raise(exception)
|
35
36
|
$stdout.should_receive(:puts).with(red "You have no access to 'foo-staging' cloud defined in Cloudfile")
|
36
|
-
lambda { @backup
|
37
|
+
lambda { invoke(@backup, :list) }.should raise_error(SystemExit)
|
37
38
|
end
|
38
39
|
|
39
40
|
context "multiple clouds" do
|
@@ -47,7 +48,7 @@ describe Shelly::CLI::Backup do
|
|
47
48
|
$stdout.should_receive(:puts).with("Available clouds:")
|
48
49
|
$stdout.should_receive(:puts).with(" * foo-production")
|
49
50
|
$stdout.should_receive(:puts).with(" * foo-staging")
|
50
|
-
lambda { @backup
|
51
|
+
lambda { invoke(@backup, :list) }.should raise_error(SystemExit)
|
51
52
|
end
|
52
53
|
|
53
54
|
it "should take cloud from command line for which to show backups" do
|
@@ -57,8 +58,8 @@ describe Shelly::CLI::Backup do
|
|
57
58
|
$stdout.should_receive(:puts).with(" Filename | Size")
|
58
59
|
$stdout.should_receive(:puts).with(" backup.postgre.tar.gz | 10kb")
|
59
60
|
$stdout.should_receive(:puts).with(" backup.mongo.tar.gz | 22kb")
|
60
|
-
@backup.options = {:cloud =>
|
61
|
-
@backup
|
61
|
+
@backup.options = {:cloud => "foo-staging"}
|
62
|
+
invoke(@backup, :list)
|
62
63
|
end
|
63
64
|
end
|
64
65
|
|
@@ -73,30 +74,32 @@ describe Shelly::CLI::Backup do
|
|
73
74
|
|
74
75
|
it "should make sure that cloud is choosen" do
|
75
76
|
@client.should_receive(:database_backup).with("foo-staging", "last")
|
76
|
-
@backup
|
77
|
+
invoke(@backup, :get)
|
78
|
+
end
|
77
79
|
|
78
|
-
|
80
|
+
it "should make sure that cloud is choosen" do
|
79
81
|
@client.should_receive(:database_backup).with("other", "last")
|
80
|
-
@backup.
|
82
|
+
@backup.options = {:cloud => "other"}
|
83
|
+
invoke(@backup, :get)
|
81
84
|
end
|
82
85
|
|
83
86
|
it "should fetch backup size and initialize download progress bar" do
|
84
87
|
@client.stub(:database_backup).and_return({"filename" => "backup.postgres.tar.gz", "size" => 333})
|
85
88
|
Shelly::DownloadProgressBar.should_receive(:new).with(333).and_return(@bar)
|
86
89
|
|
87
|
-
@backup
|
90
|
+
invoke(@backup, :get)
|
88
91
|
end
|
89
92
|
|
90
93
|
it "should fetch given backup file itself" do
|
91
94
|
@client.should_receive(:download_backup).with("foo-staging", "better.tar.gz", @bar.progress_callback)
|
92
|
-
@backup
|
95
|
+
invoke(@backup, :get, "better.tar.gz")
|
93
96
|
end
|
94
97
|
|
95
98
|
it "should show info where file has been saved" do
|
96
99
|
$stdout.should_receive(:puts)
|
97
100
|
$stdout.should_receive(:puts).with(green "Backup file saved to better.tar.gz")
|
98
101
|
@client.should_receive(:download_backup).with("foo-staging", "better.tar.gz", @bar.progress_callback)
|
99
|
-
@backup
|
102
|
+
invoke(@backup, :get, "last")
|
100
103
|
end
|
101
104
|
|
102
105
|
context "on backup not found" do
|
@@ -105,7 +108,7 @@ describe Shelly::CLI::Backup do
|
|
105
108
|
@client.stub(:database_backup).and_raise(exception)
|
106
109
|
$stdout.should_receive(:puts).with(red "Backup not found")
|
107
110
|
$stdout.should_receive(:puts).with("You can list available backups with 'shelly backup list' command")
|
108
|
-
@backup
|
111
|
+
invoke(@backup, :get, "better.tar.gz")
|
109
112
|
end
|
110
113
|
end
|
111
114
|
|
@@ -116,7 +119,7 @@ describe Shelly::CLI::Backup do
|
|
116
119
|
$stdout.should_not_receive(:puts).with(red "Backup not found")
|
117
120
|
$stdout.should_not_receive(:puts).with("You can list available backups with 'shelly backup list' command")
|
118
121
|
lambda {
|
119
|
-
@backup
|
122
|
+
invoke(@backup, :get, "better.tar.gz")
|
120
123
|
}.should raise_error(Shelly::Client::APIError)
|
121
124
|
end
|
122
125
|
end
|
@@ -135,22 +138,22 @@ describe Shelly::CLI::Backup do
|
|
135
138
|
exception = Shelly::Client::APIError.new(response.to_json, 404)
|
136
139
|
@client.stub(:request_backup).and_raise(exception)
|
137
140
|
$stdout.should_receive(:puts).with(red "You have no access to 'foo-staging' cloud defined in Cloudfile")
|
138
|
-
lambda { @backup
|
141
|
+
lambda { invoke(@backup, :create) }.should raise_error(SystemExit)
|
139
142
|
end
|
140
143
|
|
141
144
|
it "should display errors and exit 1 when kind is not valid" do
|
142
145
|
response = {"message" => "Wrong KIND argument. User one of following: postgresql, mongodb, redis"}
|
143
|
-
exception = Shelly::Client::APIError.new(response.to_json,
|
146
|
+
exception = Shelly::Client::APIError.new(response.to_json, 422)
|
144
147
|
@client.should_receive(:request_backup).and_raise(exception)
|
145
148
|
$stdout.should_receive(:puts).with(red response["message"])
|
146
|
-
lambda { @backup
|
149
|
+
lambda { invoke(@backup, :create) }.should raise_error(SystemExit)
|
147
150
|
end
|
148
151
|
|
149
152
|
it "should display information about request backup" do
|
150
153
|
@client.stub(:request_backup)
|
151
154
|
$stdout.should_receive(:puts).with(green "Backup requested. It can take up to several minutes for" +
|
152
155
|
"the backup process to finish and the backup to show up in backups list.")
|
153
|
-
@backup
|
156
|
+
invoke(@backup, :create)
|
154
157
|
end
|
155
158
|
end
|
156
159
|
end
|
@@ -6,6 +6,7 @@ describe Shelly::CLI::Config do
|
|
6
6
|
before do
|
7
7
|
FileUtils.stub(:chmod)
|
8
8
|
@config = Shelly::CLI::Config.new
|
9
|
+
Shelly::CLI::Config.stub(:new).and_return(@config)
|
9
10
|
@client = mock
|
10
11
|
Shelly::Client.stub(:new).and_return(@client)
|
11
12
|
$stdout.stub(:puts)
|
@@ -28,7 +29,7 @@ describe Shelly::CLI::Config do
|
|
28
29
|
File.delete("Cloudfile")
|
29
30
|
$stdout.should_receive(:puts).with(red "No Cloudfile found")
|
30
31
|
lambda {
|
31
|
-
@config
|
32
|
+
invoke(@config, :list)
|
32
33
|
}.should raise_error(SystemExit)
|
33
34
|
end
|
34
35
|
|
@@ -37,7 +38,7 @@ describe Shelly::CLI::Config do
|
|
37
38
|
exception = Shelly::Client::APIError.new(response.to_json, 404)
|
38
39
|
@client.stub(:app_configs).and_raise(exception)
|
39
40
|
$stdout.should_receive(:puts).with(red "You have no access to 'foo-production' cloud defined in Cloudfile")
|
40
|
-
lambda { @config
|
41
|
+
lambda { invoke(@config, :list) }.should raise_error(SystemExit)
|
41
42
|
end
|
42
43
|
|
43
44
|
it "should list available configuration files for clouds" do
|
@@ -51,7 +52,7 @@ describe Shelly::CLI::Config do
|
|
51
52
|
$stdout.should_receive(:puts).with("Custom configuration files:")
|
52
53
|
$stdout.should_receive(:puts).with(/ * \s+config\/settings.yml/)
|
53
54
|
|
54
|
-
@config
|
55
|
+
invoke(@config, :list)
|
55
56
|
end
|
56
57
|
|
57
58
|
end
|
@@ -60,19 +61,19 @@ describe Shelly::CLI::Config do
|
|
60
61
|
it "should exit with message if there is no Cloudfile" do
|
61
62
|
File.delete("Cloudfile")
|
62
63
|
$stdout.should_receive(:puts).with(red "No Cloudfile found")
|
63
|
-
lambda { @config
|
64
|
+
lambda { invoke(@config, :show) }.should raise_error(SystemExit)
|
64
65
|
end
|
65
66
|
|
66
|
-
it "should exit if no
|
67
|
+
it "should exit if no path was specified" do
|
67
68
|
$stdout.should_receive(:puts).with(red "No configuration file specified")
|
68
|
-
lambda { @config
|
69
|
+
lambda { invoke(@config, :show) }.should raise_error(SystemExit)
|
69
70
|
end
|
70
71
|
|
71
72
|
it "should show config" do
|
72
|
-
@client.should_receive(:app_config).with("foo-staging",
|
73
|
+
@client.should_receive(:app_config).with("foo-staging", "path").and_return({"path" => "test.rb", "content" => "example content"})
|
73
74
|
$stdout.should_receive(:puts).with(green "Content of test.rb:")
|
74
75
|
$stdout.should_receive(:puts).with("example content")
|
75
|
-
@config
|
76
|
+
invoke(@config, :show, "path")
|
76
77
|
end
|
77
78
|
|
78
79
|
context "multiple clouds" do
|
@@ -82,13 +83,13 @@ describe Shelly::CLI::Config do
|
|
82
83
|
|
83
84
|
it "should show info to select cloud and exit" do
|
84
85
|
$stdout.should_receive(:puts).with("You have multiple clouds in Cloudfile. Specify cloud using:")
|
85
|
-
lambda { @config
|
86
|
+
lambda { invoke(@config, :show, "path") }.should raise_error(SystemExit)
|
86
87
|
end
|
87
88
|
|
88
89
|
it "should use cloud specified by parameter" do
|
89
|
-
@client.should_receive(:app_config).with("foo-production",
|
90
|
+
@client.should_receive(:app_config).with("foo-production", "path").and_return({"path" => "test.rb", "content" => "example content"})
|
90
91
|
@config.options = {:cloud => "foo-production"}
|
91
|
-
@config
|
92
|
+
invoke(@config, :show, "path")
|
92
93
|
end
|
93
94
|
end
|
94
95
|
end
|
@@ -97,25 +98,25 @@ describe Shelly::CLI::Config do
|
|
97
98
|
it "should exit with message if there is no Cloudfile" do
|
98
99
|
File.delete("Cloudfile")
|
99
100
|
$stdout.should_receive(:puts).with(red "No Cloudfile found")
|
100
|
-
lambda { @config
|
101
|
+
lambda { invoke(@config, :create, "path") }.should raise_error(SystemExit)
|
101
102
|
end
|
102
103
|
|
103
|
-
it "should exit if no
|
104
|
+
it "should exit if no path was specified" do
|
104
105
|
$stdout.should_receive(:puts).with(red "No path specified")
|
105
|
-
lambda { @config
|
106
|
+
lambda { invoke(@config, :create) }.should raise_error(SystemExit)
|
106
107
|
end
|
107
108
|
|
108
109
|
it "should ask to set EDITOR environment variable if not set" do
|
109
110
|
@config.stub(:system) {false}
|
110
111
|
$stdout.should_receive(:puts).with(red "Please set EDITOR environment variable")
|
111
|
-
lambda { @config
|
112
|
+
lambda { invoke(@config, :create, "path") }.should raise_error(SystemExit)
|
112
113
|
end
|
113
114
|
|
114
115
|
it "should create file" do
|
115
116
|
@config.should_receive(:system).with(/vim \/tmp\/shelly-edit/).and_return(true)
|
116
117
|
@client.should_receive(:app_create_config).with("foo-staging", "path", "\n").and_return({})
|
117
118
|
$stdout.should_receive(:puts).with(green "File 'path' created, it will be used after next code deploy")
|
118
|
-
@config
|
119
|
+
invoke(@config, :create, "path")
|
119
120
|
end
|
120
121
|
|
121
122
|
context "multiple clouds" do
|
@@ -133,7 +134,7 @@ describe Shelly::CLI::Config do
|
|
133
134
|
@config.should_receive(:system).with(/vim \/tmp\/shelly-edit/).and_return(true)
|
134
135
|
@client.should_receive(:app_create_config).with("foo-production", "path", "\n").and_return({})
|
135
136
|
@config.options = {:cloud => "foo-production"}
|
136
|
-
@config
|
137
|
+
invoke(@config, :create, "path")
|
137
138
|
end
|
138
139
|
end
|
139
140
|
end
|
@@ -143,27 +144,27 @@ describe Shelly::CLI::Config do
|
|
143
144
|
it "should exit with message if there is no Cloudfile" do
|
144
145
|
File.delete("Cloudfile")
|
145
146
|
$stdout.should_receive(:puts).with(red "No Cloudfile found")
|
146
|
-
lambda { @config
|
147
|
+
lambda { invoke(@config, :edit, "path") }.should raise_error(SystemExit)
|
147
148
|
end
|
148
149
|
|
149
150
|
it "should exit if no path was specified" do
|
150
151
|
$stdout.should_receive(:puts).with(red "No configuration file specified")
|
151
|
-
lambda { @config
|
152
|
+
lambda { invoke(@config, :edit) }.should raise_error(SystemExit)
|
152
153
|
end
|
153
154
|
|
154
155
|
it "should ask to set EDITOR environment variable if not set" do
|
155
|
-
@client.should_receive(:app_config).with("foo-staging",
|
156
|
+
@client.should_receive(:app_config).with("foo-staging", "path").and_return({"path" => "test.rb", "content" => "example content"})
|
156
157
|
@config.stub(:system) {false}
|
157
158
|
$stdout.should_receive(:puts).with(red "Please set EDITOR environment variable")
|
158
|
-
lambda { @config
|
159
|
+
lambda { invoke(@config, :edit, "path") }.should raise_error(SystemExit)
|
159
160
|
end
|
160
161
|
|
161
162
|
it "should create file" do
|
162
|
-
@client.should_receive(:app_config).with("foo-staging",
|
163
|
+
@client.should_receive(:app_config).with("foo-staging", "path").and_return({"path" => "test.rb", "content" => "example content"})
|
163
164
|
@config.should_receive(:system).with(/vim \/tmp\/shelly-edit/).and_return(true)
|
164
|
-
@client.should_receive(:app_update_config).with("foo-staging",
|
165
|
+
@client.should_receive(:app_update_config).with("foo-staging", "path", "example content\n").and_return({"path" => "test.rb", "content" => "example content"})
|
165
166
|
$stdout.should_receive(:puts).with(green "File 'test.rb' updated, it will be used after next code deploy")
|
166
|
-
@config
|
167
|
+
invoke(@config, :edit, "path")
|
167
168
|
end
|
168
169
|
|
169
170
|
context "multiple clouds" do
|
@@ -174,15 +175,15 @@ describe Shelly::CLI::Config do
|
|
174
175
|
it "should show info to select cloud and exit" do
|
175
176
|
@config.stub(:system) {true}
|
176
177
|
$stdout.should_receive(:puts).with("You have multiple clouds in Cloudfile. Specify cloud using:")
|
177
|
-
lambda { @config
|
178
|
+
lambda { invoke(@config, :edit, "path") }.should raise_error(SystemExit)
|
178
179
|
end
|
179
180
|
|
180
181
|
it "should use cloud specified by parameter" do
|
181
|
-
@client.should_receive(:app_config).with("foo-production",
|
182
|
+
@client.should_receive(:app_config).with("foo-production", "path").and_return({"path" => "test.rb", "content" => "example content"})
|
182
183
|
@config.should_receive(:system).with(/vim \/tmp\/shelly-edit/).and_return(true)
|
183
|
-
@client.should_receive(:app_update_config).with("foo-production",
|
184
|
+
@client.should_receive(:app_update_config).with("foo-production", "path", "example content\n").and_return({"path" => "test.rb", "content" => "example content"})
|
184
185
|
@config.options = {:cloud => "foo-production"}
|
185
|
-
@config
|
186
|
+
invoke(@config, :edit, "path")
|
186
187
|
end
|
187
188
|
end
|
188
189
|
end
|
@@ -191,19 +192,19 @@ describe Shelly::CLI::Config do
|
|
191
192
|
it "should exit with message if there is no Cloudfile" do
|
192
193
|
File.delete("Cloudfile")
|
193
194
|
$stdout.should_receive(:puts).with(red "No Cloudfile found")
|
194
|
-
lambda { @config
|
195
|
+
lambda { invoke(@config, :delete) }.should raise_error(SystemExit)
|
195
196
|
end
|
196
197
|
|
197
198
|
it "should exit if no path was specified" do
|
198
199
|
$stdout.should_receive(:puts).with(red "No configuration file specified")
|
199
|
-
lambda { @config
|
200
|
+
lambda { invoke(@config, :delete) }.should raise_error(SystemExit)
|
200
201
|
end
|
201
202
|
|
202
203
|
it "should delete configuration file" do
|
203
|
-
@client.should_receive(:app_delete_config).with("foo-staging",
|
204
|
+
@client.should_receive(:app_delete_config).with("foo-staging", "path").and_return({})
|
204
205
|
$stdout.should_receive(:puts).with(green "File deleted, redeploy your cloud to make changes")
|
205
206
|
fake_stdin(["y"]) do
|
206
|
-
@config
|
207
|
+
invoke(@config, :delete, "path")
|
207
208
|
end
|
208
209
|
end
|
209
210
|
|
@@ -211,7 +212,7 @@ describe Shelly::CLI::Config do
|
|
211
212
|
@client.should_not_receive(:app_delete_config)
|
212
213
|
$stdout.should_receive(:puts).with("File not deleted")
|
213
214
|
fake_stdin(["n"]) do
|
214
|
-
@config
|
215
|
+
invoke(@config, :delete, "path")
|
215
216
|
end
|
216
217
|
end
|
217
218
|
|
@@ -222,15 +223,15 @@ describe Shelly::CLI::Config do
|
|
222
223
|
|
223
224
|
it "should show info to select cloud and exit" do
|
224
225
|
$stdout.should_receive(:puts).with("You have multiple clouds in Cloudfile. Specify cloud using:")
|
225
|
-
lambda { @config
|
226
|
+
lambda { invoke(@config, :delete, "path") }.should raise_error(SystemExit)
|
226
227
|
end
|
227
228
|
|
228
229
|
it "should use cloud specified by parameter" do
|
229
|
-
@client.should_receive(:app_delete_config).with("foo-production",
|
230
|
+
@client.should_receive(:app_delete_config).with("foo-production", "path").and_return({})
|
230
231
|
$stdout.should_receive(:puts).with(green "File deleted, redeploy your cloud to make changes")
|
231
232
|
@config.options = {:cloud => "foo-production"}
|
232
233
|
fake_stdin(["y"]) do
|
233
|
-
@config
|
234
|
+
invoke(@config, :delete, "path")
|
234
235
|
end
|
235
236
|
end
|
236
237
|
end
|
@@ -5,6 +5,7 @@ describe Shelly::CLI::Deploys do
|
|
5
5
|
before do
|
6
6
|
FileUtils.stub(:chmod)
|
7
7
|
@deploys = Shelly::CLI::Deploys.new
|
8
|
+
Shelly::CLI::Deploys.stub(:new).and_return(@deploys)
|
8
9
|
@client = mock
|
9
10
|
Shelly::Client.stub(:new).and_return(@client)
|
10
11
|
$stdout.stub(:puts)
|
@@ -23,7 +24,7 @@ describe Shelly::CLI::Deploys do
|
|
23
24
|
File.delete("Cloudfile")
|
24
25
|
$stdout.should_receive(:puts).with("\e[31mNo Cloudfile found\e[0m")
|
25
26
|
lambda {
|
26
|
-
@deploys
|
27
|
+
invoke(@deploys, :list)
|
27
28
|
}.should raise_error(SystemExit)
|
28
29
|
end
|
29
30
|
|
@@ -32,7 +33,7 @@ describe Shelly::CLI::Deploys do
|
|
32
33
|
exception = Shelly::Client::APIError.new(response.to_json, 404)
|
33
34
|
@client.stub(:deploy_logs).and_raise(exception)
|
34
35
|
$stdout.should_receive(:puts).with(red "You have no access to 'foo-staging' cloud defined in Cloudfile")
|
35
|
-
lambda { @deploys
|
36
|
+
lambda { invoke(@deploys, :list) }.should raise_error(SystemExit)
|
36
37
|
end
|
37
38
|
|
38
39
|
context "multiple clouds" do
|
@@ -46,7 +47,7 @@ describe Shelly::CLI::Deploys do
|
|
46
47
|
$stdout.should_receive(:puts).with("Available clouds:")
|
47
48
|
$stdout.should_receive(:puts).with(" * foo-production")
|
48
49
|
$stdout.should_receive(:puts).with(" * foo-staging")
|
49
|
-
lambda { @deploys
|
50
|
+
lambda { invoke(@deploys, :list) }.should raise_error(SystemExit)
|
50
51
|
end
|
51
52
|
|
52
53
|
it "should take cloud from command line for which to show logs" do
|
@@ -54,17 +55,19 @@ describe Shelly::CLI::Deploys do
|
|
54
55
|
$stdout.should_receive(:puts).with(green "Available deploy logs")
|
55
56
|
$stdout.should_receive(:puts).with(" * 2011-12-12-14-14-59")
|
56
57
|
@deploys.options = {:cloud => "foo-staging"}
|
57
|
-
@deploys
|
58
|
+
invoke(@deploys, :list)
|
58
59
|
end
|
59
60
|
end
|
60
61
|
|
61
62
|
context "single cloud" do
|
62
63
|
it "should display available logs" do
|
63
|
-
@client.should_receive(:deploy_logs).with("foo-staging").and_return([
|
64
|
+
@client.should_receive(:deploy_logs).with("foo-staging").and_return([
|
65
|
+
{"failed" => false, "created_at" => "2011-12-12-14-14-59"},
|
66
|
+
{"failed" => true, "created_at" => "2011-12-12-15-14-59"}])
|
64
67
|
$stdout.should_receive(:puts).with(green "Available deploy logs")
|
65
68
|
$stdout.should_receive(:puts).with(" * 2011-12-12-14-14-59")
|
66
69
|
$stdout.should_receive(:puts).with(" * 2011-12-12-15-14-59 (failed)")
|
67
|
-
@deploys
|
70
|
+
invoke(@deploys, :list)
|
68
71
|
end
|
69
72
|
end
|
70
73
|
end
|
@@ -81,7 +84,7 @@ describe Shelly::CLI::Deploys do
|
|
81
84
|
File.delete("Cloudfile")
|
82
85
|
$stdout.should_receive(:puts).with("\e[31mNo Cloudfile found\e[0m")
|
83
86
|
lambda {
|
84
|
-
@deploys
|
87
|
+
invoke(@deploys, :show)
|
85
88
|
}.should raise_error(SystemExit)
|
86
89
|
end
|
87
90
|
|
@@ -90,7 +93,7 @@ describe Shelly::CLI::Deploys do
|
|
90
93
|
exception = Shelly::Client::APIError.new(response.to_json, 404)
|
91
94
|
@client.stub(:deploy_log).and_raise(exception)
|
92
95
|
$stdout.should_receive(:puts).with(red "You have no access to 'foo-staging' cloud defined in Cloudfile")
|
93
|
-
lambda { @deploys
|
96
|
+
lambda { invoke(@deploys, :show, "last") }.should raise_error(SystemExit)
|
94
97
|
end
|
95
98
|
|
96
99
|
context "multiple clouds" do
|
@@ -104,14 +107,14 @@ describe Shelly::CLI::Deploys do
|
|
104
107
|
$stdout.should_receive(:puts).with("Available clouds:")
|
105
108
|
$stdout.should_receive(:puts).with(" * foo-production")
|
106
109
|
$stdout.should_receive(:puts).with(" * foo-staging")
|
107
|
-
lambda { @deploys
|
110
|
+
lambda { invoke(@deploys, :show, "last") }.should raise_error(SystemExit)
|
108
111
|
end
|
109
112
|
|
110
113
|
it "should render the logs" do
|
111
114
|
@client.should_receive(:deploy_log).with("foo-staging", "last").and_return(response)
|
112
115
|
expected_output
|
113
116
|
@deploys.options = {:cloud => "foo-staging"}
|
114
|
-
@deploys
|
117
|
+
invoke(@deploys, :show, "last")
|
115
118
|
end
|
116
119
|
end
|
117
120
|
|
@@ -119,7 +122,7 @@ describe Shelly::CLI::Deploys do
|
|
119
122
|
it "should render logs without passing cloud" do
|
120
123
|
@client.should_receive(:deploy_log).with("foo-staging", "last").and_return(response)
|
121
124
|
expected_output
|
122
|
-
@deploys
|
125
|
+
invoke(@deploys, :show, "last")
|
123
126
|
end
|
124
127
|
end
|
125
128
|
|
@@ -5,6 +5,7 @@ describe Shelly::CLI::Main do
|
|
5
5
|
before do
|
6
6
|
FileUtils.stub(:chmod)
|
7
7
|
@main = Shelly::CLI::Main.new
|
8
|
+
Shelly::CLI::Main.stub(:new).and_return(@main)
|
8
9
|
@client = mock
|
9
10
|
Shelly::Client.stub(:new).and_return(@client)
|
10
11
|
Shelly::User.stub(:guess_email).and_return("")
|
@@ -15,7 +16,7 @@ describe Shelly::CLI::Main do
|
|
15
16
|
describe "#version" do
|
16
17
|
it "should return shelly's version" do
|
17
18
|
$stdout.should_receive(:puts).with("shelly version #{Shelly::VERSION}")
|
18
|
-
@main
|
19
|
+
invoke(@main, :version)
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
@@ -42,7 +43,7 @@ Tasks:
|
|
42
43
|
Options:
|
43
44
|
[--debug] # Show debug information
|
44
45
|
OUT
|
45
|
-
out = IO.popen("bin/shelly").read.strip
|
46
|
+
out = IO.popen("bin/shelly --debug").read.strip
|
46
47
|
out.should == expected.strip
|
47
48
|
end
|
48
49
|
|
@@ -79,7 +80,7 @@ OUT
|
|
79
80
|
$stdout.should_receive(:puts).with("\e[31mNo such file or directory - " + @key_path + "\e[0m")
|
80
81
|
$stdout.should_receive(:puts).with("\e[31mUse ssh-keygen to generate ssh key pair\e[0m")
|
81
82
|
lambda {
|
82
|
-
@main
|
83
|
+
invoke(@main, :register)
|
83
84
|
}.should raise_error(SystemExit)
|
84
85
|
end
|
85
86
|
|
@@ -88,7 +89,7 @@ OUT
|
|
88
89
|
$stdout.should_receive(:puts).with("\e[31mUser with your ssh key already exists.\e[0m")
|
89
90
|
$stdout.should_receive(:puts).with("\e[31mYou can login using: shelly login [EMAIL]\e[0m")
|
90
91
|
lambda {
|
91
|
-
@main
|
92
|
+
invoke(@main, :register)
|
92
93
|
}.should raise_error(SystemExit)
|
93
94
|
end
|
94
95
|
|
@@ -97,7 +98,7 @@ OUT
|
|
97
98
|
$stdout.should_receive(:print).with("Password: ")
|
98
99
|
$stdout.should_receive(:print).with("Password confirmation: ")
|
99
100
|
fake_stdin(["better@example.com", "secret", "secret"]) do
|
100
|
-
@main
|
101
|
+
invoke(@main, :register)
|
101
102
|
end
|
102
103
|
end
|
103
104
|
|
@@ -106,21 +107,21 @@ OUT
|
|
106
107
|
$stdout.should_receive(:print).with("Email (kate@example.com - default): ")
|
107
108
|
@client.should_receive(:register_user).with("kate@example.com", "secret", "ssh-key AAbbcc")
|
108
109
|
fake_stdin(["", "secret", "secret"]) do
|
109
|
-
@main
|
110
|
+
invoke(@main, :register)
|
110
111
|
end
|
111
112
|
end
|
112
113
|
|
113
114
|
it "should use email provided by user" do
|
114
115
|
@client.should_receive(:register_user).with("better@example.com", "secret", "ssh-key AAbbcc")
|
115
116
|
fake_stdin(["better@example.com", "secret", "secret"]) do
|
116
|
-
@main
|
117
|
+
invoke(@main, :register)
|
117
118
|
end
|
118
119
|
end
|
119
120
|
|
120
121
|
it "should not ask about email if it's provided as argument" do
|
121
122
|
$stdout.should_receive(:puts).with("Registering with email: kate@example.com")
|
122
123
|
fake_stdin(["secret", "secret"]) do
|
123
|
-
@main
|
124
|
+
invoke(@main, :register, "kate@example.com")
|
124
125
|
end
|
125
126
|
end
|
126
127
|
|
@@ -130,7 +131,7 @@ OUT
|
|
130
131
|
$stdout.should_receive(:puts).with("\e[31mEmail can't be blank, please try again\e[0m")
|
131
132
|
lambda {
|
132
133
|
fake_stdin(["", "bob@example.com", "only-pass", "only-pass"]) do
|
133
|
-
@main
|
134
|
+
invoke(@main, :register)
|
134
135
|
end
|
135
136
|
}.should raise_error(SystemExit)
|
136
137
|
end
|
@@ -142,7 +143,7 @@ OUT
|
|
142
143
|
File.open(@key_path, "w") { |f| f << "key" }
|
143
144
|
$stdout.should_receive(:puts).with("Uploading your public SSH key from #{@key_path}")
|
144
145
|
fake_stdin(["kate@example.com", "secret", "secret"]) do
|
145
|
-
@main
|
146
|
+
invoke(@main, :register)
|
146
147
|
end
|
147
148
|
end
|
148
149
|
end
|
@@ -153,7 +154,7 @@ OUT
|
|
153
154
|
FileUtils.rm_rf(@key_path)
|
154
155
|
$stdout.should_not_receive(:puts).with("Uploading your public SSH key from #{@key_path}")
|
155
156
|
fake_stdin(["kate@example.com", "secret", "secret"]) do
|
156
|
-
@main
|
157
|
+
invoke(@main, :register)
|
157
158
|
end
|
158
159
|
end
|
159
160
|
end
|
@@ -164,7 +165,7 @@ OUT
|
|
164
165
|
$stdout.should_receive(:puts).with("Successfully registered!")
|
165
166
|
$stdout.should_receive(:puts).with("Check you mailbox for email address confirmation")
|
166
167
|
fake_stdin(["kate@example.com", "pass", "pass"]) do
|
167
|
-
@main
|
168
|
+
invoke(@main, :register)
|
168
169
|
end
|
169
170
|
end
|
170
171
|
end
|
@@ -177,7 +178,7 @@ OUT
|
|
177
178
|
$stdout.should_receive(:puts).with("\e[31mEmail has been already taken\e[0m")
|
178
179
|
lambda {
|
179
180
|
fake_stdin(["kate@example.com", "pass", "pass"]) do
|
180
|
-
@main
|
181
|
+
invoke(@main, :register)
|
181
182
|
end
|
182
183
|
}.should raise_error(SystemExit)
|
183
184
|
end
|
@@ -199,7 +200,7 @@ OUT
|
|
199
200
|
|
200
201
|
it "should ask about email and password" do
|
201
202
|
fake_stdin(["megan@example.com", "secret"]) do
|
202
|
-
@main
|
203
|
+
invoke(@main, :login)
|
203
204
|
end
|
204
205
|
end
|
205
206
|
|
@@ -207,14 +208,14 @@ OUT
|
|
207
208
|
it "should display message about successful login" do
|
208
209
|
$stdout.should_receive(:puts).with("Login successful")
|
209
210
|
fake_stdin(["megan@example.com", "secret"]) do
|
210
|
-
@main
|
211
|
+
invoke(@main, :login)
|
211
212
|
end
|
212
213
|
end
|
213
214
|
|
214
215
|
it "should accept email as parameter" do
|
215
216
|
$stdout.should_receive(:puts).with("Login successful")
|
216
217
|
fake_stdin(["secret"]) do
|
217
|
-
@main
|
218
|
+
invoke(@main, :login, "megan@example.com")
|
218
219
|
end
|
219
220
|
end
|
220
221
|
|
@@ -222,7 +223,7 @@ OUT
|
|
222
223
|
@user.should_receive(:upload_ssh_key)
|
223
224
|
$stdout.should_receive(:puts).with("Uploading your public SSH key")
|
224
225
|
fake_stdin(["megan@example.com", "secret"]) do
|
225
|
-
@main
|
226
|
+
invoke(@main, :login)
|
226
227
|
end
|
227
228
|
end
|
228
229
|
|
@@ -230,7 +231,7 @@ OUT
|
|
230
231
|
@user.should_receive(:upload_ssh_key).and_raise(RestClient::Conflict)
|
231
232
|
$stdout.should_receive(:puts).with("\e[32mYou have following clouds available:\e[0m")
|
232
233
|
fake_stdin(["megan@example.com", "secret"]) do
|
233
|
-
@main
|
234
|
+
invoke(@main, :login)
|
234
235
|
end
|
235
236
|
end
|
236
237
|
|
@@ -239,7 +240,7 @@ OUT
|
|
239
240
|
$stdout.should_receive(:puts).with(/ abc\s+\| running/)
|
240
241
|
$stdout.should_receive(:puts).with(/ fooo\s+\| no code/)
|
241
242
|
fake_stdin(["megan@example.com", "secret"]) do
|
242
|
-
@main
|
243
|
+
invoke(@main, :login)
|
243
244
|
end
|
244
245
|
end
|
245
246
|
end
|
@@ -251,7 +252,7 @@ OUT
|
|
251
252
|
$stdout.should_receive(:puts).with("\e[31mNo such file or directory - " + @key_path + "\e[0m")
|
252
253
|
$stdout.should_receive(:puts).with("\e[31mUse ssh-keygen to generate ssh key pair\e[0m")
|
253
254
|
lambda {
|
254
|
-
@main
|
255
|
+
invoke(@main, :login)
|
255
256
|
}.should raise_error(SystemExit)
|
256
257
|
end
|
257
258
|
end
|
@@ -266,7 +267,7 @@ OUT
|
|
266
267
|
$stdout.should_receive(:puts).with("\e[31mhttps://admin.winniecloud.com/users/password/new\e[0m")
|
267
268
|
lambda {
|
268
269
|
fake_stdin(["megan@example.com", "secret"]) do
|
269
|
-
@main
|
270
|
+
invoke(@main, :login)
|
270
271
|
end
|
271
272
|
}.should raise_error(SystemExit)
|
272
273
|
end
|
@@ -285,6 +286,7 @@ OUT
|
|
285
286
|
@app.stub(:git_url).and_return("git@git.shellycloud.com:foooo.git")
|
286
287
|
Shelly::App.stub(:inside_git_repository?).and_return(true)
|
287
288
|
Shelly::App.stub(:new).and_return(@app)
|
289
|
+
@client.stub(:token).and_return("abc")
|
288
290
|
end
|
289
291
|
|
290
292
|
it "should exit with message if command run outside git repository" do
|
@@ -292,7 +294,7 @@ OUT
|
|
292
294
|
$stdout.should_receive(:puts).with("\e[31mMust be run inside your project git repository\e[0m")
|
293
295
|
lambda {
|
294
296
|
fake_stdin(["", ""]) do
|
295
|
-
@main
|
297
|
+
invoke(@main, :add)
|
296
298
|
end
|
297
299
|
}.should raise_error(SystemExit)
|
298
300
|
end
|
@@ -303,33 +305,25 @@ OUT
|
|
303
305
|
it "should show help and exit if not all options are passed" do
|
304
306
|
$stdout.should_receive(:puts).with("\e[31mTry 'shelly help add' for more information\e[0m")
|
305
307
|
@main.options = {"code-name" => "foo"}
|
306
|
-
lambda {
|
308
|
+
lambda {
|
309
|
+
invoke(@main, :add)
|
310
|
+
}.should raise_error(SystemExit)
|
307
311
|
end
|
308
312
|
|
309
313
|
it "should exit if databases are not valid" do
|
310
314
|
$stdout.should_receive(:puts).with("\e[31mTry 'shelly help add' for more information\e[0m")
|
311
|
-
@main.options = {"code-name" => "foo",
|
312
|
-
lambda {
|
313
|
-
|
314
|
-
|
315
|
-
it "should display which parameter was wrong" do
|
316
|
-
expected = "shelly: unrecognized option '--unknown=param'\n" +
|
317
|
-
"Usage: shelly [COMMAND]... [OPTIONS]\n" +
|
318
|
-
"Try 'shelly --help' for more information"
|
319
|
-
|
320
|
-
Open3.popen3("bin/shelly add --unknown=param") do |stdin, stdout, stderr, wait_thr|
|
321
|
-
out = stderr.read.strip
|
322
|
-
out.should == expected
|
323
|
-
end
|
315
|
+
@main.options = {"code-name" => "foo", :databases => ["not existing"], :domains => "foo.example.com"}
|
316
|
+
lambda {
|
317
|
+
invoke(@main, :add)
|
318
|
+
}.should raise_error(SystemExit)
|
324
319
|
end
|
325
|
-
|
326
320
|
end
|
327
321
|
|
328
322
|
context "valid params" do
|
329
323
|
it "should create app on shelly cloud" do
|
330
324
|
@app.should_receive(:create)
|
331
325
|
@main.options = {"code-name" => "foo", "databases" => ["postgresql"], "domains" => ["foo.example.com"]}
|
332
|
-
@main
|
326
|
+
invoke(@main, :add)
|
333
327
|
end
|
334
328
|
end
|
335
329
|
end
|
@@ -338,7 +332,7 @@ OUT
|
|
338
332
|
$stdout.should_receive(:print).with("Cloud code name (foo-production - default): ")
|
339
333
|
@app.should_receive(:code_name=).with("mycodename")
|
340
334
|
fake_stdin(["mycodename", ""]) do
|
341
|
-
@main
|
335
|
+
invoke(@main, :add)
|
342
336
|
end
|
343
337
|
end
|
344
338
|
|
@@ -347,7 +341,7 @@ OUT
|
|
347
341
|
$stdout.should_receive(:print).with("Cloud code name (foo-production - default): ")
|
348
342
|
@app.should_receive(:code_name=).with("foo-production")
|
349
343
|
fake_stdin(["", ""]) do
|
350
|
-
@main
|
344
|
+
invoke(@main, :add)
|
351
345
|
end
|
352
346
|
end
|
353
347
|
end
|
@@ -356,7 +350,7 @@ OUT
|
|
356
350
|
$stdout.should_receive(:print).with("Which database do you want to use postgresql, mongodb, redis, none (postgresql - default): ")
|
357
351
|
@app.should_receive(:databases=).with(["postgresql", "mongodb", "redis"])
|
358
352
|
fake_stdin(["", "postgresql ,mongodb redis"]) do
|
359
|
-
@main
|
353
|
+
invoke(@main, :add)
|
360
354
|
end
|
361
355
|
end
|
362
356
|
|
@@ -364,7 +358,7 @@ OUT
|
|
364
358
|
$stdout.should_receive(:print).with("Which database do you want to use postgresql, mongodb, redis, none (postgresql - default): ")
|
365
359
|
$stdout.should_receive(:print).with("Unknown database kind. Supported are: postgresql, mongodb, redis, none: ")
|
366
360
|
fake_stdin(["", "postgresql,doesnt-exist", "none"]) do
|
367
|
-
@main
|
361
|
+
invoke(@main, :add)
|
368
362
|
end
|
369
363
|
end
|
370
364
|
|
@@ -372,7 +366,7 @@ OUT
|
|
372
366
|
it "should use 'postgresql' database as default" do
|
373
367
|
@app.should_receive(:databases=).with(["postgresql"])
|
374
368
|
fake_stdin(["", ""]) do
|
375
|
-
@main
|
369
|
+
invoke(@main, :add)
|
376
370
|
end
|
377
371
|
end
|
378
372
|
end
|
@@ -380,7 +374,7 @@ OUT
|
|
380
374
|
it "should create the app on shelly cloud" do
|
381
375
|
@app.should_receive(:create)
|
382
376
|
fake_stdin(["", ""]) do
|
383
|
-
@main
|
377
|
+
invoke(@main, :add)
|
384
378
|
end
|
385
379
|
end
|
386
380
|
|
@@ -393,7 +387,7 @@ OUT
|
|
393
387
|
$stdout.should_receive(:puts).with("\e[31mshelly add --code-name=foo-production --databases=postgresql --domains=foo-production.shellyapp.com\e[0m")
|
394
388
|
lambda {
|
395
389
|
fake_stdin(["", ""]) do
|
396
|
-
@main
|
390
|
+
invoke(@main, :add)
|
397
391
|
end
|
398
392
|
}.should raise_error(SystemExit)
|
399
393
|
end
|
@@ -402,14 +396,14 @@ OUT
|
|
402
396
|
$stdout.should_receive(:puts).with("\e[32mAdding remote production git@git.shellycloud.com:foooo.git\e[0m")
|
403
397
|
@app.should_receive(:add_git_remote)
|
404
398
|
fake_stdin(["foooo", ""]) do
|
405
|
-
@main
|
399
|
+
invoke(@main, :add)
|
406
400
|
end
|
407
401
|
end
|
408
402
|
|
409
403
|
it "should create Cloudfile" do
|
410
404
|
File.exists?("/projects/foo/Cloudfile").should be_false
|
411
405
|
fake_stdin(["foooo", ""]) do
|
412
|
-
@main
|
406
|
+
invoke(@main, :add)
|
413
407
|
end
|
414
408
|
File.read("/projects/foo/Cloudfile").should == "Example Cloudfile"
|
415
409
|
end
|
@@ -418,7 +412,7 @@ OUT
|
|
418
412
|
$stdout.should_receive(:puts).with("\e[32mProvide billing details. Opening browser...\e[0m")
|
419
413
|
@app.should_receive(:open_billing_page)
|
420
414
|
fake_stdin(["foooo", ""]) do
|
421
|
-
@main
|
415
|
+
invoke(@main, :add)
|
422
416
|
end
|
423
417
|
end
|
424
418
|
|
@@ -427,7 +421,7 @@ OUT
|
|
427
421
|
$stdout.should_receive(:puts).with("\e[32mYou can review changes using\e[0m")
|
428
422
|
$stdout.should_receive(:puts).with(" git status")
|
429
423
|
fake_stdin(["foooo", "none"]) do
|
430
|
-
@main
|
424
|
+
invoke(@main, :add)
|
431
425
|
end
|
432
426
|
end
|
433
427
|
|
@@ -439,7 +433,7 @@ OUT
|
|
439
433
|
$stdout.should_receive(:puts).with("\e[32mDeploy to production using:\e[0m")
|
440
434
|
$stdout.should_receive(:puts).with(" git push production master")
|
441
435
|
fake_stdin(["foooo", "none"]) do
|
442
|
-
@main
|
436
|
+
invoke(@main, :add)
|
443
437
|
end
|
444
438
|
end
|
445
439
|
end
|
@@ -457,19 +451,19 @@ OUT
|
|
457
451
|
$stdout.should_receive(:puts).with("\e[32mYou have following clouds available:\e[0m")
|
458
452
|
$stdout.should_receive(:puts).with(/abc\s+\| running/)
|
459
453
|
$stdout.should_receive(:puts).with(/fooo\s+\| deploy failed \(Support has been notified\)/)
|
460
|
-
@main
|
454
|
+
invoke(@main, :list)
|
461
455
|
end
|
462
456
|
|
463
457
|
it "should display info that user has no clouds" do
|
464
458
|
@client.stub(:apps).and_return([])
|
465
459
|
$stdout.should_receive(:puts).with("\e[32mYou have no clouds yet\e[0m")
|
466
|
-
@main
|
460
|
+
invoke(@main, :list)
|
467
461
|
end
|
468
462
|
|
469
463
|
it "should have a 'status' alias" do
|
470
464
|
@client.stub(:apps).and_return([])
|
471
465
|
$stdout.should_receive(:puts).with("\e[32mYou have no clouds yet\e[0m")
|
472
|
-
|
466
|
+
invoke(@main, :status)
|
473
467
|
end
|
474
468
|
|
475
469
|
context "on failure" do
|
@@ -477,9 +471,10 @@ OUT
|
|
477
471
|
body = {"message" => "Unauthorized"}
|
478
472
|
error = Shelly::Client::APIError.new(body.to_json, 401)
|
479
473
|
@client.stub(:token).and_raise(error)
|
480
|
-
$stdout.should_receive(:puts).with("
|
474
|
+
$stdout.should_receive(:puts).with(red "You are not logged in. To log in use:")
|
475
|
+
$stdout.should_receive(:puts).with(" shelly login")
|
481
476
|
lambda {
|
482
|
-
@main
|
477
|
+
invoke(@main, :list)
|
483
478
|
}.should raise_error(SystemExit)
|
484
479
|
end
|
485
480
|
end
|
@@ -502,7 +497,7 @@ OUT
|
|
502
497
|
File.delete("Cloudfile")
|
503
498
|
$stdout.should_receive(:puts).with("\e[31mNo Cloudfile found\e[0m")
|
504
499
|
lambda {
|
505
|
-
@main
|
500
|
+
invoke(@main, :start)
|
506
501
|
}.should raise_error(SystemExit)
|
507
502
|
end
|
508
503
|
|
@@ -511,7 +506,7 @@ OUT
|
|
511
506
|
exception = Shelly::Client::APIError.new(response.to_json, 404)
|
512
507
|
@client.stub(:start_cloud).and_raise(exception)
|
513
508
|
$stdout.should_receive(:puts).with(red "You have no access to 'foo-production' cloud defined in Cloudfile")
|
514
|
-
lambda { @main
|
509
|
+
lambda { invoke(@main, :start) }.should raise_error(SystemExit)
|
515
510
|
end
|
516
511
|
|
517
512
|
it "should exit if user is not logged in" do
|
@@ -520,7 +515,7 @@ OUT
|
|
520
515
|
@client.stub(:token).and_raise(exception)
|
521
516
|
$stdout.should_receive(:puts).with(red "You are not logged in. To log in use:")
|
522
517
|
$stdout.should_receive(:puts).with(" shelly login")
|
523
|
-
lambda { @main
|
518
|
+
lambda { invoke(@main, :start) }.should raise_error(SystemExit)
|
524
519
|
end
|
525
520
|
|
526
521
|
context "single cloud in Cloudfile" do
|
@@ -528,7 +523,7 @@ OUT
|
|
528
523
|
@client.stub(:start_cloud)
|
529
524
|
$stdout.should_receive(:puts).with(green "Starting cloud foo-production. Check status with:")
|
530
525
|
$stdout.should_receive(:puts).with(" shelly list")
|
531
|
-
@main
|
526
|
+
invoke(@main, :start)
|
532
527
|
end
|
533
528
|
end
|
534
529
|
|
@@ -543,7 +538,7 @@ OUT
|
|
543
538
|
$stdout.should_receive(:puts).with("Available clouds:")
|
544
539
|
$stdout.should_receive(:puts).with(" * foo-production")
|
545
540
|
$stdout.should_receive(:puts).with(" * foo-staging")
|
546
|
-
lambda { @main
|
541
|
+
lambda { invoke(@main, :start) }.should raise_error(SystemExit)
|
547
542
|
end
|
548
543
|
|
549
544
|
it "should fetch from command line which cloud to start" do
|
@@ -551,7 +546,7 @@ OUT
|
|
551
546
|
$stdout.should_receive(:puts).with(green "Starting cloud foo-staging. Check status with:")
|
552
547
|
$stdout.should_receive(:puts).with(" shelly list")
|
553
548
|
@main.options = {:cloud => "foo-staging"}
|
554
|
-
@main
|
549
|
+
invoke(@main, :start)
|
555
550
|
end
|
556
551
|
end
|
557
552
|
|
@@ -559,14 +554,14 @@ OUT
|
|
559
554
|
it "should show information that cloud is running" do
|
560
555
|
raise_conflict(:state => "running")
|
561
556
|
$stdout.should_receive(:puts).with(red "Not starting: cloud 'foo-production' is already running")
|
562
|
-
lambda { @main
|
557
|
+
lambda { invoke(@main, :start) }.should raise_error(SystemExit)
|
563
558
|
end
|
564
559
|
|
565
560
|
%w{deploying configuring}.each do |state|
|
566
561
|
it "should show information that cloud is #{state}" do
|
567
562
|
raise_conflict(:state => state)
|
568
563
|
$stdout.should_receive(:puts).with(red "Not starting: cloud 'foo-production' is currently deploying")
|
569
|
-
lambda { @main
|
564
|
+
lambda { invoke(@main, :start) }.should raise_error(SystemExit)
|
570
565
|
end
|
571
566
|
end
|
572
567
|
|
@@ -575,7 +570,7 @@ OUT
|
|
575
570
|
$stdout.should_receive(:puts).with(red "Not starting: no source code provided")
|
576
571
|
$stdout.should_receive(:puts).with(red "Push source code using:")
|
577
572
|
$stdout.should_receive(:puts).with(" git push production master")
|
578
|
-
lambda { @main
|
573
|
+
lambda { invoke(@main, :start) }.should raise_error(SystemExit)
|
579
574
|
end
|
580
575
|
|
581
576
|
%w{deploy_failed configuration_failed}.each do |state|
|
@@ -584,14 +579,14 @@ OUT
|
|
584
579
|
$stdout.should_receive(:puts).with(red "Not starting: deployment failed")
|
585
580
|
$stdout.should_receive(:puts).with(red "Support has been notified")
|
586
581
|
$stdout.should_receive(:puts).with(red "See http://example.com/logs for reasons of failure")
|
587
|
-
lambda { @main
|
582
|
+
lambda { invoke(@main, :start) }.should raise_error(SystemExit)
|
588
583
|
end
|
589
584
|
end
|
590
585
|
it "should open billing page" do
|
591
586
|
raise_conflict(:state => "no_billing")
|
592
587
|
$stdout.should_receive(:puts).with(red "Please fill in billing details to start foo-production. Opening browser.")
|
593
588
|
@app.should_receive(:open_billing_page)
|
594
|
-
lambda { @main
|
589
|
+
lambda { invoke(@main, :start) }.should raise_error(SystemExit)
|
595
590
|
end
|
596
591
|
|
597
592
|
def raise_conflict(options = {})
|
@@ -620,7 +615,7 @@ OUT
|
|
620
615
|
File.delete("Cloudfile")
|
621
616
|
$stdout.should_receive(:puts).with("\e[31mNo Cloudfile found\e[0m")
|
622
617
|
lambda {
|
623
|
-
@main
|
618
|
+
invoke(@main, :stop)
|
624
619
|
}.should raise_error(SystemExit)
|
625
620
|
end
|
626
621
|
|
@@ -629,7 +624,7 @@ OUT
|
|
629
624
|
exception = Shelly::Client::APIError.new(response.to_json, 404)
|
630
625
|
@client.stub(:stop_cloud).and_raise(exception)
|
631
626
|
$stdout.should_receive(:puts).with(red "You have no access to 'foo-production' cloud defined in Cloudfile")
|
632
|
-
lambda { @main
|
627
|
+
lambda { invoke(@main, :stop) }.should raise_error(SystemExit)
|
633
628
|
end
|
634
629
|
|
635
630
|
it "should exit if user is not logged in" do
|
@@ -638,14 +633,14 @@ OUT
|
|
638
633
|
@client.stub(:token).and_raise(exception)
|
639
634
|
$stdout.should_receive(:puts).with(red "You are not logged in. To log in use:")
|
640
635
|
$stdout.should_receive(:puts).with(" shelly login")
|
641
|
-
lambda { @main
|
636
|
+
lambda { invoke(@main, :stop) }.should raise_error(SystemExit)
|
642
637
|
end
|
643
638
|
|
644
639
|
context "single cloud in Cloudfile" do
|
645
640
|
it "should start the cloud" do
|
646
641
|
@client.stub(:stop_cloud)
|
647
642
|
$stdout.should_receive(:puts).with("Cloud 'foo-production' stopped")
|
648
|
-
@main
|
643
|
+
invoke(@main, :stop)
|
649
644
|
end
|
650
645
|
end
|
651
646
|
|
@@ -660,14 +655,14 @@ OUT
|
|
660
655
|
$stdout.should_receive(:puts).with("Available clouds:")
|
661
656
|
$stdout.should_receive(:puts).with(" * foo-production")
|
662
657
|
$stdout.should_receive(:puts).with(" * foo-staging")
|
663
|
-
lambda { @main
|
658
|
+
lambda { invoke(@main, :stop) }.should raise_error(SystemExit)
|
664
659
|
end
|
665
660
|
|
666
661
|
it "should fetch from command line which cloud to start" do
|
667
662
|
@client.should_receive(:stop_cloud).with("foo-staging")
|
668
663
|
$stdout.should_receive(:puts).with("Cloud 'foo-staging' stopped")
|
669
664
|
@main.options = {:cloud => "foo-staging"}
|
670
|
-
@main
|
665
|
+
invoke(@main, :stop)
|
671
666
|
end
|
672
667
|
end
|
673
668
|
end
|
@@ -678,29 +673,21 @@ OUT
|
|
678
673
|
Shelly::App.stub(:inside_git_repository?).and_return(true)
|
679
674
|
end
|
680
675
|
|
681
|
-
it "should exit with message if command run outside git repository" do
|
682
|
-
Shelly::App.stub(:inside_git_repository?).and_return(false)
|
683
|
-
$stdout.should_receive(:puts).with("\e[31mMust be run inside your project git repository\e[0m")
|
684
|
-
lambda {
|
685
|
-
@main.ip
|
686
|
-
}.should raise_error(SystemExit)
|
687
|
-
end
|
688
|
-
|
689
676
|
it "should exit with message if there is no Cloudfile" do
|
690
677
|
File.delete("Cloudfile")
|
691
678
|
$stdout.should_receive(:puts).with("\e[31mNo Cloudfile found\e[0m")
|
692
679
|
lambda {
|
693
|
-
@main
|
680
|
+
invoke(@main, :ip)
|
694
681
|
}.should raise_error(SystemExit)
|
695
682
|
end
|
696
683
|
|
697
684
|
context "on success" do
|
698
685
|
it "should display mail and web server ip's" do
|
699
|
-
@client.stub(:
|
686
|
+
@client.stub(:app).and_return(response)
|
700
687
|
$stdout.should_receive(:puts).with("\e[32mCloud foo-production:\e[0m")
|
701
688
|
$stdout.should_receive(:puts).with(" Web server IP: 22.22.22.22")
|
702
689
|
$stdout.should_receive(:puts).with(" Mail server IP: 11.11.11.11")
|
703
|
-
@main
|
690
|
+
invoke(@main, :ip)
|
704
691
|
end
|
705
692
|
end
|
706
693
|
|
@@ -709,18 +696,12 @@ OUT
|
|
709
696
|
end
|
710
697
|
|
711
698
|
context "on failure" do
|
712
|
-
it "should raise an error if user is not in git repository" do
|
713
|
-
Shelly::App.stub(:inside_git_repository?).and_return(false)
|
714
|
-
$stdout.should_receive(:puts).with("\e[31mMust be run inside your project git repository\e[0m")
|
715
|
-
lambda { @main.ip }.should raise_error(SystemExit)
|
716
|
-
end
|
717
|
-
|
718
699
|
it "should raise an error if user does not have access to cloud" do
|
719
700
|
response = {"message" => "Cloud foo-staging not found"}
|
720
701
|
exception = Shelly::Client::APIError.new(response.to_json, 404)
|
721
|
-
@client.stub(:
|
702
|
+
@client.stub(:app).and_raise(exception)
|
722
703
|
$stdout.should_receive(:puts).with(red "You have no access to 'foo-staging' cloud defined in Cloudfile")
|
723
|
-
@main
|
704
|
+
invoke(@main, :ip)
|
724
705
|
end
|
725
706
|
end
|
726
707
|
end
|
@@ -753,9 +734,9 @@ OUT
|
|
753
734
|
$stdout.should_receive(:puts).with("\n")
|
754
735
|
$stdout.should_receive(:puts).with("Scheduling application delete - done")
|
755
736
|
$stdout.should_receive(:puts).with("Removing git remote - done")
|
737
|
+
@main.options = {:cloud => "foo-staging"}
|
756
738
|
fake_stdin(["yes", "yes", "yes"]) do
|
757
|
-
@main
|
758
|
-
@main.delete
|
739
|
+
invoke(@main, :delete)
|
759
740
|
end
|
760
741
|
end
|
761
742
|
|
@@ -763,8 +744,7 @@ OUT
|
|
763
744
|
@app.should_not_receive(:delete)
|
764
745
|
lambda{
|
765
746
|
fake_stdin(["yes", "yes", "no"]) do
|
766
|
-
@main
|
767
|
-
@main.delete
|
747
|
+
invoke(@main, :delete, "--cloud", "foo-staging")
|
768
748
|
end
|
769
749
|
}.should raise_error(SystemExit)
|
770
750
|
end
|
@@ -780,8 +760,7 @@ OUT
|
|
780
760
|
Shelly::App.stub(:inside_git_repository?).and_return(false)
|
781
761
|
$stdout.should_receive(:puts).with("Missing git remote")
|
782
762
|
fake_stdin(["yes", "yes", "yes"]) do
|
783
|
-
@main
|
784
|
-
@main.delete
|
763
|
+
invoke(@main, :delete, "--cloud", "foo-staging")
|
785
764
|
end
|
786
765
|
end
|
787
766
|
end
|
@@ -799,8 +778,7 @@ OUT
|
|
799
778
|
$stdout.should_receive(:puts).with("\e[31mApplication not found\e[0m")
|
800
779
|
lambda{
|
801
780
|
fake_stdin(["yes", "yes", "yes"]) do
|
802
|
-
@main
|
803
|
-
@main.delete
|
781
|
+
invoke(@main, :delete, "--cloud", "foo-bar")
|
804
782
|
end
|
805
783
|
}.should raise_error(SystemExit)
|
806
784
|
end
|
@@ -824,7 +802,7 @@ OUT
|
|
824
802
|
$stdout.should_receive(:puts).with("Scheduling application delete - done")
|
825
803
|
$stdout.should_receive(:puts).with("Removing git remote - done")
|
826
804
|
fake_stdin(["yes", "yes", "yes"]) do
|
827
|
-
@main
|
805
|
+
invoke(@main, :delete)
|
828
806
|
end
|
829
807
|
end
|
830
808
|
end
|
@@ -848,7 +826,7 @@ OUT
|
|
848
826
|
File.delete("Cloudfile")
|
849
827
|
$stdout.should_receive(:puts).with("\e[31mNo Cloudfile found\e[0m")
|
850
828
|
lambda {
|
851
|
-
@main
|
829
|
+
invoke(@main, :logs)
|
852
830
|
}.should raise_error(SystemExit)
|
853
831
|
end
|
854
832
|
|
@@ -858,7 +836,7 @@ OUT
|
|
858
836
|
@client.stub(:application_logs).and_raise(exception)
|
859
837
|
$stdout.should_receive(:puts).
|
860
838
|
with(red "You have no access to cloud 'foo-production'")
|
861
|
-
lambda { @main
|
839
|
+
lambda { invoke(@main, :logs) }.should raise_error(SystemExit)
|
862
840
|
end
|
863
841
|
|
864
842
|
it "should exit if user is not logged in" do
|
@@ -868,7 +846,7 @@ OUT
|
|
868
846
|
$stdout.should_receive(:puts).
|
869
847
|
with(red "You are not logged in. To log in use:")
|
870
848
|
$stdout.should_receive(:puts).with(" shelly login")
|
871
|
-
lambda { @main
|
849
|
+
lambda { invoke(@main, :logs) }.should raise_error(SystemExit)
|
872
850
|
end
|
873
851
|
|
874
852
|
context "single cloud in Cloudfile" do
|
@@ -877,7 +855,7 @@ OUT
|
|
877
855
|
$stdout.should_receive(:puts).with(green "Cloud foo-production:")
|
878
856
|
$stdout.should_receive(:puts).with(green "Instance 1:")
|
879
857
|
$stdout.should_receive(:puts).with("log1")
|
880
|
-
@main
|
858
|
+
invoke(@main, :logs)
|
881
859
|
end
|
882
860
|
end
|
883
861
|
|
@@ -894,7 +872,7 @@ OUT
|
|
894
872
|
$stdout.should_receive(:puts).with("Available clouds:")
|
895
873
|
$stdout.should_receive(:puts).with(" * foo-production")
|
896
874
|
$stdout.should_receive(:puts).with(" * foo-staging")
|
897
|
-
lambda { @main
|
875
|
+
lambda { invoke(@main, :logs) }.should raise_error(SystemExit)
|
898
876
|
end
|
899
877
|
|
900
878
|
it "should fetch from command line which cloud to start" do
|
@@ -904,7 +882,7 @@ OUT
|
|
904
882
|
$stdout.should_receive(:puts).with(green "Instance 1:")
|
905
883
|
$stdout.should_receive(:puts).with("log1")
|
906
884
|
@main.options = {:cloud => "foo-staging"}
|
907
|
-
@main
|
885
|
+
invoke(@main, :logs)
|
908
886
|
end
|
909
887
|
end
|
910
888
|
|
@@ -916,7 +894,7 @@ OUT
|
|
916
894
|
$stdout.should_receive(:puts).with("log1")
|
917
895
|
$stdout.should_receive(:puts).with(green "Instance 2:")
|
918
896
|
$stdout.should_receive(:puts).with("log2")
|
919
|
-
@main
|
897
|
+
invoke(@main, :logs)
|
920
898
|
end
|
921
899
|
end
|
922
900
|
end
|