Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add integration spec

Change-Id: Ibfc198012eb2d79bcbd126ebdfb90a249a9feb5c
  • Loading branch information...
commit f41e071623ee4e318044c0fcb52b78c0aad08eed 1 parent 2f13377
@vito vito authored
View
3  .gitignore
@@ -4,4 +4,5 @@
Gemfile.lock
pkg/*
coverage/*
-.idea
+.idea
+spec/tmp
View
2  lib/vmc/cli.rb
@@ -266,7 +266,7 @@ def client_target
def ensure_config_dir
config = File.expand_path(VMC::CONFIG_DIR)
- Dir.mkdir(config) unless File.exist? config
+ FileUtils.mkdir_p(config) unless File.exist? config
end
def set_target(url)
View
19 lib/vmc/constants.rb
@@ -1,12 +1,13 @@
module VMC
- OLD_TARGET_FILE = "~/.vmc_target"
- OLD_TOKENS_FILE = "~/.vmc_token"
+ OLD_TARGET_FILE = "~/.vmc_target".freeze
+ OLD_TOKENS_FILE = "~/.vmc_token".freeze
- CONFIG_DIR = "~/.vmc"
- LOGS_DIR = "#{CONFIG_DIR}/logs"
- PLUGINS_FILE = "#{CONFIG_DIR}/plugins.yml"
- TARGET_FILE = "#{CONFIG_DIR}/target"
- TOKENS_FILE = "#{CONFIG_DIR}/tokens.yml"
- COLORS_FILE = "#{CONFIG_DIR}/colors.yml"
- CRASH_FILE = "#{CONFIG_DIR}/crash"
+ CONFIG_DIR = (defined?(SPEC_ROOT) ? "#{SPEC_ROOT}/tmp/.vmc" : "~/.vmc").freeze
+
+ LOGS_DIR = "#{CONFIG_DIR}/logs".freeze
+ PLUGINS_FILE = "#{CONFIG_DIR}/plugins.yml".freeze
+ TARGET_FILE = "#{CONFIG_DIR}/target".freeze
+ TOKENS_FILE = "#{CONFIG_DIR}/tokens.yml".freeze
+ COLORS_FILE = "#{CONFIG_DIR}/colors.yml".freeze
+ CRASH_FILE = "#{CONFIG_DIR}/crash".freeze
end
View
3  spec/assets/hello-sinatra/Gemfile
@@ -0,0 +1,3 @@
+source "https://rubygems.org"
+
+gem "sinatra"
View
6 spec/assets/hello-sinatra/main.rb
@@ -0,0 +1,6 @@
+require "rubygems"
+require "sinatra"
+
+get "/" do
+ "Hello, world!"
+end
View
59 spec/features/new_user_flow_spec.rb
@@ -0,0 +1,59 @@
+require 'spec_helper'
+
+if ENV['VMC_TEST_USER'] && ENV['VMC_TEST_PASSWORD'] && ENV['VMC_TEST_TARGET']
+ describe 'A new user tries to use VMC against v1 production' do
+ let(:target) { ENV['VMC_TEST_TARGET'] }
+ let(:username) { ENV['VMC_TEST_USER'] }
+ let(:password) { ENV['VMC_TEST_PASSWORD'] }
+ let(:output) { StringIO.new }
+ let(:out) { output.string.gsub(/\. \x08([\x08\. ]+)/, "... ") } # trim animated dots
+ let(:app) { "hello-sinatra" }
+
+ before do
+ FileUtils.rm_rf VMC::CONFIG_DIR
+ stub(VMC::CLI).exit { |code| code }
+ WebMock.allow_net_connect!
+ end
+
+ after do
+ with_output_to { VMC::CLI.start %W(delete #{app} -f) }
+ end
+
+ it 'and pushes a simple sinatra app using defaults as much as possible' do
+ with_output_to output do
+ vmc_ok %W(target #{target})
+ vmc_ok %W(login #{username} --password #{password})
+ vmc_fail %W(app #{app})
+
+ Dir.chdir("#{SPEC_ROOT}/assets/#{app}") do
+ vmc_ok %W(push #{app} --runtime ruby19 --url #{app}-vmc-test.cloudfoundry.com -f)
+ vmc_ok %W(push #{app})
+ end
+
+ vmc_ok %W(delete #{app} -f)
+ end
+
+ expect(out).to eq <<-OUT.strip_heredoc
+ Setting target to https://#{target}... OK
+ target: https://#{target}
+
+ Authenticating... OK
+ Unknown app '#{app}'.
+ Creating #{app}... OK
+
+ Updating #{app}... OK
+ Uploading #{app}... OK
+ Starting #{app}... OK
+ Checking #{app}... OK
+ Uploading #{app}... OK
+ Stopping #{app}... OK
+
+ Starting #{app}... OK
+ Checking #{app}... OK
+ Deleting #{app}... OK
+ OUT
+ end
+ end
+else
+ $stderr.puts 'Skipping integration specs; please provide $VMC_TEST_TARGET, $VMC_TEST_USER, and $VMC_TEST_PASSWORD'
+end
View
17 spec/spec_helper.rb
@@ -1,5 +1,6 @@
-require "rspec"
+SPEC_ROOT = File.dirname(__FILE__).freeze
+require "rspec"
require "cfoundry"
require "vmc"
require 'factory_girl'
@@ -15,13 +16,23 @@
c.mock_with :rr
end
+class String
+ def strip_heredoc
+ min = scan(/^[ \t]*(?=\S)/).min
+ indent = min ? min.size : 0
+ gsub(/^[ \t]{#{indent}}/, '')
+ end
+end
-def reassign_stdout_to(output)
+def with_output_to(output = StringIO.new)
old_out = $stdout
+ old_err = $stderr
$stdout = output
- yield $stdout
+ $stderr = output
+ yield output
ensure
$stdout = old_out
+ $stderr = old_err
end
def name_list(xs)
View
7 spec/support/feature_helpers.rb
@@ -0,0 +1,7 @@
+def vmc_ok(argv)
+ expect(VMC::CLI.start(argv + ["--no-script"])).to eq 0
+end
+
+def vmc_fail(argv)
+ expect(VMC::CLI.start(argv + ["--no-script"])).to_not eq 0
+end
View
2  spec/vmc/cli/organization/orgs_spec.rb
@@ -20,7 +20,7 @@
end
subject do
- reassign_stdout_to output do
+ with_output_to output do
Mothership.new.invoke(:orgs, inputs, given, global)
end
end
View
2  spec/vmc/cli/space/spaces_spec.rb
@@ -21,7 +21,7 @@
end
subject do
- reassign_stdout_to output do
+ with_output_to output do
Mothership.new.invoke(:spaces, inputs, given, global)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.