-
Notifications
You must be signed in to change notification settings - Fork 0
/
t1_test.go
44 lines (36 loc) · 1.49 KB
/
t1_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
package appcron
import (
"errors"
"testing"
"time"
)
//----------------------------------------------------------------------------------------------------------------------------//
func TestCronlog(t *testing.T) {
type paramsBlock struct {
err error
msg string
kv []any
expect string
}
err := errors.New("Something went wrong")
msg := "Test message"
params := []paramsBlock{
{nil, "", []any{}, "[cron] "},
{nil, "", []any{"p1", "v1", "p2", 3, "p3", time.Unix(60, 123456789).UTC()}, "[cron] p1=v1, p2=3, p3=1970-01-01T00:01:00.123Z"},
{nil, msg, []any{}, "[cron] Test message"},
{nil, msg, []any{"p1", "v1", "p2", 3, "p3", time.Unix(60, 123456789).UTC()}, "[cron] Test message (p1=v1, p2=3, p3=1970-01-01T00:01:00.123Z)"},
{err, "", []any{}, "[cron] Something went wrong"},
{err, "", []any{"p1", "v1", "p2", 3, "p3", time.Unix(60, 123456789).UTC()}, "[cron] Something went wrong (p1=v1, p2=3, p3=1970-01-01T00:01:00.123Z)"},
{err, msg, []any{}, "[cron] Something went wrong: Test message"},
{err, msg, []any{"p1", "v1", "p2", 3, "p3", time.Unix(60, 123456789).UTC()}, "[cron] Something went wrong: Test message (p1=v1, p2=3, p3=1970-01-01T00:01:00.123Z)"},
}
cl := &CronLog{}
for i, p := range params {
i++
m := cl.makeMsg(p.err, p.msg, p.kv...)
if m != p.expect {
t.Errorf(`%d: message "%s", expected "%s"`, i, m, p.expect)
}
}
}
//----------------------------------------------------------------------------------------------------------------------------//