spec/cfn_flow/cli_spec.rb in cfn-flow-0.9.0 vs spec/cfn_flow/cli_spec.rb in cfn-flow-0.10.0

- old
+ new

@@ -148,14 +148,15 @@ end it 'can cleanup' do # Stubbing hacks alert! - # The first time we call :describe_stacks, return the stack we launch. - # The second time, we're loading 'another-stack' to clean it up + # The first two times we call :describe_stacks, return the stack we launch. + # The third time, we're loading 'another-stack' to clean it up stack_stubs = [ { stacks: [ stub_stack_data(stack_name: 'cfn-flow-spec-stack') ] }, + { stacks: [ stub_stack_data(stack_name: 'cfn-flow-spec-stack') ] }, { stacks: [ stub_stack_data(stack_name: 'another-stack') ] } ] Aws.config[:cloudformation]= { stub_responses: { describe_stacks: stack_stubs, @@ -171,10 +172,61 @@ end end end + describe '#update' do + it 'fails with no args' do + out, err = capture_io { cli.start [:update] } + out.must_equal '' + err.must_match(/ERROR.+no arguments/) + end + + it 'returns an error when stack is not in service' do + stack_data = stub_stack_data + stack_data[:tags][0][:value] = 'none-such-service' + Aws.config[:cloudformation]= { + stub_responses: { + describe_stacks: { stacks: [ stack_data ] } + } + } + out, err = capture_io { cli.start [:update, 'production', 'none-such-stack'] } + out.must_equal '' + err.must_match "not tagged for service #{CfnFlow.service}" + end + + it 'returns an error when stack environment does not match' do + stack_data = stub_stack_data + Aws.config[:cloudformation]= { + stub_responses: { + describe_stacks: { stacks: [ stack_data ] } + } + } + out, err = capture_io { cli.start [:update, 'none-such-env', 'mystack'] } + out.must_equal '' + err.must_match "not tagged for environment none-such-env" + end + + it 'succeeds' do + stack_name = CfnFlow.config['stack']['stack_name'] + + Aws.config[:cloudformation]= { + stub_responses: { + describe_stacks: { stacks: [ stub_stack_data(stack_name: stack_name, stack_status: 'UPDATE_COMPLETE') ] }, + describe_stack_events: { stack_events: [ stub_event_data(resource_status: 'UPDATE_COMPLETE') ] }, + } + } + out, err = capture_io { cli.start [:update, 'production', stack_name] } + + out.must_match "Updating stack #{stack_name}" + out.must_match "Polling for events..." + out.must_match "UPDATE_COMPLETE" + out.must_match "Stack Outputs:" + err.must_equal '' + end + end + describe '#list' do it 'has no output with no stacks' do out, err = capture_io { cli.start [:list] } out.must_equal '' err.must_equal '' @@ -255,15 +307,34 @@ expected = CfnFlow.cfn_resource.stack('mystack').data.to_hash.to_yaml out.must_equal expected err.must_equal '' end - it 'handles --json option' do - out, _ = capture_io { cli.start [:show, 'mystack', '--json'] } + it 'handles json format' do + out, _ = capture_io { cli.start [:show, 'mystack', '--format=json'] } expected = MultiJson.dump(CfnFlow.cfn_resource.stack('mystack').data.to_hash, pretty: true) + "\n" out.must_equal expected end + + describe 'outputs-table format' do + it 'handles shows a table when there are events' do + out, _ = capture_io { cli.start [:show, 'mystack', '--format=outputs-table'] } + out.must_match(/KEY\s+VALUE\s+DESCRIPTION/) + out.must_match(/mykey\s+myvalue\s+My Output/) + end + + it 'handles no events' do + Aws.config[:cloudformation]= { + stub_responses: { + describe_stacks: { stacks: [ stub_stack_data(outputs: nil) ] } + } + } + out, _ = capture_io { cli.start [:show, 'mystack', '--format=outputs-table'] } + out.must_match "No stack outputs to show." + + end + end end it 'returns an error with missing stacks' do Aws.config[:cloudformation]= { stub_responses: { describe_stacks: 'ValidationError' } @@ -349,18 +420,22 @@ describe '#delete' do describe 'with a stack' do before do Aws.config[:cloudformation] = { - stub_responses: { describe_stacks: { stacks: [ stub_stack_data ] } } + stub_responses: { + describe_stacks: { stacks: [ stub_stack_data ] }, + describe_stack_events: { stack_events: [ stub_event_data ] } + } } end it 'deletes the stack' do Thor::LineEditor.stub :readline, "yes" do out, err = capture_io { cli.start [:delete, 'mystack'] } - out.must_equal "Deleted stack mystack\n" + out.must_match "Deleted stack mystack" + out.must_match "Polling for events..." err.must_equal '' end end it 'does not delete the stack if you say no' do @@ -371,10 +446,10 @@ end end it 'does not ask when --force is set' do out, err = capture_io { cli.start [:delete, '--force', 'mystack'] } - out.must_equal "Deleted stack mystack\n" + out.must_match "Deleted stack mystack" err.must_equal '' end end it 'returns an error for a stack in another service' do