@@ -11,6 +11,7 @@ import (
1111 "testing"
1212
1313 "github.com/google/go-cmp/cmp"
14+ "github.com/google/go-cmp/cmp/cmpopts"
1415)
1516
1617func TestOrganizationsService_GetAllCustomProperties (t * testing.T ) {
@@ -484,3 +485,255 @@ func TestOrganizationsService_CreateOrUpdateRepoCustomPropertyValues(t *testing.
484485 return client .Organizations .CreateOrUpdateRepoCustomPropertyValues (ctx , "o" , nil , nil )
485486 })
486487}
488+
489+ func TestCustomPropertyDefaultValueString (t * testing.T ) {
490+ t .Parallel ()
491+ for _ , d := range []struct {
492+ testName string
493+ property * CustomProperty
494+ ok bool
495+ want string
496+ }{
497+ {
498+ testName : "invalid_type" ,
499+ property : & CustomProperty {
500+ ValueType : PropertyValueTypeMultiSelect ,
501+ DefaultValue : []string {"a" , "b" },
502+ },
503+ ok : false ,
504+ want : "" ,
505+ },
506+ {
507+ testName : "string_invalid_value" ,
508+ property : & CustomProperty {
509+ ValueType : PropertyValueTypeString ,
510+ DefaultValue : []string {"a" , "b" },
511+ },
512+ ok : false ,
513+ want : "" ,
514+ },
515+ {
516+ testName : "string_nil_value" ,
517+ property : & CustomProperty {
518+ ValueType : PropertyValueTypeString ,
519+ DefaultValue : nil ,
520+ },
521+ ok : false ,
522+ want : "" ,
523+ },
524+ {
525+ testName : "string_value" ,
526+ property : & CustomProperty {
527+ ValueType : PropertyValueTypeString ,
528+ DefaultValue : "test-string" ,
529+ },
530+ ok : true ,
531+ want : "test-string" ,
532+ },
533+ {
534+ testName : "single_select_invalid_value" ,
535+ property : & CustomProperty {
536+ ValueType : PropertyValueTypeSingleSelect ,
537+ DefaultValue : []string {"a" , "b" },
538+ },
539+ ok : false ,
540+ want : "" ,
541+ },
542+ {
543+ testName : "single_select_nil_value" ,
544+ property : & CustomProperty {
545+ ValueType : PropertyValueTypeSingleSelect ,
546+ DefaultValue : nil ,
547+ },
548+ ok : false ,
549+ want : "" ,
550+ },
551+ {
552+ testName : "single_select_value" ,
553+ property : & CustomProperty {
554+ ValueType : PropertyValueTypeSingleSelect ,
555+ DefaultValue : "test-string" ,
556+ },
557+ ok : true ,
558+ want : "test-string" ,
559+ },
560+ {
561+ testName : "url_invalid_value" ,
562+ property : & CustomProperty {
563+ ValueType : PropertyValueTypeURL ,
564+ DefaultValue : []string {"a" , "b" },
565+ },
566+ ok : false ,
567+ want : "" ,
568+ },
569+ {
570+ testName : "url_nil_value" ,
571+ property : & CustomProperty {
572+ ValueType : PropertyValueTypeURL ,
573+ DefaultValue : nil ,
574+ },
575+ ok : false ,
576+ want : "" ,
577+ },
578+ {
579+ testName : "url_value" ,
580+ property : & CustomProperty {
581+ ValueType : PropertyValueTypeURL ,
582+ DefaultValue : "http://example.com" ,
583+ },
584+ ok : true ,
585+ want : "http://example.com" ,
586+ },
587+ } {
588+ t .Run (d .testName , func (t * testing.T ) {
589+ t .Parallel ()
590+ got , ok := d .property .DefaultValueString ()
591+
592+ if ok != d .ok {
593+ t .Fatalf ("CustomProperty.DefaultValueString set ok to %+v, want %+v" , ok , d .ok )
594+ }
595+
596+ if got != d .want {
597+ t .Fatalf ("CustomProperty.DefaultValueString returned %+v, want %+v" , got , d .want )
598+ }
599+ })
600+ }
601+ }
602+
603+ func TestCustomPropertyDefaultValueStrings (t * testing.T ) {
604+ t .Parallel ()
605+ for _ , d := range []struct {
606+ testName string
607+ property * CustomProperty
608+ ok bool
609+ want []string
610+ }{
611+ {
612+ testName : "invalid_type" ,
613+ property : & CustomProperty {
614+ ValueType : PropertyValueTypeString ,
615+ DefaultValue : "test" ,
616+ },
617+ ok : false ,
618+ want : []string {},
619+ },
620+ {
621+ testName : "multi_select_invalid_value" ,
622+ property : & CustomProperty {
623+ ValueType : PropertyValueTypeMultiSelect ,
624+ DefaultValue : "test" ,
625+ },
626+ ok : false ,
627+ want : []string {},
628+ },
629+ {
630+ testName : "multi_select_nil_value" ,
631+ property : & CustomProperty {
632+ ValueType : PropertyValueTypeMultiSelect ,
633+ DefaultValue : nil ,
634+ },
635+ ok : false ,
636+ want : []string {},
637+ },
638+ {
639+ testName : "multi_select_single_value" ,
640+ property : & CustomProperty {
641+ ValueType : PropertyValueTypeMultiSelect ,
642+ DefaultValue : []string {"a" },
643+ },
644+ ok : true ,
645+ want : []string {"a" },
646+ },
647+ {
648+ testName : "multi_select_multi_value" ,
649+ property : & CustomProperty {
650+ ValueType : PropertyValueTypeMultiSelect ,
651+ DefaultValue : []string {"a" , "b" },
652+ },
653+ ok : true ,
654+ want : []string {"a" , "b" },
655+ },
656+ } {
657+ t .Run (d .testName , func (t * testing.T ) {
658+ t .Parallel ()
659+ got , ok := d .property .DefaultValueStrings ()
660+
661+ if ok != d .ok {
662+ t .Fatalf ("CustomProperty.DefaultValueStrings set ok to %+v, want %+v" , ok , d .ok )
663+ }
664+
665+ if ! cmp .Equal (got , d .want , cmpopts .EquateEmpty ()) {
666+ t .Fatalf ("CustomProperty.DefaultValueStrings returned %+v, want %+v" , got , d .want )
667+ }
668+ })
669+ }
670+ }
671+
672+ func TestCustomPropertyDefaultValueBool (t * testing.T ) {
673+ t .Parallel ()
674+ for _ , d := range []struct {
675+ testName string
676+ property * CustomProperty
677+ ok bool
678+ want bool
679+ }{
680+ {
681+ testName : "invalid_type" ,
682+ property : & CustomProperty {
683+ ValueType : PropertyValueTypeString ,
684+ DefaultValue : "test" ,
685+ },
686+ ok : false ,
687+ want : false ,
688+ },
689+ {
690+ testName : "true_false_invalid_value" ,
691+ property : & CustomProperty {
692+ ValueType : PropertyValueTypeTrueFalse ,
693+ DefaultValue : "test" ,
694+ },
695+ ok : false ,
696+ want : false ,
697+ },
698+ {
699+ testName : "true_false_nil_value" ,
700+ property : & CustomProperty {
701+ ValueType : PropertyValueTypeTrueFalse ,
702+ DefaultValue : nil ,
703+ },
704+ ok : false ,
705+ want : false ,
706+ },
707+ {
708+ testName : "true_false_true_value" ,
709+ property : & CustomProperty {
710+ ValueType : PropertyValueTypeTrueFalse ,
711+ DefaultValue : "true" ,
712+ },
713+ ok : true ,
714+ want : true ,
715+ },
716+ {
717+ testName : "true_false_false_value" ,
718+ property : & CustomProperty {
719+ ValueType : PropertyValueTypeTrueFalse ,
720+ DefaultValue : "false" ,
721+ },
722+ ok : true ,
723+ want : false ,
724+ },
725+ } {
726+ t .Run (d .testName , func (t * testing.T ) {
727+ t .Parallel ()
728+ got , ok := d .property .DefaultValueBool ()
729+
730+ if ok != d .ok {
731+ t .Fatalf ("CustomProperty.DefaultValueBool set ok to %+v, want %+v" , ok , d .ok )
732+ }
733+
734+ if ok != d .ok {
735+ t .Fatalf ("CustomProperty.DefaultValueBool returned %+v, want %+v" , got , d .want )
736+ }
737+ })
738+ }
739+ }
0 commit comments