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 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))
}
}
@ -377,7 +377,7 @@ Options:
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 {
return ""
}
@ -386,11 +386,15 @@ func outputsAsString(state *terraform.State, schema []*config.Output) string {
outputBuf := new(bytes.Buffer)
if len(outputs) > 0 {
schemaMap := make(map[string]*config.Output)
for _, s := range schema {
schemaMap[s.Name] = s
if schema != nil {
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
keyLen := 0
@ -404,7 +408,8 @@ func outputsAsString(state *terraform.State, schema []*config.Output) string {
sort.Strings(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))
continue
}

View File

@ -887,6 +887,15 @@ func TestApply_stateNoExist(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)
args := []string{
@ -902,7 +911,7 @@ func TestApply_sensitiveOutput(t *testing.T) {
if !strings.Contains(output, "notsensitive = Hello world") {
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)
}
}

View File

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

View File

@ -109,7 +109,7 @@ func (c *RefreshCommand) Run(args []string) int {
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))
}

View File

@ -159,7 +159,7 @@ func TestAtlasClient_UnresolvableConflict(t *testing.T) {
select {
case <-doneCh:
// OK
case <-time.After(50 * time.Millisecond):
case <-time.After(500 * time.Millisecond):
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)
}
ctx = planFromFile.Context(&ContextOpts{
ctx, err = planFromFile.Context(&ContextOpts{
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
})
if err != nil {
t.Fatalf("err: %s", err)
}
state, err = ctx.Apply()
if err != nil {