Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Merge branch 'space-org-bug'
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugenia Dellapenna & Ian Baker committed Mar 6, 2013
2 parents 80fe738 + 15f0831 commit adb024f
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 35 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Expand Up @@ -12,6 +12,10 @@ env:
- secure: "UE5QlcvsNEEIiaFVBThh9LFW3LyQG8endi10y1kislgdlVrkpx/b/REU0wwz\nLf1aPGMtKCWbRqBZk0zg8JYTQoig/2wXnct5IJuabOrtgcoWZl/pxGr/0U5A\n5/v0pEq1i3FtXBbOe4Oe2vQuJzhs/WrUXO6gGHsncwQsAreqJtw="
- secure: "IerTwFN0kvQ8zEXxoZJ/NQjwyRzSxh9HbDdr1IljNLyEgDIfx5i57ufemwlH\nVujsITuwg1Ut6b7OLfXFTmbdGHR21XhI3TMBoO34bLuChNlKFQaSkibVSXqe\nr1cTmnbsmVYM4IMImiS0c15WVpVZTYesZTB+P5EsIeQdFJ+j0cw="
- secure: "nZQ4n2D+pzOgWz9Rb75L0NQoKvHOOkms+EpRUlbpq/saSN1pITIpbwGtlbpm\nFGGZbilQxfmdgkp1Wg+3/BmRjgWbn7vjrmudZ5Y137uebmtFhI46/wcjaSTf\n3LBbxkxIQMnzNxGE6PgZgJBrow2pSJ6+ZGI6bk50n+PKQc0kVKY="
- secure: "t/u/i4F02vNym2kwopei2UDWL7FmLkn5t05Qya2kqObENGHHf3vv4OHIB6Ok\nZguSrMkf4BP9mx9GeFbga1vEUo/L88tls7L3wsqdLEwzevRaqlqOcUbVP/jL\nh4MZ/TJ/zpfDY1ddm3jB7qI0GF1UcFppdxO16A33JgDkyqjL1cw="
- secure: "T0wMEmJjya+D+Qvx4hZfHwaBXBYSeQFo4qSSwKsv2UkLnDmi2R+Wmv+mCMUe\noKzXhYEeTAQ7QXIMGU2pQKsHMFYrECsNxS9Y7P7XHWeo7MOwu4zRfcOhkCMk\ndmkR92TEM4Np3hVVDFz3SzivwxV60Txa5b5JO2IvnhmAqvj9SLM="
- secure: "cjF0yCIHb+JvolUkUtJXwjgD+4pub5nJ5mDP1meoC3f6NRMlL8Tm8a4+k3US\nujEqn2GUXKZvWFmcO/PSNIZ50xNuSFnArPjQ0b1RLpxB7+UJTix5b07of4pr\nntXG0zvMjuocNxyEt/skGbjbZk8/sVyfCVhFcmc3sYYdUinJXks="
- secure: "QIR+zEq8nlFtHbWcp4r0MJ0gibijNB8y81vvf0FlnsY/oCITRevxgIr7D7i1\nzVGoVie0NiguCmXHBVpKIZXnd2OKBcFOM2T9sf5vEeQtF+gjGDcLL2ZPRxOT\nbLkjkg2MWMiEX4HeLd4f9aZEZSCHFvn9PfqANPZGPm767B4gMak="

before_script: ./script/setup_187

Expand Down
1 change: 0 additions & 1 deletion Gemfile
Expand Up @@ -29,6 +29,5 @@ group :test do
end

group :development do
gem "pry"
gem "gem-release"
end
8 changes: 0 additions & 8 deletions Gemfile.lock
Expand Up @@ -74,24 +74,18 @@ GEM
multi_json (~> 1.3)
cf-uaa-lib (1.3.7)
multi_json
coderay (1.0.9)
crack (0.3.2)
diff-lcs (1.1.3)
fakefs (0.4.2)
ffaker (1.15.0)
gem-release (0.4.1)
json_pure (1.7.7)
method_source (0.8.1)
mime-types (1.21)
multi_json (1.6.1)
multipart-post (1.2.0)
parallel (0.6.2)
parallel_tests (0.10.0)
parallel
pry (0.9.12)
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.4)
rake (10.0.3)
rest-client (1.6.7)
mime-types (>= 1.16)
Expand All @@ -105,7 +99,6 @@ GEM
diff-lcs (~> 1.1.3)
rspec-mocks (2.12.2)
rubyzip (0.9.9)
slop (3.4.3)
uuidtools (2.1.3)
webmock (1.9.3)
addressable (>= 2.2.7)
Expand All @@ -129,7 +122,6 @@ DEPENDENCIES
mothership!
multi_json (~> 1.3)
parallel_tests
pry
rake
rr (~> 1.0)
rspec (~> 2.11)
Expand Down
40 changes: 25 additions & 15 deletions lib/vmc/cli/start/base.rb
Expand Up @@ -37,32 +37,42 @@ def display_target
def select_org(input, info)
if input.has?(:organization) || !org_valid?(info[:organization])
org = input[:organization]
with_progress("Switching to organization #{c(org.name, :name)}") {} if org
org
if org
with_progress("Switching to organization #{c(org.name, :name)}") {}
client.current_organization = org
end
info[:organization] = org ? org.guid : nil
!!org
else
client.current_organization
info[:organization] = nil
client.current_organization = nil
false
end
end

def select_space(org, input, info, changed_org)
def select_space(input, info, changed_org)
if input.has?(:space) || !space_valid?(info[:space])
line if changed_org && !quiet?
space = input[:space, org]
with_progress("Switching to space #{c(space.name, :name)}") {} if space
space
space = input[:space, client.current_organization]
if space
with_progress("Switching to space #{c(space.name, :name)}") {}
client.current_space = space
end
info[:space] = space ? space.guid : nil
else
client.current_space
info[:space] = nil
client.current_space = nil
end
end

def select_org_and_space(input, info)
org = select_org(input, info)
changed_org = client.current_organization != org
space = select_space(org, input, info, changed_org) if org
info.merge!(
:organization => (org ? org.guid : nil),
:space => (space ? space.guid : nil)
)
changed_org = select_org(input, info)
if client.current_organization
select_space(input, info, changed_org)
else
info[:space] = nil
client.current_space = nil
end
end

def org_valid?(guid, user = client.current_user)
Expand Down
21 changes: 21 additions & 0 deletions spec/console_app_specker/console_app_specker_matchers_spec.rb
Expand Up @@ -77,6 +77,27 @@
subject.negative_failure_message.should == "expected 'expected_output' to not be printed, but it was. full output:\nactual_output"
end
end

context "when expecting branching output" do
let(:expected_output) { {
"expected_output" => proc {},
"other_expected_output" => proc {}
} }

it "has a correct failure message" do
run("echo -n actual_output") do |runner|
subject.matches?(runner)
subject.failure_message.should == "expected one of 'expected_output', 'other_expected_output' to be printed, but it wasn't. full output:\nactual_output"
end
end

it "has a correct negative failure message" do
run("echo -n expected_output") do |runner|
subject.matches?(runner)
subject.negative_failure_message.should == "expected 'expected_output' to not be printed, but it was. full output:\nexpected_output"
end
end
end
end
end

Expand Down
16 changes: 13 additions & 3 deletions spec/console_app_specker/specker_runner_spec.rb
Expand Up @@ -85,16 +85,26 @@ def asset(file)

context "expecting multiple branches" do
context "and one of them matches" do
it "can be passed a hash of values with callbacks" do
it "can be passed a hash of values with callbacks, and returns the matched key" do
run("echo 1 3") do |runner|
branches = {
"1" => proc { 1 },
"2" => proc { 2 },
"3" => proc { 3 }
}

expect(runner.expect(branches)).to eq 1
expect(runner.expect(branches)).to eq 3
expect(runner.expect(branches)).to eq "1"
expect(runner.expect(branches)).to eq "3"
end
end

it "calls the matched callback" do
callback = mock!
run("echo 1 3") do |runner|
branches = {
"1" => proc { callback }
}
runner.expect(branches)
end
end
end
Expand Down
64 changes: 64 additions & 0 deletions spec/features/v2/login_spec.rb
@@ -0,0 +1,64 @@
require "spec_helper"

if ENV['VMC_V2_TEST_USER'] && ENV['VMC_V2_TEST_PASSWORD'] && ENV['VMC_V2_TEST_TARGET'] && ENV['VMC_V2_OTHER_TEST_USER']
describe 'A user logs in and switches spaces, after a different user has logged in', :ruby19 => true do
include ConsoleAppSpeckerMatchers

let(:target) { ENV['VMC_V2_TEST_TARGET'] }
let(:username) { ENV['VMC_V2_TEST_USER'] }
let(:password) { ENV['VMC_V2_TEST_PASSWORD'] }

let(:second_username) { ENV['VMC_V2_OTHER_TEST_USER'] }
let(:second_organization) { ENV['VMC_V2_OTHER_TEST_ORGANIZATION'] }
let(:second_space) { ENV['VMC_V2_OTHER_TEST_SPACE'] }
let(:second_password) { ENV['VMC_V2_OTHER_TEST_PASSWORD'] || ENV['VMC_V2_TEST_PASSWORD'] }

before do
Interact::Progress::Dots.start!

run("#{vmc_bin} target #{target}") do |runner|
expect(runner).to say "Setting target"
expect(runner).to say target
runner.wait_for_exit
end

run("#{vmc_bin} logout") do |runner|
runner.wait_for_exit
end
end

after do
Interact::Progress::Dots.stop!
end

context "when a different user is already logged in" do
before do
run("#{vmc_bin} login #{username} --password #{password}") do |runner|
expect(runner).to say "Authenticating... OK"

expect(runner).to say "Switching to organization"
expect(runner).to say "OK"

expect(runner).to say "Space"
runner.send_keys("1")

expect(runner).to say "Switching to space"
expect(runner).to say "OK"

runner.wait_for_exit
end
end

it "can switch spaces on login" do
run("#{vmc_bin} login #{second_username} --password #{second_password} --organization #{second_organization} --space #{second_space}") do |runner|
expect(runner).to say "Authenticating... OK"
expect(runner).to say "Switching to organization #{second_organization}... OK"
expect(runner).to say "Switching to space #{second_space}... OK"
runner.wait_for_exit
end
end
end
end
else
$stderr.puts 'Skipping v2 integration specs; please provide $VMC_V2_TEST_TARGET, $VMC_V2_TEST_USER, $VMC_V2_TEST_PASSWORD, and $VMC_V2_OTHER_TEST_USER'
end
2 changes: 1 addition & 1 deletion spec/features/v2/push_flow_spec.rb
Expand Up @@ -121,5 +121,5 @@
end
end
else
$stderr.puts 'Skipping integration specs; please provide $VMC_TEST_TARGET, $VMC_TEST_USER, and $VMC_TEST_PASSWORD'
$stderr.puts 'Skipping v2 integration specs; please provide $VMC_V2_TEST_TARGET, $VMC_V2_TEST_USER, and $VMC_V2_TEST_PASSWORD'
end
4 changes: 2 additions & 2 deletions spec/features/v2/switching_targets_spec.rb
Expand Up @@ -16,7 +16,7 @@

it "can switch targets, even if a target is invalid" do
run("#{vmc_bin} target invalid-target") do |runner|
expect(runner).to say "target refused"
expect(runner).to say /target refused/i
runner.wait_for_exit
end

Expand All @@ -29,4 +29,4 @@
end
else
$stderr.puts 'Skipping v2 integration specs; please provide $VMC_V2_TEST_TARGET'
end
end
19 changes: 15 additions & 4 deletions spec/support/console_app_specker_matchers.rb
Expand Up @@ -11,17 +11,28 @@ def initialize(expected_output, timeout = 30)

def matches?(runner)
raise InvalidInputError unless runner.respond_to?(:expect)
expected = runner.expect(@expected_output, @timeout)
@matched = runner.expect(@expected_output, @timeout)
@full_output = runner.output
!!expected
!!@matched
end

def failure_message
"expected '#{@expected_output}' to be printed, but it wasn't. full output:\n#@full_output"
if @expected_output.is_a?(Hash)
expected_keys = @expected_output.keys.map{|key| "'#{key}'"}.join(', ')
"expected one of #{expected_keys} to be printed, but it wasn't. full output:\n#@full_output"
else
"expected '#{@expected_output}' to be printed, but it wasn't. full output:\n#@full_output"
end
end

def negative_failure_message
"expected '#{@expected_output}' to not be printed, but it was. full output:\n#@full_output"
if @expected_output.is_a?(Hash)
match = @matched
else
match = @expected_output
end

"expected '#{match}' to not be printed, but it was. full output:\n#@full_output"
end
end

Expand Down
3 changes: 2 additions & 1 deletion spec/support/specker_runner.rb
Expand Up @@ -69,11 +69,12 @@ def expect_branches(branches, timeout)
data = expected.first.match(/(#{branch_names})$/)
matched = data[1]
branches[matched].call
matched
end

def numeric_exit_code(status)
status.exitstatus
rescue NoMethodError
status
end
end
end

0 comments on commit adb024f

Please sign in to comment.