@@ -5,7 +5,6 @@ package command
5
5
6
6
import (
7
7
"path"
8
- "strings"
9
8
"testing"
10
9
11
10
"github.com/google/go-cmp/cmp"
@@ -26,14 +25,18 @@ func TestQuery(t *testing.T) {
26
25
{
27
26
name : "basic query" ,
28
27
directory : "basic" ,
29
- expectedOut : `list.test_instance.example id=test-instance-1 Test Instance 1
30
- list.test_instance.example id=test-instance-2 Test Instance 2` ,
28
+ expectedOut : `list.test_instance.example id=test-instance-1 Test Instance 1
29
+ list.test_instance.example id=test-instance-2 Test Instance 2
30
+
31
+ ` ,
31
32
},
32
33
{
33
34
name : "query referencing local variable" ,
34
35
directory : "with-locals" ,
35
- expectedOut : `list.test_instance.example id=test-instance-1 Test Instance 1
36
- list.test_instance.example id=test-instance-2 Test Instance 2` ,
36
+ expectedOut : `list.test_instance.example id=test-instance-1 Test Instance 1
37
+ list.test_instance.example id=test-instance-2 Test Instance 2
38
+
39
+ ` ,
37
40
},
38
41
{
39
42
name : "config with no query block" ,
@@ -62,8 +65,8 @@ The configuration does not contain any resources that can be queried.
62
65
expectedErr : []string {`
63
66
Error: No configuration files
64
67
65
- Query Plan requires a query configuration to be present. Create a Terraform
66
- query configuration file (.tfquery.hcl file) and try again.
68
+ Query requires a query configuration to be present. Create a Terraform query
69
+ configuration file (.tfquery.hcl file) and try again.
67
70
` },
68
71
},
69
72
{
@@ -117,18 +120,19 @@ Blocks of type "resource" are not expected here.
117
120
output = done (t )
118
121
actual := output .All ()
119
122
if len (ts .expectedErr ) == 0 {
120
- if code != 0 && len ( ts . expectedErr ) == 0 {
123
+ if code != 0 {
121
124
t .Fatalf ("bad: %d\n \n %s" , code , output .Stderr ())
125
+ }
122
126
123
- // Check that we have query output
124
- if ! strings .Contains (actual , ts .expectedOut ) {
125
- t .Errorf ("expected query output to contain '%s', got: %s" , ts .expectedOut , actual )
126
- }
127
+ // Check that we have query output
128
+ if diff := cmp .Diff (ts .expectedOut , actual ); diff != "" {
129
+ t .Errorf ("expected query output to contain %q, \n got: %q, \n diff: %s" , ts .expectedOut , actual , diff )
127
130
}
131
+
128
132
} else {
129
133
for _ , expected := range ts .expectedErr {
130
134
if diff := cmp .Diff (expected , actual ); diff != "" {
131
- t .Errorf ("expected error message to contain '%s', \n got: %s, diff : %s" , expected , actual , diff )
135
+ t .Errorf ("expected error message to contain '%s', \n got: %s, \n diff : %s" , expected , actual , diff )
132
136
}
133
137
}
134
138
}
0 commit comments