forked from hashicorp/go-eventlogger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event_test.go
78 lines (73 loc) · 1.79 KB
/
event_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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package eventlogger
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestEvent_FormattedAs(t *testing.T) {
tests := []struct {
name string
e *Event
formatType string
formatttedValue []byte
want []byte
}{
{
name: "text",
e: &Event{Formatted: map[string][]byte{}},
formatType: "text",
formatttedValue: []byte("text-format"),
want: []byte("text-format"),
},
{
name: "nil-formatted-map",
e: &Event{Formatted: nil},
formatType: "text",
formatttedValue: []byte("text-format"),
want: []byte("text-format"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
tt.e.FormattedAs(tt.formatType, tt.formatttedValue)
got, ok := tt.e.Format(tt.formatType)
require.Truef(ok, "format %s not found", tt.formatType)
assert.Equal(tt.want, got)
})
}
}
func TestEvent_Format(t *testing.T) {
tests := []struct {
name string
e *Event
formatType string
want []byte
wantOk bool
}{
{
name: "found",
e: &Event{Formatted: map[string][]byte{"found": []byte("found")}},
formatType: "found",
want: []byte("found"),
wantOk: true,
},
{
name: "not-ok-with-nil-Formatted-map",
e: &Event{},
formatType: "not-ok",
want: nil,
wantOk: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert := assert.New(t)
got, gotOk := tt.e.Format(tt.formatType)
assert.Equal(tt.wantOk, gotOk)
assert.Equal(tt.want, got)
})
}
}