|
1 | 1 | package jsonformat |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "encoding/json" |
4 | 5 | "fmt" |
5 | 6 | "testing" |
6 | 7 |
|
7 | | - "github.com/hashicorp/terraform/internal/command/jsonformat/differ/attribute_path" |
8 | | - |
9 | 8 | "github.com/google/go-cmp/cmp" |
10 | 9 | "github.com/mitchellh/colorstring" |
11 | 10 | "github.com/zclconf/go-cty/cty" |
12 | 11 |
|
13 | 12 | "github.com/hashicorp/terraform/internal/addrs" |
14 | 13 | "github.com/hashicorp/terraform/internal/command/jsonformat/differ" |
| 14 | + "github.com/hashicorp/terraform/internal/command/jsonformat/differ/attribute_path" |
15 | 15 | "github.com/hashicorp/terraform/internal/command/jsonplan" |
16 | 16 | "github.com/hashicorp/terraform/internal/command/jsonprovider" |
17 | 17 | "github.com/hashicorp/terraform/internal/configs/configschema" |
18 | 18 | "github.com/hashicorp/terraform/internal/lang/marks" |
19 | 19 | "github.com/hashicorp/terraform/internal/plans" |
20 | 20 | "github.com/hashicorp/terraform/internal/providers" |
21 | 21 | "github.com/hashicorp/terraform/internal/states" |
| 22 | + "github.com/hashicorp/terraform/internal/terminal" |
22 | 23 | "github.com/hashicorp/terraform/internal/terraform" |
23 | 24 | ) |
24 | 25 |
|
| 26 | +func TestRenderHuman_EmptyPlan(t *testing.T) { |
| 27 | + color := &colorstring.Colorize{Colors: colorstring.DefaultColors, Disable: true} |
| 28 | + streams, done := terminal.StreamsForTesting(t) |
| 29 | + |
| 30 | + plan := Plan{} |
| 31 | + |
| 32 | + renderer := Renderer{Colorize: color, Streams: streams} |
| 33 | + plan.renderHuman(renderer, plans.NormalMode) |
| 34 | + |
| 35 | + want := ` |
| 36 | +No changes. Your infrastructure matches the configuration. |
| 37 | +
|
| 38 | +Terraform has compared your real infrastructure against your configuration |
| 39 | +and found no differences, so no changes are needed. |
| 40 | +` |
| 41 | + |
| 42 | + got := done(t).Stdout() |
| 43 | + if diff := cmp.Diff(want, got); len(diff) > 0 { |
| 44 | + t.Errorf("unexpected output\ngot:\n%s\nwant:\n%s\ndiff:\n%s", got, want, diff) |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +func TestRenderHuman_EmptyOutputs(t *testing.T) { |
| 49 | + color := &colorstring.Colorize{Colors: colorstring.DefaultColors, Disable: true} |
| 50 | + streams, done := terminal.StreamsForTesting(t) |
| 51 | + |
| 52 | + outputVal, _ := json.Marshal("some-text") |
| 53 | + plan := Plan{ |
| 54 | + OutputChanges: map[string]jsonplan.Change{ |
| 55 | + "a_string": { |
| 56 | + Actions: []string{"no-op"}, |
| 57 | + Before: outputVal, |
| 58 | + After: outputVal, |
| 59 | + }, |
| 60 | + }, |
| 61 | + } |
| 62 | + |
| 63 | + renderer := Renderer{Colorize: color, Streams: streams} |
| 64 | + plan.renderHuman(renderer, plans.NormalMode) |
| 65 | + |
| 66 | + want := ` |
| 67 | +No changes. Your infrastructure matches the configuration. |
| 68 | +
|
| 69 | +Terraform has compared your real infrastructure against your configuration |
| 70 | +and found no differences, so no changes are needed. |
| 71 | +` |
| 72 | + |
| 73 | + got := done(t).Stdout() |
| 74 | + if diff := cmp.Diff(want, got); len(diff) > 0 { |
| 75 | + t.Errorf("unexpected output\ngot:\n%s\nwant:\n%s\ndiff:\n%s", got, want, diff) |
| 76 | + } |
| 77 | +} |
| 78 | + |
25 | 79 | func TestResourceChange_primitiveTypes(t *testing.T) { |
26 | 80 | testCases := map[string]testCase{ |
27 | 81 | "creation": { |
|
0 commit comments