@@ -5,6 +5,7 @@ package command
55
66import (
77 "path"
8+ "strings"
89 "testing"
910
1011 "github.com/google/go-cmp/cmp"
@@ -83,6 +84,15 @@ Error: Unsupported block type
8384Blocks of type "resource" are not expected here.
8485` },
8586 },
87+ {
88+ name : "empty result" ,
89+ directory : "empty-result" ,
90+ expectedOut : `list.test_instance.example id=test-instance-1 Test Instance 1
91+ list.test_instance.example id=test-instance-2 Test Instance 2
92+
93+ Warning: list block(s) [list.test_instance.example2] returned 0 results.` ,
94+ initCode : 0 ,
95+ },
8696 }
8797
8898 for _ , ts := range tests {
@@ -118,19 +128,22 @@ Blocks of type "resource" are not expected here.
118128 args := []string {"-no-color" }
119129 code = c .Run (args )
120130 output = done (t )
121- actual := output .All ()
122131 if len (ts .expectedErr ) == 0 {
123132 if code != 0 {
124133 t .Fatalf ("bad: %d\n \n %s" , code , output .Stderr ())
125134 }
135+ actual := strings .TrimSpace (output .Stdout ())
126136
127137 // 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 )
138+ expected := strings .TrimSpace (ts .expectedOut )
139+ if diff := cmp .Diff (expected , actual ); diff != "" {
140+ t .Errorf ("expected query output to contain \n %q, \n got: \n %q, \n diff: %s" , expected , actual , diff )
130141 }
131142
132143 } else {
144+ actual := strings .TrimSpace (output .Stderr ())
133145 for _ , expected := range ts .expectedErr {
146+ expected := strings .TrimSpace (expected )
134147 if diff := cmp .Diff (expected , actual ); diff != "" {
135148 t .Errorf ("expected error message to contain '%s', \n got: %s, \n diff: %s" , expected , actual , diff )
136149 }
@@ -228,11 +241,12 @@ func queryFixtureProvider() *testing_provider.MockProvider {
228241
229242 configMap := wholeConfigMap ["config" ]
230243
231- // For empty results test case //TODO: Remove?
232- if ami , ok := wholeConfigMap ["ami" ]; ok && ami .AsString () == "ami-nonexistent" {
244+ // For empty results test case
245+ ami , ok := configMap .AsValueMap ()["ami" ]
246+ if ok && ami .AsString () == "ami-nonexistent" {
233247 return providers.ListResourceResponse {
234248 Result : cty .ObjectVal (map [string ]cty.Value {
235- "data" : cty .ListVal ([] cty.Value {} ),
249+ "data" : cty .ListValEmpty ( cty .DynamicPseudoType ),
236250 "config" : configMap ,
237251 }),
238252 }
0 commit comments