@@ -265,15 +265,13 @@ func TestProjectsService_ListProjectFieldsForOrg(t *testing.T) {
265
265
t .Parallel ()
266
266
client , mux , _ := setup (t )
267
267
268
- // Combined handler: supports initial test case and dual before/after validation scenario.
269
268
mux .HandleFunc ("/orgs/o/projectsV2/1/fields" , func (w http.ResponseWriter , r * http.Request ) {
270
269
testMethod (t , r , "GET" )
271
270
q := r .URL .Query ()
272
271
if q .Get ("before" ) == "b" && q .Get ("after" ) == "a" {
273
272
fmt .Fprint (w , `[]` )
274
273
return
275
274
}
276
- // default expectation for main part of test
277
275
testFormValues (t , r , values {"q" : "text" , "after" : "2" , "before" : "1" })
278
276
fmt .Fprint (w , `[
279
277
{
@@ -321,25 +319,37 @@ func TestProjectsService_ListProjectFieldsForOrg(t *testing.T) {
321
319
t .Fatalf ("Projects.ListProjectFieldsForOrg returned %d fields, want 2" , len (fields ))
322
320
}
323
321
324
- // Validate first field (with options)
325
322
field1 := fields [0 ]
326
323
if field1 .ID == nil || * field1 .ID != 1 || field1 .Name != "Status" || field1 .DataType != "single_select" {
327
- t .Errorf ("First field: got ID=%v, Name=%s, DataType=%s; want 1, Status, single_select" ,
328
- field1 .ID , field1 .Name , field1 .DataType )
324
+ t .Errorf ("First field: got ID=%v, Name=%s, DataType=%s; want 1, Status, single_select" , field1 .ID , field1 .Name , field1 .DataType )
329
325
}
330
326
if len (field1 .Options ) != 2 {
331
327
t .Errorf ("First field options: got %d, want 2" , len (field1 .Options ))
332
- }
333
- if field1 .Options [0 ].Name != "Todo" || field1 .Options [1 ].Name != "In Progress" {
334
- t .Errorf ("First field option names: got %s, %s; want Todo, In Progress" ,
335
- field1 .Options [0 ].Name , field1 .Options [1 ].Name )
328
+ } else {
329
+ getName := func (o * any ) string {
330
+ if o == nil || * o == nil {
331
+ return ""
332
+ }
333
+ switch v := (* o ).(type ) {
334
+ case map [string ]any :
335
+ if n , ok := v ["name" ].(string ); ok {
336
+ return n
337
+ }
338
+ default :
339
+ // fall back to fmt for debug; reflection can be added if needed.
340
+ }
341
+ return ""
342
+ }
343
+ name0 , name1 := getName (field1 .Options [0 ]), getName (field1 .Options [1 ])
344
+ if name0 != "Todo" || name1 != "In Progress" {
345
+ t .Errorf ("First field option names: got %q, %q; want Todo, In Progress" , name0 , name1 )
346
+ }
336
347
}
337
348
338
349
// Validate second field (without options)
339
350
field2 := fields [1 ]
340
351
if field2 .ID == nil || * field2 .ID != 2 || field2 .Name != "Priority" || field2 .DataType != "text" {
341
- t .Errorf ("Second field: got ID=%v, Name=%s, DataType=%s; want 2, Priority, text" ,
342
- field2 .ID , field2 .Name , field2 .DataType )
352
+ t .Errorf ("Second field: got ID=%v, Name=%s, DataType=%s; want 2, Priority, text" , field2 .ID , field2 .Name , field2 .DataType )
343
353
}
344
354
if len (field2 .Options ) != 0 {
345
355
t .Errorf ("Second field options: got %d, want 0" , len (field2 .Options ))
@@ -403,7 +413,6 @@ func TestProjectsService_ListProjectFieldsForOrg_pagination(t *testing.T) {
403
413
t .Fatalf ("expected resp.After=cursor2 got %q" , resp .After )
404
414
}
405
415
406
- // Use resp.After as opts.After for next page
407
416
opts := & ListProjectsOptions {ListProjectsPaginationOptions : ListProjectsPaginationOptions {After : resp .After }}
408
417
second , resp2 , err := client .Projects .ListProjectFieldsForOrg (ctx , "o" , 1 , opts )
409
418
if err != nil {
@@ -417,7 +426,6 @@ func TestProjectsService_ListProjectFieldsForOrg_pagination(t *testing.T) {
417
426
}
418
427
}
419
428
420
- // Marshal test ensures V2 fields marshal correctly.
421
429
func TestProjectV2_Marshal (t * testing.T ) {
422
430
t .Parallel ()
423
431
testJSONMarshal (t , & ProjectV2 {}, "{}" )
@@ -443,47 +451,48 @@ func TestProjectV2_Marshal(t *testing.T) {
443
451
testJSONMarshal (t , p , want )
444
452
}
445
453
446
- // Marshal test ensures V2 field structures marshal correctly.
447
454
func TestProjectV2Field_Marshal (t * testing.T ) {
448
455
t .Parallel ()
449
- testJSONMarshal (t , & ProjectV2Field {}, "{}" )
450
- testJSONMarshal (t , & ProjectV2FieldOption {}, "{}" )
456
+ testJSONMarshal (t , & ProjectV2Field {}, "{}" ) // empty struct
457
+ testJSONMarshal (t , & ProjectV2FieldOption {}, "{}" ) // option struct still individually testable
458
+
459
+ type optStruct struct {
460
+ Color string `json:"color,omitempty"`
461
+ Description string `json:"description,omitempty"`
462
+ ID string `json:"id,omitempty"`
463
+ Name string `json:"name,omitempty"`
464
+ }
465
+ optVal := & optStruct {Color : "blue" , Description : "Tasks to be done" , ID : "option1" , Name : "Todo" }
466
+ var optAny any = optVal
451
467
452
468
field := & ProjectV2Field {
453
- ID : Ptr (int64 (1 )),
454
- NodeID : "node_1" ,
455
- Name : "Status" ,
456
- DataType : "single_select" ,
457
- URL : "https://api.github.com/projects/1/fields/field1" ,
458
- Options : []* ProjectV2FieldOption {
459
- {
460
- ID : "option1" ,
461
- Name : "Todo" ,
462
- Color : "blue" ,
463
- Description : "Tasks to be done" ,
464
- },
465
- },
469
+ ID : Ptr (int64 (1 )),
470
+ NodeID : "node_1" ,
471
+ Name : "Status" ,
472
+ DataType : "single_select" ,
473
+ URL : "https://api.github.com/projects/1/fields/field1" ,
474
+ Options : []* any {& optAny },
466
475
CreatedAt : & Timestamp {referenceTime },
467
476
UpdatedAt : & Timestamp {referenceTime },
468
477
}
469
478
470
479
want := `{
471
480
"id": 1,
472
- "node_id": "node_1",
473
- "name": "Status",
474
- "dataType": "single_select",
475
- "url": "https://api.github.com/projects/1/fields/field1",
476
- "options": [
477
- {
478
- "id": "option1",
479
- "name": "Todo",
480
- "color": "blue",
481
- "description": "Tasks to be done"
482
- }
483
- ],
484
- "created_at": ` + referenceTimeStr + `,
485
- "updated_at": ` + referenceTimeStr + `
486
- }`
481
+ "node_id": "node_1",
482
+ "name": "Status",
483
+ "dataType": "single_select",
484
+ "url": "https://api.github.com/projects/1/fields/field1",
485
+ "options": [
486
+ {
487
+ "id": "option1",
488
+ "name": "Todo",
489
+ "color": "blue",
490
+ "description": "Tasks to be done"
491
+ }
492
+ ],
493
+ "created_at": ` + referenceTimeStr + `,
494
+ "updated_at": ` + referenceTimeStr + `
495
+ }`
487
496
488
497
testJSONMarshal (t , field , want )
489
498
}
0 commit comments