Initial cloud-services repo - gateway service + pkg modules
This commit is contained in:
49
pkg/common/trex_config_test.go
Normal file
49
pkg/common/trex_config_test.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"reflect"
|
||||
"fiskerinc.com/modules/logger"
|
||||
)
|
||||
|
||||
func TestStringToTrexLogLevel(t *testing.T){
|
||||
level := UnmarshalLogLevelString("Warning")
|
||||
|
||||
if level != Warn{
|
||||
t.Fail()
|
||||
}
|
||||
|
||||
level = UnmarshalLogLevelString("ErRoR")
|
||||
|
||||
if level != Error{
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogLevelToLogger(t *testing.T){
|
||||
log := Debug.ToLoggerLevel()
|
||||
if !compareLevel(log(), logger.Debug()){
|
||||
t.Error("Debug did not give debug logger")
|
||||
}
|
||||
|
||||
log = Error.ToLoggerLevel()
|
||||
if !compareLevel(log(), logger.Error()){
|
||||
t.Error("Error did not give error logger")
|
||||
}
|
||||
|
||||
log = Critical.ToLoggerLevel()
|
||||
if !compareLevel(log(), logger.Error()){
|
||||
t.Error("Critical did not give error logger")
|
||||
}
|
||||
}
|
||||
|
||||
func compareLevel(our, theirs *logger.Event)(match bool){
|
||||
// If the log level is too low, such as debug, the event comes back as null
|
||||
// Surprisingly calling .Msg does not cause an error on it though
|
||||
if *our == *theirs{
|
||||
return true
|
||||
}
|
||||
ourVal := reflect.ValueOf(*our).FieldByName("level")
|
||||
theirVal := reflect.ValueOf(*theirs).FieldByName("level")
|
||||
return ourVal.Int() == theirVal.Int()
|
||||
}
|
||||
Reference in New Issue
Block a user