@@ -73,7 +73,7 @@ func TestServerListResource(t *testing.T) {
7373 server * fwserver.Server
7474 request * fwserver.ListRequest
7575 expectedStreamEvents []fwserver.ListResult
76- expectedError diag. Diagnostics
76+ expectedError string
7777 }{
7878 "success-with-zero-results" : {
7979 server : & fwserver.Server {
@@ -89,20 +89,6 @@ func TestServerListResource(t *testing.T) {
8989 },
9090 expectedStreamEvents : []fwserver.ListResult {},
9191 },
92- "success-with-nil-results" : {
93- server : & fwserver.Server {
94- Provider : & testprovider.Provider {},
95- },
96- request : & fwserver.ListRequest {
97- Config : & tfsdk.Config {},
98- ListResource : & testprovider.ListResource {
99- ListMethod : func (ctx context.Context , req list.ListRequest , resp * list.ListResultsStream ) {
100- // Do nothing, so that resp.Results is nil
101- },
102- },
103- },
104- expectedStreamEvents : []fwserver.ListResult {},
105- },
10692 "success-with-multiple-results" : {
10793 server : & fwserver.Server {
10894 Provider : & testprovider.Provider {},
@@ -167,167 +153,17 @@ func TestServerListResource(t *testing.T) {
167153 },
168154 },
169155 },
170- "error-on-nil-config" : {
171- server : & fwserver.Server {
172- Provider : & testprovider.Provider {},
173- },
174- request : & fwserver.ListRequest {
175- Config : nil ,
176- ListResource : & testprovider.ListResource {
177- ListMethod : func (ctx context.Context , req list.ListRequest , resp * list.ListResultsStream ) {
178- resp .Results = list .NoListResults
179- },
180- },
181- },
182- expectedError : diag.Diagnostics {
183- diag .NewErrorDiagnostic ("Invalid ListResource Request" , "Config cannot be nil" ),
184- },
185- expectedStreamEvents : []fwserver.ListResult {},
186- },
187- "error-on-nil-resource-identity" : {
188- server : & fwserver.Server {
189- Provider : & testprovider.Provider {},
190- },
191- request : & fwserver.ListRequest {
192- Config : & tfsdk.Config {},
193- ListResource : & testprovider.ListResource {
194- ListMethod : func (ctx context.Context , req list.ListRequest , resp * list.ListResultsStream ) {
195- resp .Results = slices .Values ([]list.ListResult {
196- {
197- Identity : nil ,
198- Resource : & tfsdk.Resource {
199- Schema : testSchema ,
200- Raw : testResourceValue1 ,
201- },
202- DisplayName : "Test Resource 1" ,
203- },
204- })
205- },
206- },
207- },
208- expectedStreamEvents : []fwserver.ListResult {
209- {
210- Diagnostics : diag.Diagnostics {
211- diag .NewErrorDiagnostic ("Incomplete List Result" , "..." ),
212- },
213- },
214- },
215- },
216- "error-on-null-resource-identity" : {
217- server : & fwserver.Server {
218- Provider : & testprovider.Provider {},
219- },
220- request : & fwserver.ListRequest {
221- Config : & tfsdk.Config {},
222- ListResource : & testprovider.ListResource {
223- ListMethod : func (ctx context.Context , req list.ListRequest , resp * list.ListResultsStream ) {
224- resp .Results = slices .Values ([]list.ListResult {
225- {
226- Identity : & tfsdk.ResourceIdentity {},
227- Resource : & tfsdk.Resource {
228- Schema : testSchema ,
229- Raw : testResourceValue1 ,
230- },
231- DisplayName : "Test Resource 1" ,
232- },
233- })
234- },
235- },
236- },
237- expectedStreamEvents : []fwserver.ListResult {
238- {
239- Diagnostics : diag.Diagnostics {
240- diag .NewErrorDiagnostic ("Incomplete List Result" , "..." ),
241- },
242- },
243- },
244- },
245- "warning-on-missing-resource" : {
246- server : & fwserver.Server {
247- Provider : & testprovider.Provider {},
248- },
249- request : & fwserver.ListRequest {
250- Config : & tfsdk.Config {},
251- IncludeResource : true ,
252- ListResource : & testprovider.ListResource {
253- ListMethod : func (ctx context.Context , req list.ListRequest , resp * list.ListResultsStream ) {
254- resp .Results = slices .Values ([]list.ListResult {
255- {
256- Identity : & tfsdk.ResourceIdentity {
257- Schema : testIdentitySchema ,
258- Raw : testIdentityValue1 ,
259- },
260- Resource : nil ,
261- DisplayName : "Test Resource 1" ,
262- },
263- })
264- },
265- },
266- },
267- expectedStreamEvents : []fwserver.ListResult {
268- {
269- Identity : & tfsdk.ResourceIdentity {
270- Schema : testIdentitySchema ,
271- Raw : testIdentityValue1 ,
272- },
273- DisplayName : "Test Resource 1" ,
274- Diagnostics : diag.Diagnostics {
275- diag .NewWarningDiagnostic ("Incomplete List Result" , "..." ),
276- },
277- },
278- },
279- },
280- "warning-on-null-resource" : {
281- server : & fwserver.Server {
282- Provider : & testprovider.Provider {},
283- },
284- request : & fwserver.ListRequest {
285- Config : & tfsdk.Config {},
286- IncludeResource : true ,
287- ListResource : & testprovider.ListResource {
288- ListMethod : func (ctx context.Context , req list.ListRequest , resp * list.ListResultsStream ) {
289- resp .Results = slices .Values ([]list.ListResult {
290- {
291- Identity : & tfsdk.ResourceIdentity {
292- Schema : testIdentitySchema ,
293- Raw : testIdentityValue1 ,
294- },
295- Resource : & tfsdk.Resource {},
296- DisplayName : "Test Resource 1" ,
297- },
298- })
299- },
300- },
301- },
302- expectedStreamEvents : []fwserver.ListResult {
303- {
304- Identity : & tfsdk.ResourceIdentity {
305- Schema : testIdentitySchema ,
306- Raw : testIdentityValue1 ,
307- },
308- Resource : & tfsdk.Resource {},
309- DisplayName : "Test Resource 1" ,
310- Diagnostics : diag.Diagnostics {
311- diag .NewWarningDiagnostic ("Incomplete List Result" , "..." ),
312- },
313- },
314- },
315- },
316156 }
317157
318158 for name , testCase := range testCases {
319159 t .Run (name , func (t * testing.T ) {
320160 t .Parallel ()
321161
322162 response := & fwserver.ListResultsStream {}
323- err := testCase .server .ListResource (context .Background (), testCase .request , response )
324- if diff := cmp .Diff (testCase .expectedError , err ); diff != "" {
325- t .Errorf ("unexpected error difference: %s" , diff )
326- }
163+ testCase .server .ListResource (context .Background (), testCase .request , response )
327164
328165 opts := cmp.Options {
329166 cmp .Comparer (func (a , b diag.Diagnostics ) bool {
330- // Differences in Detail() are not relevant to correctness of logic
331167 for i := range a {
332168 if a [i ].Severity () != b [i ].Severity () || a [i ].Summary () != b [i ].Summary () {
333169 return false
0 commit comments