1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-21 13:23:07 +01:00

chore: adds more gotests

This commit is contained in:
Amir Raminfar
2023-07-15 13:07:05 -07:00
parent 079ac56442
commit c774ba7edb

View File

@@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"encoding/binary"
"reflect"
"strings"
"sync"
"testing"
@@ -77,3 +78,51 @@ func waitTimeout(wg *sync.WaitGroup, timeout time.Duration) bool {
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)
}
})
}
}