@@ -602,6 +602,110 @@ func TestResolve_LocalFieldNilValue(t *testing.T) {
602602 assert .Nil (t , val )
603603}
604604
605+ func TestResolve_UserGlobalAsLocalConfigField (t * testing.T ) {
606+ tests := []struct {
607+ name string
608+ flagName string
609+ setup func (conf configuration.Configuration )
610+ org string
611+ folder string
612+ wantVal any
613+ wantSource configresolver.ConfigSource
614+ }{
615+ {
616+ name : "machine scope: LocalConfigField Changed=true returns Value" ,
617+ flagName : "api_endpoint" ,
618+ setup : func (conf configuration.Configuration ) {
619+ conf .Set (configresolver .UserGlobalKey ("api_endpoint" ), & configresolver.LocalConfigField {Value : "user-ep" , Changed : true })
620+ },
621+ org : "org1" ,
622+ folder : "" ,
623+ wantVal : "user-ep" ,
624+ wantSource : configresolver .ConfigSourceUserGlobal ,
625+ },
626+ {
627+ name : "machine scope: LocalConfigField Changed=false falls through to default" ,
628+ flagName : "api_endpoint" ,
629+ setup : func (conf configuration.Configuration ) {
630+ conf .Set (configresolver .UserGlobalKey ("api_endpoint" ), & configresolver.LocalConfigField {Value : "ignored" , Changed : false })
631+ },
632+ org : "org1" ,
633+ folder : "" ,
634+ wantVal : nil ,
635+ wantSource : configresolver .ConfigSourceDefault ,
636+ },
637+ {
638+ name : "machine scope: LocalConfigField Changed=false falls through to remote" ,
639+ flagName : "api_endpoint" ,
640+ setup : func (conf configuration.Configuration ) {
641+ conf .Set (configresolver .UserGlobalKey ("api_endpoint" ), & configresolver.LocalConfigField {Value : "ignored" , Changed : false })
642+ conf .Set (configresolver .RemoteMachineKey ("api_endpoint" ), & configresolver.RemoteConfigField {Value : "remote-ep" , IsLocked : false })
643+ },
644+ org : "org1" ,
645+ folder : "" ,
646+ wantVal : "remote-ep" ,
647+ wantSource : configresolver .ConfigSourceRemote ,
648+ },
649+ {
650+ name : "folder scope: LocalConfigField Changed=true returns Value" ,
651+ flagName : "snyk_code_enabled" ,
652+ setup : func (conf configuration.Configuration ) {
653+ conf .Set (configresolver .UserGlobalKey ("snyk_code_enabled" ), & configresolver.LocalConfigField {Value : true , Changed : true })
654+ },
655+ org : "org1" ,
656+ folder : "/proj" ,
657+ wantVal : true ,
658+ wantSource : configresolver .ConfigSourceUserGlobal ,
659+ },
660+ {
661+ name : "folder scope: LocalConfigField Changed=false falls through to default" ,
662+ flagName : "snyk_code_enabled" ,
663+ setup : func (conf configuration.Configuration ) {
664+ conf .Set (configresolver .UserGlobalKey ("snyk_code_enabled" ), & configresolver.LocalConfigField {Value : true , Changed : false })
665+ },
666+ org : "org1" ,
667+ folder : "/proj" ,
668+ wantVal : nil ,
669+ wantSource : configresolver .ConfigSourceDefault ,
670+ },
671+ {
672+ name : "folder scope: LocalConfigField Changed=false falls through to remote org" ,
673+ flagName : "snyk_code_enabled" ,
674+ setup : func (conf configuration.Configuration ) {
675+ conf .Set (configresolver .UserGlobalKey ("snyk_code_enabled" ), & configresolver.LocalConfigField {Value : true , Changed : false })
676+ conf .Set (configresolver .RemoteOrgKey ("org1" , "snyk_code_enabled" ), & configresolver.RemoteConfigField {Value : false , IsLocked : false })
677+ },
678+ org : "org1" ,
679+ folder : "/proj" ,
680+ wantVal : false ,
681+ wantSource : configresolver .ConfigSourceRemote ,
682+ },
683+ }
684+
685+ for _ , tc := range tests {
686+ t .Run (tc .name , func (t * testing.T ) {
687+ fs := newTestFlagSet ()
688+ conf := configuration .NewWithOpts ()
689+ tc .setup (conf )
690+ r := newResolver (conf , fs )
691+
692+ val , src := r .Resolve (tc .flagName , tc .org , tc .folder )
693+ assert .Equal (t , tc .wantVal , val )
694+ assert .Equal (t , tc .wantSource , src )
695+ })
696+ }
697+ }
698+
699+ func TestResolveBool_UserGlobalAsLocalConfigField (t * testing.T ) {
700+ fs := newTestFlagSet ()
701+ conf := configuration .NewWithOpts ()
702+ name := "snyk_code_enabled"
703+ conf .Set (configresolver .UserGlobalKey (name ), & configresolver.LocalConfigField {Value : true , Changed : true })
704+ r := newResolver (conf , fs )
705+ got := r .ResolveBool (name , "org1" , "/proj" )
706+ assert .True (t , got , "ResolveBool must unwrap LocalConfigField.Value, not see the struct pointer" )
707+ }
708+
605709func TestResolve_UserGlobalKeyDeleted (t * testing.T ) {
606710 fs := newTestFlagSet ()
607711 conf := configuration .NewWithOpts ()
0 commit comments