summaryrefslogtreecommitdiff
path: root/internal/logging/util_test.go
blob: b26e6e352969d996790fed9532990f843728ab3e (plain)
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
44
45
46
47
48
package logging

import (
	"testing"
	"time"

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

func TestFormatFilePath(t *testing.T) {
	testCases := []struct {
		name     string
		have     string
		now      time.Time
		expected string
	}{
		{
			"ShouldReturnInput",
			"abc 123",
			time.Unix(0, 0).UTC(),
			"abc 123",
		},
		{
			"ShouldReturnStandardWithDateTime",
			"abc %d 123",
			time.Unix(0, 0).UTC(),
			"abc 1970-01-01T00:00:00Z 123",
		},
		{
			"ShouldReturnStandardWithDateTimeFormatter",
			"abc {datetime} 123",
			time.Unix(0, 0).UTC(),
			"abc 1970-01-01T00:00:00Z 123",
		},
		{
			"ShouldReturnStandardWithDateTimeCustomLayout",
			"abc {datetime:Mon Jan 2 15:04:05 MST 2006} 123",
			time.Unix(0, 0).UTC(),
			"abc Thu Jan 1 00:00:00 UTC 1970 123",
		},
	}

	for _, tc := range testCases {
		t.Run(tc.name, func(t *testing.T) {
			assert.Equal(t, tc.expected, FormatFilePath(tc.have, tc.now))
		})
	}
}