shelly 0.1.24 → 0.1.25
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/CHANGELOG.md +5 -0
- data/lib/shelly/app.rb +36 -3
- data/lib/shelly/cli/backup.rb +4 -3
- data/lib/shelly/cli/main.rb +33 -3
- data/lib/shelly/cli/runner.rb +1 -1
- data/lib/shelly/cloudfile.rb +3 -17
- data/lib/shelly/helpers.rb +1 -3
- data/lib/shelly/version.rb +1 -1
- data/spec/shelly/app_spec.rb +45 -2
- data/spec/shelly/cli/backup_spec.rb +6 -4
- data/spec/shelly/cli/files_spec.rb +1 -1
- data/spec/shelly/cli/main_spec.rb +62 -4
- data/spec/shelly/cli/runner_spec.rb +1 -1
- data/spec/shelly/cli/user_spec.rb +0 -1
- data/spec/shelly/cloudfile_spec.rb +62 -26
- data/spec/spec_helper.rb +1 -0
- metadata +54 -3
data/CHANGELOG.md
CHANGED
data/lib/shelly/app.rb
CHANGED
@@ -9,10 +9,12 @@ module Shelly
|
|
9
9
|
SERVER_SIZES = %w(small large)
|
10
10
|
|
11
11
|
attr_accessor :code_name, :databases, :ruby_version, :environment,
|
12
|
-
:git_url, :domains, :web_server_ip, :size, :thin, :redeem_code
|
12
|
+
:git_url, :domains, :web_server_ip, :size, :thin, :redeem_code,
|
13
|
+
:content
|
13
14
|
|
14
|
-
def initialize(code_name = nil)
|
15
|
+
def initialize(code_name = nil, content = nil)
|
15
16
|
self.code_name = code_name
|
17
|
+
self.content = content
|
16
18
|
end
|
17
19
|
|
18
20
|
def databases=(dbs)
|
@@ -117,7 +119,7 @@ module Shelly
|
|
117
119
|
guessed = nil
|
118
120
|
cloudfile = Cloudfile.new
|
119
121
|
if cloudfile.present?
|
120
|
-
clouds = cloudfile.clouds
|
122
|
+
clouds = cloudfile.clouds.map(&:code_name)
|
121
123
|
if clouds.grep(/staging/).present?
|
122
124
|
guessed = "production"
|
123
125
|
production_clouds = clouds.grep(/production/)
|
@@ -236,8 +238,39 @@ module Shelly
|
|
236
238
|
rsync(source, destination)
|
237
239
|
end
|
238
240
|
|
241
|
+
# Public: Return databases for given Cloud in Cloudfile
|
242
|
+
# Returns Array of databases
|
243
|
+
def cloud_databases
|
244
|
+
content["servers"].map do |server, settings|
|
245
|
+
settings["databases"]
|
246
|
+
end.flatten.uniq
|
247
|
+
end
|
248
|
+
|
249
|
+
# Public: Delayed job enabled?
|
250
|
+
# Returns true if delayed job is present
|
251
|
+
def delayed_job?
|
252
|
+
option?("delayed_job")
|
253
|
+
end
|
254
|
+
|
255
|
+
# Public: Whenever enabled?
|
256
|
+
# Returns true if whenever is present
|
257
|
+
def whenever?
|
258
|
+
option?("whenever")
|
259
|
+
end
|
260
|
+
|
261
|
+
# Public: Return databases to backup for given Cloud in Cloudfile
|
262
|
+
# Returns Array of databases, except redis db
|
263
|
+
def backup_databases
|
264
|
+
cloud_databases - ['redis']
|
265
|
+
end
|
266
|
+
|
239
267
|
private
|
240
268
|
|
269
|
+
# Internal: Checks if specified option is present in Cloudfile
|
270
|
+
def option?(option)
|
271
|
+
content["servers"].any? {|_, settings| settings.has_key?(option)}
|
272
|
+
end
|
273
|
+
|
241
274
|
def ssh
|
242
275
|
@ssh ||= shelly.console(code_name)
|
243
276
|
end
|
data/lib/shelly/cli/backup.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "shelly/cli/command"
|
2
2
|
require "shelly/backup"
|
3
3
|
require "shelly/download_progress_bar"
|
4
|
+
require 'launchy'
|
4
5
|
|
5
6
|
module Shelly
|
6
7
|
module CLI
|
@@ -19,14 +20,14 @@ module Shelly
|
|
19
20
|
app = multiple_clouds(options[:cloud], "backup list")
|
20
21
|
backups = app.database_backups
|
21
22
|
if backups.present?
|
22
|
-
limit =
|
23
|
+
limit = 0
|
23
24
|
unless options[:all] || backups.count < (Shelly::Backup::LIMIT + 1)
|
24
25
|
limit = Shelly::Backup::LIMIT - 1
|
25
26
|
say "Limiting the number of backups to #{Shelly::Backup::LIMIT}."
|
26
27
|
say "Use --all or -a option to list all backups."
|
27
28
|
end
|
28
29
|
to_display = [["Filename", "| Size", "| State"]]
|
29
|
-
backups[
|
30
|
+
backups[-limit..-1].each do |backup|
|
30
31
|
to_display << [backup.filename, "| #{backup.human_size}", "| #{backup.state.humanize}"]
|
31
32
|
end
|
32
33
|
|
@@ -70,7 +71,7 @@ module Shelly
|
|
70
71
|
say_error "Cloudfile must be present in current working directory or specify database kind with:", :with_exit => false
|
71
72
|
say_error "`shelly backup create DB_KIND`"
|
72
73
|
end
|
73
|
-
app.request_backup(kind ||
|
74
|
+
app.request_backup(kind || app.backup_databases)
|
74
75
|
say "Backup requested. It can take up to several minutes for " +
|
75
76
|
"the backup process to finish.", :green
|
76
77
|
rescue Client::ValidationException => e
|
data/lib/shelly/cli/main.rb
CHANGED
@@ -384,6 +384,10 @@ We have been notified about it. We will be adding new resources shortly}
|
|
384
384
|
"Gemfile.lock is missing in git repository",
|
385
385
|
:show_fulfilled => verbose)
|
386
386
|
|
387
|
+
print_check(structure.config_ru?, "File config.ru is present",
|
388
|
+
"File config.ru is missing",
|
389
|
+
:show_fulfilled => verbose)
|
390
|
+
|
387
391
|
print_check(structure.gem?("shelly-dependencies"),
|
388
392
|
"Gem 'shelly-dependencies' is present",
|
389
393
|
"Gem 'shelly-dependencies' is missing, we recommend to install it\n See more at https://shellycloud.com/documentation/requirements#shelly-dependencies",
|
@@ -395,9 +399,35 @@ We have been notified about it. We will be adding new resources shortly}
|
|
395
399
|
print_check(structure.gem?("rake"), "Gem 'rake' is present",
|
396
400
|
"Gem 'rake' is missing in the Gemfile", :show_fulfilled => verbose)
|
397
401
|
|
398
|
-
|
399
|
-
|
400
|
-
:show_fulfilled => verbose)
|
402
|
+
|
403
|
+
print_check(structure.gem?("rake"), "Gem 'rake' is present",
|
404
|
+
"Gem 'rake' is missing in the Gemfile", :show_fulfilled => verbose)
|
405
|
+
|
406
|
+
cloudfile = Cloudfile.new
|
407
|
+
if cloudfile.present?
|
408
|
+
cloudfile.clouds.each do |cloud|
|
409
|
+
if cloud.databases.include?('postgresql')
|
410
|
+
print_check(structure.gem?("pg") || structure.gem?("postgres"),
|
411
|
+
"Postgresql driver is present for '#{cloud}' cloud",
|
412
|
+
"Postgresql driver is missing in the Gemfile for '#{cloud}' cloud,\n we recommend adding 'pg' gem to Gemfile",
|
413
|
+
:show_fulfilled => verbose)
|
414
|
+
end
|
415
|
+
|
416
|
+
if cloud.delayed_job?
|
417
|
+
print_check(structure.gem?("delayed_job"),
|
418
|
+
"Gem 'delayed_job' is present for '#{cloud}' cloud",
|
419
|
+
"Gem 'delayed_job' is missing in the Gemfile for '#{cloud}' cloud",
|
420
|
+
:show_fulfilled => verbose)
|
421
|
+
end
|
422
|
+
|
423
|
+
if cloud.whenever?
|
424
|
+
print_check(structure.gem?("whenever"),
|
425
|
+
"Gem 'whenever' is present for '#{cloud}' cloud",
|
426
|
+
"Gem 'whenever' is missing in the Gemfile for '#{cloud}' cloud",
|
427
|
+
:show_fulfilled => verbose)
|
428
|
+
end
|
429
|
+
end
|
430
|
+
end
|
401
431
|
|
402
432
|
print_check(!structure.gem?("mysql") && !structure.gem?("mysql2"),"",
|
403
433
|
"mysql driver present in the Gemfile (not supported on Shelly Cloud)",
|
data/lib/shelly/cli/runner.rb
CHANGED
@@ -23,7 +23,7 @@ module Shelly
|
|
23
23
|
say_error "You are not logged in. To log in use: `shelly login`"
|
24
24
|
rescue Client::NotFoundException => e
|
25
25
|
raise if debug? or e.resource != :cloud
|
26
|
-
say_error "You have no access to '#{e.id}' cloud
|
26
|
+
say_error "You have no access to '#{e.id}' cloud"
|
27
27
|
rescue Client::GemVersionException => e
|
28
28
|
raise if debug?
|
29
29
|
say "Required shelly gem version: #{e.body["required_version"]}"
|
data/lib/shelly/cloudfile.rb
CHANGED
@@ -16,7 +16,9 @@ module Shelly
|
|
16
16
|
# Returns Array of clouds names from Cloudfile
|
17
17
|
# nil if there is no cloudfile
|
18
18
|
def clouds
|
19
|
-
content.keys.sort
|
19
|
+
content.keys.sort.map do |code_name|
|
20
|
+
Shelly::App.new(code_name, content[code_name.to_s])
|
21
|
+
end if content
|
20
22
|
end
|
21
23
|
|
22
24
|
# Public: Generate example Cloudfile based on object attributes
|
@@ -35,22 +37,6 @@ module Shelly
|
|
35
37
|
File.open(path, "a+") { |f| f << generate }
|
36
38
|
end
|
37
39
|
|
38
|
-
# Public: Return databases for given Cloud in Cloudfile
|
39
|
-
# Returns Array of databases
|
40
|
-
def databases(cloud)
|
41
|
-
content[cloud.to_s]["servers"].map do |server, settings|
|
42
|
-
settings["databases"]
|
43
|
-
end.flatten.uniq
|
44
|
-
end
|
45
|
-
|
46
|
-
# Public: Return databases to backup for given Cloud in Cloudfile
|
47
|
-
# Returns Array of databases, except redis db
|
48
|
-
def backup_databases(cloud)
|
49
|
-
databases(cloud) - ['redis']
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
40
|
# Internal: Load and parse Cloudfile
|
55
41
|
def content
|
56
42
|
return unless present?
|
data/lib/shelly/helpers.rb
CHANGED
@@ -115,9 +115,7 @@ More info at http://git-scm.com/book/en/Git-Basics-Getting-a-Git-Repository}
|
|
115
115
|
exit 1
|
116
116
|
end
|
117
117
|
|
118
|
-
|
119
|
-
app.code_name = cloud || clouds.first
|
120
|
-
app
|
118
|
+
cloud ? Shelly::App.new(cloud) : clouds.first
|
121
119
|
end
|
122
120
|
|
123
121
|
def print_logs(logs)
|
data/lib/shelly/version.rb
CHANGED
data/spec/shelly/app_spec.rb
CHANGED
@@ -7,8 +7,7 @@ describe Shelly::App do
|
|
7
7
|
Dir.chdir("/projects/foo")
|
8
8
|
@client = mock(:api_url => "https://api.example.com", :shellyapp_url => "http://shellyapp.example.com")
|
9
9
|
Shelly::Client.stub(:new).and_return(@client)
|
10
|
-
@app = Shelly::App.new
|
11
|
-
@app.code_name = "foo-staging"
|
10
|
+
@app = Shelly::App.new('foo-staging')
|
12
11
|
end
|
13
12
|
|
14
13
|
describe ".guess_code_name" do
|
@@ -394,4 +393,48 @@ describe Shelly::App do
|
|
394
393
|
@app.create_cloudfile
|
395
394
|
end
|
396
395
|
end
|
396
|
+
|
397
|
+
describe "#databases" do
|
398
|
+
before do
|
399
|
+
content = {"servers" => {"app1" => {"databases" => ["postgresql", "redis"]},
|
400
|
+
"app2" => {"databases" => ["mongodb"]}}}
|
401
|
+
@app.stub(:content).and_return(content)
|
402
|
+
end
|
403
|
+
|
404
|
+
it "should return databases in cloudfile" do
|
405
|
+
@app.cloud_databases.should =~ ['redis', 'mongodb', 'postgresql']
|
406
|
+
end
|
407
|
+
|
408
|
+
it "should return databases except for redis" do
|
409
|
+
@app.backup_databases.should =~ ['postgresql', 'mongodb']
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
describe "#delayed_job?" do
|
414
|
+
it "should return true if present" do
|
415
|
+
content = {"servers" => {"app1" => {"delayed_job" => 1}}}
|
416
|
+
@app.stub(:content).and_return(content)
|
417
|
+
@app.delayed_job?.should be_true
|
418
|
+
end
|
419
|
+
|
420
|
+
it "should retrun false if not present" do
|
421
|
+
content = {"servers" => {"app1" => {"size" => "small"}}}
|
422
|
+
@app.stub(:content).and_return(content)
|
423
|
+
@app.delayed_job?.should be_false
|
424
|
+
end
|
425
|
+
end
|
426
|
+
|
427
|
+
describe "#whenever?" do
|
428
|
+
it "should return true if present" do
|
429
|
+
content = {"servers" => {"app1" => {"whenever" => true}}}
|
430
|
+
@app.stub(:content).and_return(content)
|
431
|
+
@app.whenever?.should be_true
|
432
|
+
end
|
433
|
+
|
434
|
+
it "should return false if not present" do
|
435
|
+
content = {"servers" => {"app1" => {"size" => "small"}}}
|
436
|
+
@app.stub(:content).and_return(content)
|
437
|
+
@app.whenever?.should be_false
|
438
|
+
end
|
439
|
+
end
|
397
440
|
end
|
@@ -135,7 +135,9 @@ describe Shelly::CLI::Backup do
|
|
135
135
|
FileUtils.mkdir_p("/projects/foo")
|
136
136
|
Dir.chdir("/projects/foo")
|
137
137
|
$stdout.stub(:puts)
|
138
|
-
@
|
138
|
+
@app = mock(:backup_databases => ['postgresql', 'mongodb'], :code_name => "foo-staging")
|
139
|
+
Shelly::App.stub(:new).and_return(@app)
|
140
|
+
@cloudfile = mock(:present? => true, :clouds => [@app])
|
139
141
|
Shelly::Cloudfile.stub(:new).and_return(@cloudfile)
|
140
142
|
end
|
141
143
|
|
@@ -145,7 +147,7 @@ describe Shelly::CLI::Backup do
|
|
145
147
|
|
146
148
|
# multiple_clouds is tested in main_spec.rb in describe "#start" block
|
147
149
|
it "should ensure multiple_clouds check" do
|
148
|
-
@
|
150
|
+
@app.stub(:request_backup)
|
149
151
|
@backup.should_receive(:multiple_clouds).and_return(@app)
|
150
152
|
invoke(@backup, :create)
|
151
153
|
end
|
@@ -153,7 +155,7 @@ describe Shelly::CLI::Backup do
|
|
153
155
|
it "should display errors and exit 1 when kind is not valid" do
|
154
156
|
response = {"errors" => [["kind", "is invalid"]]}
|
155
157
|
exception = Shelly::Client::ValidationException.new(response)
|
156
|
-
@
|
158
|
+
@app.should_receive(:request_backup).and_raise(exception)
|
157
159
|
$stdout.should_receive(:puts).with(red "Kind is invalid")
|
158
160
|
lambda { invoke(@backup, :create) }.should raise_error(SystemExit)
|
159
161
|
end
|
@@ -169,7 +171,7 @@ describe Shelly::CLI::Backup do
|
|
169
171
|
end
|
170
172
|
|
171
173
|
it "should display information about request backup" do
|
172
|
-
@
|
174
|
+
@app.stub(:request_backup)
|
173
175
|
$stdout.should_receive(:puts).with(green "Backup requested. It can take up to several minutes for " +
|
174
176
|
"the backup process to finish.")
|
175
177
|
invoke(@backup, :create)
|
@@ -10,7 +10,7 @@ describe Shelly::CLI::Files do
|
|
10
10
|
@client.stub(:token).and_return("abc")
|
11
11
|
FileUtils.mkdir_p("/projects/foo")
|
12
12
|
Dir.chdir("/projects/foo")
|
13
|
-
@app = Shelly::App.new("foo-
|
13
|
+
@app = Shelly::App.new("foo-production")
|
14
14
|
Shelly::App.stub(:new).and_return(@app)
|
15
15
|
File.open("Cloudfile", 'w') { |f| f.write("foo-production:\n") }
|
16
16
|
end
|
@@ -615,7 +615,9 @@ More info at http://git-scm.com/book/en/Git-Basics-Getting-a-Git-Repository\e[0m
|
|
615
615
|
# this tests multiple_clouds method used in majority of tasks
|
616
616
|
context "multiple clouds in Cloudfile" do
|
617
617
|
before do
|
618
|
-
|
618
|
+
Shelly::App.unstub(:new)
|
619
|
+
File.open("Cloudfile", 'w') {|f|
|
620
|
+
f.write("foo-staging:\nfoo-production:\n") }
|
619
621
|
end
|
620
622
|
|
621
623
|
it "should show information to start specific cloud and exit" do
|
@@ -709,7 +711,7 @@ We have been notified about it. We will be adding new resources shortly")
|
|
709
711
|
File.open("Cloudfile", 'w') {|f| f.write("foo-production:\n") }
|
710
712
|
Shelly::User.stub(:new).and_return(@user)
|
711
713
|
@client.stub(:apps).and_return([{"code_name" => "foo-production"}, {"code_name" => "foo-staging"}])
|
712
|
-
@app = Shelly::App.new
|
714
|
+
@app = Shelly::App.new("foo-production")
|
713
715
|
Shelly::App.stub(:new).and_return(@app)
|
714
716
|
end
|
715
717
|
|
@@ -942,7 +944,7 @@ We have been notified about it. We will be adding new resources shortly")
|
|
942
944
|
before do
|
943
945
|
Shelly::App.stub(:inside_git_repository?).and_return(true)
|
944
946
|
@user = Shelly::User.new
|
945
|
-
@app = Shelly::App.new
|
947
|
+
@app = Shelly::App.new('foo-staging')
|
946
948
|
@client.stub(:token).and_return("abc")
|
947
949
|
@app.stub(:delete)
|
948
950
|
Shelly::User.stub(:new).and_return(@user)
|
@@ -1275,7 +1277,7 @@ We have been notified about it. We will be adding new resources shortly")
|
|
1275
1277
|
before do
|
1276
1278
|
Shelly::App.stub(:inside_git_repository?).and_return(true)
|
1277
1279
|
Bundler::Definition.stub_chain(:build, :specs, :map) \
|
1278
|
-
.and_return(["thin"])
|
1280
|
+
.and_return(["thin", "pg", "delayed_job", "whenever"])
|
1279
1281
|
Shelly::StructureValidator.any_instance.stub(:repo_paths) \
|
1280
1282
|
.and_return(["config.ru", "Gemfile", "Gemfile.lock"])
|
1281
1283
|
end
|
@@ -1344,6 +1346,62 @@ We have been notified about it. We will be adding new resources shortly")
|
|
1344
1346
|
end
|
1345
1347
|
end
|
1346
1348
|
|
1349
|
+
context "cloudfile" do
|
1350
|
+
before do
|
1351
|
+
cloud = mock(:code_name => "foo-staging", :databases => ["postgresql"],
|
1352
|
+
:whenever? => true, :delayed_job? => true, :to_s => "foo-staging")
|
1353
|
+
cloudfile = mock(:clouds => [cloud])
|
1354
|
+
|
1355
|
+
Shelly::Cloudfile.stub(:new).and_return(cloudfile)
|
1356
|
+
end
|
1357
|
+
|
1358
|
+
context "whenever is enabled" do
|
1359
|
+
it "should show that necessary gem doesn't exist" do
|
1360
|
+
Bundler::Definition.stub_chain(:build, :specs, :map).and_return([])
|
1361
|
+
$stdout.should_receive(:puts).with(" #{red("✗")} Gem 'whenever' is missing in the Gemfile for 'foo-staging' cloud")
|
1362
|
+
invoke(@main, :check)
|
1363
|
+
end
|
1364
|
+
|
1365
|
+
it "should show that necessary gem exists" do
|
1366
|
+
$stdout.should_receive(:puts).with(" #{green("✓")} Gem 'whenever' is present for 'foo-staging' cloud")
|
1367
|
+
invoke(@main, :check)
|
1368
|
+
end
|
1369
|
+
end
|
1370
|
+
|
1371
|
+
context "delayed_job is enabled" do
|
1372
|
+
it "should show that necessary gem doesn't exist" do
|
1373
|
+
Bundler::Definition.stub_chain(:build, :specs, :map).and_return([])
|
1374
|
+
$stdout.should_receive(:puts).with(" #{red("✗")} Gem 'delayed_job' is missing in the Gemfile for 'foo-staging' cloud")
|
1375
|
+
invoke(@main, :check)
|
1376
|
+
end
|
1377
|
+
|
1378
|
+
it "should show that necessary gem exists" do
|
1379
|
+
$stdout.should_receive(:puts).with(" #{green("✓")} Gem 'delayed_job' is present for 'foo-staging' cloud")
|
1380
|
+
invoke(@main, :check)
|
1381
|
+
end
|
1382
|
+
end
|
1383
|
+
|
1384
|
+
context "postgresql is enabled" do
|
1385
|
+
it "should show that necessary gem doesn't exist" do
|
1386
|
+
Bundler::Definition.stub_chain(:build, :specs, :map).and_return([])
|
1387
|
+
$stdout.should_receive(:puts).with(" #{red("✗")} Postgresql driver is missing in the Gemfile for 'foo-staging' cloud,\n we recommend adding 'pg' gem to Gemfile")
|
1388
|
+
invoke(@main, :check)
|
1389
|
+
end
|
1390
|
+
|
1391
|
+
it "should show that necessary gem exists - postgres" do
|
1392
|
+
Bundler::Definition.stub_chain(:build, :specs, :map).and_return(["postgres"])
|
1393
|
+
$stdout.should_receive(:puts).with(" #{green("✓")} Postgresql driver is present for 'foo-staging' cloud")
|
1394
|
+
invoke(@main, :check)
|
1395
|
+
end
|
1396
|
+
|
1397
|
+
it "should show that necessary gem exists - pg" do
|
1398
|
+
Bundler::Definition.stub_chain(:build, :specs, :map).and_return(["pg"])
|
1399
|
+
$stdout.should_receive(:puts).with(" #{green("✓")} Postgresql driver is present for 'foo-staging' cloud")
|
1400
|
+
invoke(@main, :check)
|
1401
|
+
end
|
1402
|
+
end
|
1403
|
+
end
|
1404
|
+
|
1347
1405
|
context "when mysql gem exists" do
|
1348
1406
|
it "should show that mysql gem is not supported by Shelly Cloud" do
|
1349
1407
|
Bundler::Definition.stub_chain(:build, :specs, :map).and_return(["mysql"])
|
@@ -84,7 +84,7 @@ describe Shelly::CLI::Runner do
|
|
84
84
|
it "should rescue not found exception for cloud" do
|
85
85
|
exception = Shelly::Client::NotFoundException.new({"resource" => "cloud", "id" => "foooo"}, 404)
|
86
86
|
@client.stub(:apps).and_raise(exception)
|
87
|
-
$stdout.should_receive(:puts).with("You have no access to 'foooo' cloud
|
87
|
+
$stdout.should_receive(:puts).with("You have no access to 'foooo' cloud")
|
88
88
|
lambda {
|
89
89
|
@runner.start
|
90
90
|
}.should raise_error(SystemExit)
|
@@ -8,7 +8,6 @@ describe Shelly::CLI::User do
|
|
8
8
|
Shelly::CLI::User.stub(:new).and_return(@cli_user)
|
9
9
|
@client = mock
|
10
10
|
Shelly::Client.stub(:new).and_return(@client)
|
11
|
-
Shelly::User.stub(:guess_email).and_return("")
|
12
11
|
$stdout.stub(:puts)
|
13
12
|
$stdout.stub(:print)
|
14
13
|
@client.stub(:token).and_return("abc")
|
@@ -5,7 +5,6 @@ describe Shelly::Cloudfile do
|
|
5
5
|
before do
|
6
6
|
FileUtils.mkdir_p("/projects/foo")
|
7
7
|
Dir.chdir("/projects/foo")
|
8
|
-
@hash = {:code_name => {:code => "test"}}
|
9
8
|
@client = mock
|
10
9
|
Shelly::Client.stub(:new).and_return(@client)
|
11
10
|
@cloudfile = Shelly::Cloudfile.new
|
@@ -22,6 +21,68 @@ describe Shelly::Cloudfile do
|
|
22
21
|
yaml.should == {"domains" => ["*.example.com", "example.com"]}
|
23
22
|
end
|
24
23
|
|
24
|
+
describe "#content" do
|
25
|
+
it "should fetch and parse file content" do
|
26
|
+
content = <<-config
|
27
|
+
foo-staging:
|
28
|
+
ruby_version: 1.9.3
|
29
|
+
environment: production
|
30
|
+
monitoring_email: bob@example.com
|
31
|
+
domains:
|
32
|
+
- foo-staging.winniecloud.com
|
33
|
+
servers:
|
34
|
+
app1:
|
35
|
+
size: small
|
36
|
+
thin: 2
|
37
|
+
whenever: on
|
38
|
+
delayed_job: 1
|
39
|
+
databases:
|
40
|
+
- postgresql
|
41
|
+
config
|
42
|
+
File.open("/projects/foo/Cloudfile", "w") { |f| f << content }
|
43
|
+
@cloudfile.content.should == {"foo-staging" => {
|
44
|
+
"ruby_version" => "1.9.3",
|
45
|
+
"environment" => "production",
|
46
|
+
"monitoring_email" => "bob@example.com",
|
47
|
+
"domains" => ["foo-staging.winniecloud.com"],
|
48
|
+
"servers" => { "app1" =>
|
49
|
+
{"size" => "small",
|
50
|
+
"thin" => 2,
|
51
|
+
"whenever" => true,
|
52
|
+
"delayed_job" => 1,
|
53
|
+
"databases" => ["postgresql"]}
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#clouds" do
|
61
|
+
it "should create Cloud objects" do
|
62
|
+
content = <<-config
|
63
|
+
foo-staging:
|
64
|
+
ruby_version: 1.9.3
|
65
|
+
servers:
|
66
|
+
app1:
|
67
|
+
size: small
|
68
|
+
foo-production:
|
69
|
+
environment: production
|
70
|
+
servers:
|
71
|
+
app1:
|
72
|
+
thin: 2
|
73
|
+
config
|
74
|
+
File.open("/projects/foo/Cloudfile", "w") { |f| f << content }
|
75
|
+
cloud1 = Shelly::App.should_receive(:new).with("foo-staging",
|
76
|
+
{"ruby_version"=>"1.9.3",
|
77
|
+
"servers"=>{"app1"=>{"size"=>"small"}}})
|
78
|
+
cloud2 = Shelly::App.should_receive(:new).with("foo-production",
|
79
|
+
{"environment"=>"production",
|
80
|
+
"servers"=>{"app1"=>{"thin"=>2}}})
|
81
|
+
|
82
|
+
@cloudfile.clouds
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
25
86
|
describe "#generate" do
|
26
87
|
before do
|
27
88
|
@cloudfile.code_name = "foo-staging"
|
@@ -88,31 +149,6 @@ config
|
|
88
149
|
end
|
89
150
|
end
|
90
151
|
|
91
|
-
describe "#databases" do
|
92
|
-
before do
|
93
|
-
content = <<-config
|
94
|
-
foo-staging:
|
95
|
-
servers:
|
96
|
-
app1:
|
97
|
-
databases:
|
98
|
-
- postgresql
|
99
|
-
- redis
|
100
|
-
app2:
|
101
|
-
databases:
|
102
|
-
- mongodb
|
103
|
-
config
|
104
|
-
File.open("Cloudfile", 'w') {|f| f.write(content) }
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should return databases in cloudfile" do
|
108
|
-
@cloudfile.databases("foo-staging").should =~ ['redis', 'mongodb', 'postgresql']
|
109
|
-
end
|
110
|
-
|
111
|
-
it "should return databases except for redis" do
|
112
|
-
@cloudfile.backup_databases("foo-staging").should =~ ['postgresql', 'mongodb']
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
152
|
describe "#create" do
|
117
153
|
before do
|
118
154
|
@cloudfile.stub(:generate).and_return("foo-staging:")
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shelly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.25
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -59,6 +59,38 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: ruby_gntp
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rb-fsevent
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
62
94
|
- !ruby/object:Gem::Dependency
|
63
95
|
name: fakefs
|
64
96
|
requirement: !ruby/object:Gem::Requirement
|
@@ -289,4 +321,23 @@ rubygems_version: 1.8.24
|
|
289
321
|
signing_key:
|
290
322
|
specification_version: 3
|
291
323
|
summary: Shelly Cloud command line tool
|
292
|
-
test_files:
|
324
|
+
test_files:
|
325
|
+
- spec/helpers.rb
|
326
|
+
- spec/input_faker.rb
|
327
|
+
- spec/shelly/app_spec.rb
|
328
|
+
- spec/shelly/backup_spec.rb
|
329
|
+
- spec/shelly/cli/backup_spec.rb
|
330
|
+
- spec/shelly/cli/config_spec.rb
|
331
|
+
- spec/shelly/cli/deploys_spec.rb
|
332
|
+
- spec/shelly/cli/files_spec.rb
|
333
|
+
- spec/shelly/cli/main_spec.rb
|
334
|
+
- spec/shelly/cli/runner_spec.rb
|
335
|
+
- spec/shelly/cli/user_spec.rb
|
336
|
+
- spec/shelly/client_spec.rb
|
337
|
+
- spec/shelly/cloudfile_spec.rb
|
338
|
+
- spec/shelly/download_progress_bar_spec.rb
|
339
|
+
- spec/shelly/model_spec.rb
|
340
|
+
- spec/shelly/structure_validator_spec.rb
|
341
|
+
- spec/shelly/user_spec.rb
|
342
|
+
- spec/spec_helper.rb
|
343
|
+
- spec/thor/options_spec.rb
|