aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/internal/vespa/log_test.go
blob: 2d0c75d0a0ad78dacc968f03b68c6ba4f2c7ba7d (plain) (blame)
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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package vespa

import (
	"testing"
	"time"

	"github.com/stretchr/testify/assert"
)

func TestParseLogEntry(t *testing.T) {
	expected := LogEntry{
		Time:      time.Date(2021, 9, 27, 10, 31, 30, 905535000, time.UTC),
		Host:      "host1a.dev.aws-us-east-1c",
		Service:   "logserver-container",
		Component: "Container.com.yahoo.container.jdisc.ConfiguredApplication",
		Level:     "info",
		Message:   "Switching to the latest deployed set of configurations and components. Application config generation: 52532",
	}
	in := "1632738690.905535	host1a.dev.aws-us-east-1c	806/53	logserver-container	Container.com.yahoo.container.jdisc.ConfiguredApplication	info	Switching to the latest deployed set of configurations and components. Application config generation: 52532"
	logEntry, err := ParseLogEntry(in)
	assert.Nil(t, err)
	assert.Equal(t, expected, logEntry)

	formatted := "[2021-09-27 10:31:30.905535] host1a.dev.aws-us-east-1c info    logserver-container Container.com.yahoo.container.jdisc.ConfiguredApplication\tSwitching to the latest deployed set of configurations and components. Application config generation: 52532"
	assert.Equal(t, formatted, logEntry.Format(false))

	in = "1632738690.905535	host1a.dev.aws-us-east-1c	806/53	logserver-container	Container.com.yahoo.container.jdisc.ConfiguredApplication	info	message containing newline\\nand\\ttab"
	logEntry, err = ParseLogEntry(in)
	assert.Nil(t, err)
	assert.Equal(t, "[2021-09-27 10:31:30.905535] host1a.dev.aws-us-east-1c info    logserver-container Container.com.yahoo.container.jdisc.ConfiguredApplication\tmessage containing newline\nand\ttab", logEntry.Format(true))
}