File tree Expand file tree Collapse file tree 2 files changed +54
-1
lines changed Expand file tree Collapse file tree 2 files changed +54
-1
lines changed Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ func NewProtobufClient(endpoint string, config Config) *Client {
8888}
8989
9090func (c * Client ) logLevelEnabled (level LogLevel ) bool {
91- return level >= c .config .LogLevel
91+ return c . config . LogLevel > LogLevelNone && level >= c .config .LogLevel
9292}
9393
9494func (c * Client ) log (level LogLevel , message string , fields map [string ]string ) {
Original file line number Diff line number Diff line change @@ -649,3 +649,56 @@ func TestHandlePublishFossil(t *testing.T) {
649649 testFossil (t , client )
650650 })
651651}
652+
653+ func TestLogLevel (t * testing.T ) {
654+ cases := []struct {
655+ name string
656+ configuredLevel LogLevel
657+ requestedLevel LogLevel
658+ enabled bool
659+ }{
660+ {
661+ "configured with debug, requested trace" ,
662+ LogLevelDebug ,
663+ LogLevelTrace ,
664+ false ,
665+ },
666+ {
667+ "configured with none, requested trace" ,
668+ LogLevelNone ,
669+ LogLevelTrace ,
670+ false ,
671+ },
672+ {
673+ "configured with none, requested dabug" ,
674+ LogLevelNone ,
675+ LogLevelDebug ,
676+ false ,
677+ },
678+ {
679+ "configured with trace, requested debug" ,
680+ LogLevelTrace ,
681+ LogLevelDebug ,
682+ true ,
683+ },
684+ {
685+ "configured with debug, requested debug" ,
686+ LogLevelDebug ,
687+ LogLevelDebug ,
688+ true ,
689+ },
690+ }
691+
692+ for _ , tc := range cases {
693+ t .Run (tc .name , func (t * testing.T ) {
694+ client := NewJsonClient ("ws://localhost:9000/connection/websocket" , Config {
695+ LogLevel : tc .configuredLevel ,
696+ })
697+
698+ got := client .logLevelEnabled (tc .requestedLevel )
699+ if got != tc .enabled {
700+ t .Errorf ("expected %v got %v" , tc .enabled , got )
701+ }
702+ })
703+ }
704+ }
You can’t perform that action at this time.
0 commit comments