core: Fix issues from rebasing dev-0.7 onto master

- Fix sensitive outputs for lists and maps
- Fix test prelude which was missed during conflict resolution
- Fix `terraform output` to match old behaviour and not have outputs
  header and colouring
- Bump timeout on TestAtlasClient_UnresolvableConflict
This commit is contained in:
James Nugent 2016-05-10 14:56:26 -04:00
parent 9d77e0af6c
commit 6a20e8927d
6 changed files with 28 additions and 11 deletions

View File

@ -251,7 +251,7 @@ func (c *ApplyCommand) Run(args []string) int {
} }
if !c.Destroy { if !c.Destroy {
if outputs := outputsAsString(state, ctx.Module().Config().Outputs); outputs != "" { if outputs := outputsAsString(state, ctx.Module().Config().Outputs, true); outputs != "" {
c.Ui.Output(c.Colorize().Color(outputs)) c.Ui.Output(c.Colorize().Color(outputs))
} }
} }
@ -377,7 +377,7 @@ Options:
return strings.TrimSpace(helpText) return strings.TrimSpace(helpText)
} }
func outputsAsString(state *terraform.State, schema []*config.Output) string { func outputsAsString(state *terraform.State, schema []*config.Output, includeHeader bool) string {
if state == nil { if state == nil {
return "" return ""
} }
@ -386,11 +386,15 @@ func outputsAsString(state *terraform.State, schema []*config.Output) string {
outputBuf := new(bytes.Buffer) outputBuf := new(bytes.Buffer)
if len(outputs) > 0 { if len(outputs) > 0 {
schemaMap := make(map[string]*config.Output) schemaMap := make(map[string]*config.Output)
for _, s := range schema { if schema != nil {
schemaMap[s.Name] = s for _, s := range schema {
schemaMap[s.Name] = s
}
} }
outputBuf.WriteString("[reset][bold][green]\nOutputs:\n\n") if includeHeader {
outputBuf.WriteString("[reset][bold][green]\nOutputs:\n\n")
}
// Output the outputs in alphabetical order // Output the outputs in alphabetical order
keyLen := 0 keyLen := 0
@ -404,7 +408,8 @@ func outputsAsString(state *terraform.State, schema []*config.Output) string {
sort.Strings(ks) sort.Strings(ks)
for _, k := range ks { for _, k := range ks {
if schemaMap[k].Sensitive { schema, ok := schemaMap[k]
if ok && schema.Sensitive {
outputBuf.WriteString(fmt.Sprintf("%s = <sensitive>\n", k)) outputBuf.WriteString(fmt.Sprintf("%s = <sensitive>\n", k))
continue continue
} }

View File

@ -887,6 +887,15 @@ func TestApply_stateNoExist(t *testing.T) {
} }
func TestApply_sensitiveOutput(t *testing.T) { func TestApply_sensitiveOutput(t *testing.T) {
p := testProvider()
ui := new(cli.MockUi)
c := &ApplyCommand{
Meta: Meta{
ContextOpts: testCtxConfig(p),
Ui: ui,
},
}
statePath := testTempFile(t) statePath := testTempFile(t)
args := []string{ args := []string{
@ -902,7 +911,7 @@ func TestApply_sensitiveOutput(t *testing.T) {
if !strings.Contains(output, "notsensitive = Hello world") { if !strings.Contains(output, "notsensitive = Hello world") {
t.Fatalf("bad: output should contain 'notsensitive' output\n%s", output) t.Fatalf("bad: output should contain 'notsensitive' output\n%s", output)
} }
if !strings.Contains(output, "sensitive = <sensitive>") { if !strings.Contains(output, "sensitive = <sensitive>") {
t.Fatalf("bad: output should contain 'sensitive' output\n%s", output) t.Fatalf("bad: output should contain 'sensitive' output\n%s", output)
} }
} }

View File

@ -81,7 +81,7 @@ func (c *OutputCommand) Run(args []string) int {
} }
if name == "" { if name == "" {
c.Ui.Output(outputsAsString(state)) c.Ui.Output(outputsAsString(state, nil, false))
return 0 return 0
} }

View File

@ -109,7 +109,7 @@ func (c *RefreshCommand) Run(args []string) int {
return 1 return 1
} }
if outputs := outputsAsString(newState, ctx.Module().Config().Outputs); outputs != "" { if outputs := outputsAsString(newState, ctx.Module().Config().Outputs, true); outputs != "" {
c.Ui.Output(c.Colorize().Color(outputs)) c.Ui.Output(c.Colorize().Color(outputs))
} }

View File

@ -159,7 +159,7 @@ func TestAtlasClient_UnresolvableConflict(t *testing.T) {
select { select {
case <-doneCh: case <-doneCh:
// OK // OK
case <-time.After(50 * time.Millisecond): case <-time.After(500 * time.Millisecond):
t.Fatalf("Timed out after 50ms, probably because retrying infinitely.") t.Fatalf("Timed out after 50ms, probably because retrying infinitely.")
} }
} }

View File

@ -2598,11 +2598,14 @@ func TestContext2Apply_destroyModuleWithAttrsReferencingResource(t *testing.T) {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
ctx = planFromFile.Context(&ContextOpts{ ctx, err = planFromFile.Context(&ContextOpts{
Providers: map[string]ResourceProviderFactory{ Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p), "aws": testProviderFuncFixed(p),
}, },
}) })
if err != nil {
t.Fatalf("err: %s", err)
}
state, err = ctx.Apply() state, err = ctx.Apply()
if err != nil { if err != nil {