engineyard 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/spec_helper.rb CHANGED
@@ -22,6 +22,7 @@ require 'engineyard'
22
22
 
23
23
  # Spec stuff
24
24
  require 'spec/autorun'
25
+ require 'tmpdir'
25
26
  require 'yaml'
26
27
  require 'pp'
27
28
  support = Dir[File.join(EY_ROOT,'/spec/support/*.rb')]
@@ -30,6 +31,7 @@ support.each{|helper| require helper }
30
31
  Spec::Runner.configure do |config|
31
32
  config.include Spec::Helpers
32
33
  config.extend Spec::GitRepo
34
+ config.extend Spec::Helpers::SemanticNames
33
35
 
34
36
  config.before(:all) do
35
37
  FakeWeb.allow_net_connect = false
@@ -65,7 +67,7 @@ EY.define_git_repo("default") do |git_dir|
65
67
  system("git commit -m 'initial commit' >/dev/null 2>&1")
66
68
  end
67
69
 
68
- shared_examples_for "an integration test without an eyrc file" do
70
+ shared_examples_for "integration without an eyrc file" do
69
71
  use_git_repo('default')
70
72
 
71
73
  before(:all) do
@@ -84,8 +86,8 @@ shared_examples_for "an integration test without an eyrc file" do
84
86
  end
85
87
 
86
88
  # Use this in conjunction with the 'ey' helper method
87
- shared_examples_for "an integration test" do
88
- it_should_behave_like "an integration test without an eyrc file"
89
+ shared_examples_for "integration" do
90
+ given "integration without an eyrc file"
89
91
 
90
92
  before(:all) do
91
93
  token = { ENV['CLOUD_URL'] => {
@@ -99,3 +101,5 @@ shared_examples_for "it has an api" do
99
101
  @api = EY::API.new('asdf')
100
102
  end
101
103
  end
104
+
105
+
@@ -54,6 +54,24 @@ class FakeAwsm < Sinatra::Base
54
54
  {"logs" => @@scenario.logs(params[:env_id])}.to_json
55
55
  end
56
56
 
57
+ get "/api/v2/environments/:env_id/recipes" do
58
+ redirect '/fakes3/recipe'
59
+ end
60
+
61
+ get "/fakes3/recipe" do
62
+ content_type "binary/octet-stream"
63
+ status(200)
64
+
65
+ tempdir = File.join(Dir.tmpdir, "ey_test_cmds_#{Time.now.tv_sec}#{Time.now.tv_usec}_#{$$}")
66
+ Dir.mkdir(tempdir)
67
+ Dir.mkdir("#{tempdir}/cookbooks")
68
+ File.open("#{tempdir}/cookbooks/README", 'w') do |f|
69
+ f.write "Remove this file to clone an upstream git repository of cookbooks\n"
70
+ end
71
+
72
+ Dir.chdir(tempdir) { `tar czf - cookbooks` }
73
+ end
74
+
57
75
  post "/api/v2/environments/:env_id/recipes" do
58
76
  if params[:file][:tempfile]
59
77
  files = `tar --list -z -f "#{params[:file][:tempfile].path}"`.split(/\n/)
@@ -108,6 +108,19 @@ module Spec
108
108
  end
109
109
  retval
110
110
  end
111
+
112
+ end
113
+ end
114
+
115
+ module Spec
116
+ module Helpers
117
+ module SemanticNames
118
+
119
+ def given(name)
120
+ it_should_behave_like name
121
+ end
122
+
123
+ end
111
124
  end
112
125
  end
113
126
 
@@ -0,0 +1,132 @@
1
+ module Spec
2
+ module Helpers
3
+ module SharedIntegrationTestUtils
4
+
5
+ def run_ey(command_options, ey_options)
6
+ if respond_to?(:extra_ey_options) # needed for ssh tests
7
+ ey_options.merge!(extra_ey_options)
8
+ end
9
+
10
+ ey(command_to_run(command_options), ey_options)
11
+ end
12
+
13
+ def make_scenario(hash)
14
+ # since nil will silently turn to empty string when interpolated,
15
+ # and there's a lot of string matching involved in integration
16
+ # testing, it would be nice to have early notification of typos.
17
+ scenario = Hash.new { |h,k| raise "Tried to get key #{k.inspect}, but it's missing!" }
18
+ scenario.merge!(hash)
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+
25
+
26
+ shared_examples_for "it takes an environment name" do
27
+ include Spec::Helpers::SharedIntegrationTestUtils
28
+
29
+ it "operates on the current environment by default" do
30
+ api_scenario "one app, one environment"
31
+ run_ey({:env => nil}, {:debug => true})
32
+ verify_ran(make_scenario({
33
+ :environment => 'giblets',
34
+ :application => 'rails232app',
35
+ :master_ip => '174.129.198.124',
36
+ :ssh_username => 'turkey',
37
+ }))
38
+ end
39
+
40
+ it "complains when you specify a nonexistent environment" do
41
+ api_scenario "one app, one environment"
42
+ run_ey({:env => 'typo-happens-here'}, {:expect_failure => true})
43
+ @err.should match(/no environment named 'typo-happens-here'/i)
44
+ end
45
+
46
+ context "given a piece of the environment name" do
47
+ before(:all) do
48
+ api_scenario "one app, many similarly-named environments"
49
+ end
50
+
51
+ it "complains when the substring is ambiguous" do
52
+ run_ey({:env => 'staging'}, {:expect_failure => true})
53
+ @err.should match(/'staging' is ambiguous/)
54
+ end
55
+
56
+ it "works when the substring is unambiguous" do
57
+ api_scenario "one app, many similarly-named environments"
58
+ run_ey({:env => 'prod'}, {:debug => true})
59
+ verify_ran(make_scenario({
60
+ :environment => 'railsapp_production',
61
+ :application => 'rails232app',
62
+ :master_ip => '174.129.198.124',
63
+ :ssh_username => 'turkey',
64
+ }))
65
+ end
66
+ end
67
+
68
+ it "complains when it can't guess the environment and its name isn't specified" do
69
+ api_scenario "one app, one environment, not linked"
70
+ run_ey({:env => nil}, {:expect_failure => true})
71
+ @err.should =~ /single environment/i
72
+ end
73
+ end
74
+
75
+ shared_examples_for "it invokes eysd" do
76
+ include Spec::Helpers::SharedIntegrationTestUtils
77
+
78
+ context "eysd install" do
79
+ before(:all) do
80
+ api_scenario "one app, one environment"
81
+ end
82
+
83
+ before(:each) do
84
+ ENV.delete "NO_SSH"
85
+ end
86
+
87
+ after(:each) do
88
+ ENV['NO_SSH'] = "true"
89
+ end
90
+
91
+ def exiting_ssh(exit_code)
92
+ "#!/usr/bin/env ruby\n exit!(#{exit_code}) if ARGV.to_s =~ /Base64.decode64/"
93
+ end
94
+
95
+ it "raises an error if SSH fails" do
96
+ run_ey({:env => 'giblets'},
97
+ {:prepend_to_path => {'ssh' => exiting_ssh(255)}, :expect_failure => true})
98
+ @err.should =~ /SSH connection to \S+ failed/
99
+ end
100
+
101
+ it "installs ey-deploy if it's missing" do
102
+ run_ey({:env => 'giblets'}, {:prepend_to_path => {'ssh' => exiting_ssh(104)}})
103
+
104
+ gem_install_command = @ssh_commands.find do |command|
105
+ command =~ /gem install ey-deploy/
106
+ end
107
+ gem_install_command.should_not be_nil
108
+ gem_install_command.should =~ %r{/usr/local/ey_resin/ruby/bin/gem install.*ey-deploy}
109
+ end
110
+
111
+ it "upgrades ey-deploy if it's too old" do
112
+ run_ey({:env => 'giblets'}, {:prepend_to_path => {'ssh' => exiting_ssh(70)}})
113
+ @ssh_commands.should have_command_like(/gem uninstall -a -x ey-deploy/)
114
+ @ssh_commands.should have_command_like(/gem install ey-deploy/)
115
+ end
116
+
117
+ it "raises an error if ey-deploy is too new" do
118
+ run_ey({:env => 'giblets'},
119
+ {:prepend_to_path => {'ssh' => exiting_ssh(17)}, :expect_failure => true})
120
+ @ssh_commands.should_not have_command_like(/gem install ey-deploy/)
121
+ @ssh_commands.should_not have_command_like(/eysd deploy/)
122
+ @err.should match(/too new/i)
123
+ end
124
+
125
+ it "does not change ey-deploy if its version is satisfactory" do
126
+ run_ey({:env => 'giblets'}, {:prepend_to_path => {'ssh' => exiting_ssh(0)}})
127
+ @ssh_commands.should_not have_command_like(/gem install ey-deploy/)
128
+ @ssh_commands.should_not have_command_like(/gem uninstall.* ey-deploy/)
129
+ @ssh_commands.should have_command_like(/eysd deploy/)
130
+ end
131
+ end
132
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 4
7
+ - 5
8
8
  - 0
9
- version: 0.4.0
9
+ version: 0.5.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - EY Cloud Team
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-11 00:00:00 -07:00
17
+ date: 2010-06-16 00:00:00 -07:00
18
18
  default_executable: ey
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -113,6 +113,7 @@ files:
113
113
  - lib/engineyard/cli/recipes.rb
114
114
  - lib/engineyard/cli/thor_fixes.rb
115
115
  - lib/engineyard/cli/ui.rb
116
+ - lib/engineyard/cli/web.rb
116
117
  - lib/engineyard/cli.rb
117
118
  - lib/engineyard/collection/environments.rb
118
119
  - lib/engineyard/collection.rb
@@ -177,12 +178,16 @@ test_files:
177
178
  - spec/ey/logs_spec.rb
178
179
  - spec/ey/rebuild_spec.rb
179
180
  - spec/ey/recipes/apply_spec.rb
181
+ - spec/ey/recipes/download_spec.rb
180
182
  - spec/ey/recipes/upload_spec.rb
181
183
  - spec/ey/rollback_spec.rb
182
184
  - spec/ey/ssh_spec.rb
185
+ - spec/ey/web/disable_spec.rb
186
+ - spec/ey/web/enable_spec.rb
183
187
  - spec/spec_helper.rb
184
188
  - spec/support/bundled_ey
185
189
  - spec/support/fake_awsm.ru
186
190
  - spec/support/git_repo.rb
187
191
  - spec/support/helpers.rb
188
192
  - spec/support/ruby_ext.rb
193
+ - spec/support/shared_behavior.rb