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