@@ -431,6 +431,87 @@ func TestUpdateMask(t *testing.T) {
431431 }
432432}
433433
434+ func TestNormalizeAssigneeMode (t * testing.T ) {
435+ tests := []struct {
436+ name string
437+ mode string
438+ add []string
439+ remove []string
440+ wantMode string
441+ wantOpts bool
442+ wantAdd []string
443+ wantRemove []string
444+ wantErrSubstr string
445+ }{
446+ {
447+ name : "no mode or students returns empty" ,
448+ wantMode : "" ,
449+ wantOpts : false ,
450+ },
451+ {
452+ name : "mode only uppercases" ,
453+ mode : "all_students" ,
454+ wantMode : "ALL_STUDENTS" ,
455+ wantOpts : false ,
456+ },
457+ {
458+ name : "students default mode" ,
459+ add : []string {"a" , "b" },
460+ remove : []string {"c" },
461+ wantMode : "INDIVIDUAL_STUDENTS" ,
462+ wantOpts : true ,
463+ wantAdd : []string {"a" , "b" },
464+ wantRemove : []string {"c" },
465+ },
466+ {
467+ name : "students with explicit mode" ,
468+ mode : "INDIVIDUAL_STUDENTS" ,
469+ add : []string {"a" },
470+ wantMode : "INDIVIDUAL_STUDENTS" ,
471+ wantOpts : true ,
472+ wantAdd : []string {"a" },
473+ },
474+ {
475+ name : "students with invalid mode errors" ,
476+ mode : "ALL_STUDENTS" ,
477+ add : []string {"a" },
478+ wantErrSubstr : "INDIVIDUAL_STUDENTS" ,
479+ },
480+ }
481+
482+ for _ , tt := range tests {
483+ t .Run (tt .name , func (t * testing.T ) {
484+ gotMode , gotOpts , err := normalizeAssigneeMode (tt .mode , tt .add , tt .remove )
485+ if tt .wantErrSubstr != "" {
486+ if err == nil {
487+ t .Fatal ("expected error, got nil" )
488+ }
489+ if ! strings .Contains (err .Error (), tt .wantErrSubstr ) {
490+ t .Fatalf ("error %q does not contain %q" , err .Error (), tt .wantErrSubstr )
491+ }
492+ return
493+ }
494+ if err != nil {
495+ t .Fatalf ("unexpected error: %v" , err )
496+ }
497+ if gotMode != tt .wantMode {
498+ t .Errorf ("mode = %q, want %q" , gotMode , tt .wantMode )
499+ }
500+ if (gotOpts != nil ) != tt .wantOpts {
501+ t .Fatalf ("opts nil = %v, want %v" , gotOpts == nil , ! tt .wantOpts )
502+ }
503+ if tt .wantOpts {
504+ if strings .Join (gotOpts .AddStudentIds , "," ) != strings .Join (tt .wantAdd , "," ) {
505+ t .Errorf ("add = %v, want %v" , gotOpts .AddStudentIds , tt .wantAdd )
506+ }
507+ if strings .Join (gotOpts .RemoveStudentIds , "," ) != strings .Join (tt .wantRemove , "," ) {
508+ t .Errorf ("remove = %v, want %v" , gotOpts .RemoveStudentIds , tt .wantRemove )
509+ }
510+ }
511+ })
512+ }
513+ }
514+
434515func TestParseFloat (t * testing.T ) {
435516 tests := []struct {
436517 name string
0 commit comments