-
Notifications
You must be signed in to change notification settings - Fork 0
/
pkg_test.go
69 lines (60 loc) · 1.98 KB
/
pkg_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
package clogger
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSet(t *testing.T) {
/*
Set* without creating an event should not affect ctx,
but should return a new event.
Package calls
*/
t.Run("Set* has no effect on missing event from ctx", func(t *testing.T) {
ctx := context.Background()
Set(ctx, "set_key", "set_val").
SetOnErr("set_err_key", "set_err_value").
SetLabel("set_label_key", "set_label_value")
assert.NotNil(t, ctx)
ev := eventFromCtx(ctx)
ev.End()
assert.NotNil(t, ev)
assert.NotEqual(t, "set_val", ev.fields.retrieve("set_key"))
assert.NotEqual(t, "set_err_value", ev.fields.retrieve("set_err_key"))
assert.NotEqual(t, "set_label_value", ev.fields.retrieve("set_label_key"))
})
/*
Test with (a properly) created event
Method calls
*/
t.Run("Method calls: event is persisted and populated", func(t *testing.T) {
ctx := context.Background()
cctx, ev := NewEvent(ctx, "A new event happened.")
ev.Set("set_key", "set_value").
SetOnErr("set_err_key", "set_err_value").
SetLabel("set_label_key", "set_label_value")
ev.End()
assert.NotNil(t, cctx)
assert.NotNil(t, ev)
assert.Equal(t, "set_value", ev.fields.retrieve("set_key"))
assert.Equal(t, "set_err_value", ev.errFields.retrieve("set_err_key"))
assert.Equal(t, "set_label_value", ev.labels.retrieve("set_label_key"))
})
/*
Test with (a properly) created event
Package calls
*/
t.Run("Package calls: event is persisted and populated", func(t *testing.T) {
ctx := context.Background()
cctx, ev := NewEvent(ctx, "A new event happened.")
Set(cctx, "set_key", "set_value").
SetOnErr("set_err_key", "set_err_value").
SetLabel("set_label_key", "set_label_value")
ev.End()
assert.NotNil(t, cctx)
assert.NotNil(t, ev)
assert.Equal(t, "set_value", ev.fields.retrieve("set_key"))
assert.Equal(t, "set_err_value", ev.errFields.retrieve("set_err_key"))
assert.Equal(t, "set_label_value", ev.labels.retrieve("set_label_key"))
})
}