mirror of
https://github.com/amir20/dozzle.git
synced 2025-12-21 21:33:18 +01:00
chore: adds more gotests
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -77,3 +78,51 @@ func waitTimeout(wg *sync.WaitGroup, timeout time.Duration) bool {
|
|||||||
return true // timed out
|
return true // timed out
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_createEvent(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
message string
|
||||||
|
streamType StdType
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
want *LogEvent
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "empty message",
|
||||||
|
args: args{
|
||||||
|
message: "",
|
||||||
|
},
|
||||||
|
want: &LogEvent{
|
||||||
|
Message: "",
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
name: "simple json message",
|
||||||
|
args: args{
|
||||||
|
message: "2020-05-13T18:55:37.772853839Z {\"key\": \"value\"}",
|
||||||
|
},
|
||||||
|
want: &LogEvent{
|
||||||
|
Message: map[string]interface{}{
|
||||||
|
"key": "value",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid json message",
|
||||||
|
args: args{
|
||||||
|
message: "2020-05-13T18:55:37.772853839Z {\"key\"}",
|
||||||
|
},
|
||||||
|
want: &LogEvent{
|
||||||
|
Message: "{\"key\"}",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := createEvent(tt.args.message, STDOUT); !reflect.DeepEqual(got.Message, tt.want.Message) {
|
||||||
|
t.Errorf("createEvent() = %v, want %v", got.Message, tt.want.Message)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user