-
Notifications
You must be signed in to change notification settings - Fork 3
/
read_test.go
43 lines (37 loc) · 1.22 KB
/
read_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package logfrog
import (
"fmt"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
const simpleLine = `{"level":"info"}`
func TestRead(t *testing.T) {
_, _, errReadCrap := read("[crap")
require.Error(t, errReadCrap)
_, logData, errRead := read(simpleLine)
require.NoError(t, errRead)
assert.Equal(t, "info", logData["level"])
}
func TestReadDockerComposeLine(t *testing.T) {
expectedLabel := "some sörvice"
label, logData, errRead := readDockerComposeLine(" " + expectedLabel + " | " + simpleLine)
assert.Equal(t, expectedLabel, label)
require.NoError(t, errRead)
assert.Equal(t, "info", logData["level"])
}
func TestReadGoGrappleLine(t *testing.T) {
expectedMessage := "just a message"
msgJSON := `{"msg":"` + expectedMessage + `"}`
label, logData, errRead := readGograppleLine(msgJSON)
assert.Equal(t, "dlv", label)
require.NoError(t, errRead)
assert.Equal(t, expectedMessage, logData["msg"])
nested := strings.ReplaceAll(msgJSON, `"`, "\\\"")
processMsg := fmt.Sprintf(`{"msg": "%s"}`, nested)
label, logData, errRead = readGograppleLine(processMsg)
assert.Equal(t, "process", label)
require.NoError(t, errRead)
assert.Equal(t, expectedMessage, logData["msg"])
}