1
0
Fork 0
mirror of https://github.com/eosswedenorg/antelope-api-healthcheck synced 2026-06-18 05:00:03 +02:00

Adding src/helpers.go

This commit is contained in:
Henrik Hautakoski 2022-10-20 15:09:21 +02:00
parent da28a68943
commit 704965b9cc
No known key found for this signature in database
GPG key ID: 608414D93E862CCD
2 changed files with 49 additions and 0 deletions

20
src/helpers.go Normal file
View file

@ -0,0 +1,20 @@
package main
import (
log "github.com/inconshreveable/log15"
)
func parseLogFormatter(name string) log.Format {
switch name {
case "logfmt" :
return log.LogfmtFormat()
case "json" :
return log.JsonFormat()
case "json-pretty" :
return log.JsonFormatEx(true, true)
default :
return log.TerminalFormat()
}
}

29
src/helpers_test.go Normal file
View file

@ -0,0 +1,29 @@
package main
import (
"reflect"
"testing"
log "github.com/inconshreveable/log15"
)
func Test_parseLogFormatter(t *testing.T) {
tests := []struct {
name string
arg string
want log.Format
}{
{ "Default", "", log.TerminalFormat() },
{ "LogFmt", "logfmt", log.LogfmtFormat() },
{ "Json", "json", log.JsonFormat() },
{ "JsonPretty", "json-pretty", log.JsonFormat() },
{ "Unknown", "unknown", log.TerminalFormat() },
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := parseLogFormatter(tt.arg); reflect.ValueOf(got).Pointer() != reflect.ValueOf(tt.want).Pointer() {
t.Errorf("parseLogFormatter() = %v, want %v", got, tt.want)
}
})
}
}