-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsafe_test.go
49 lines (44 loc) · 898 Bytes
/
safe_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
package work
import (
"context"
"testing"
"github.com/matryer/is"
"github.com/sirupsen/logrus"
)
func Test_RunE(t *testing.T) {
logger := logrus.WithFields(logrus.Fields{
"method": "Test_WithGinLogrus",
})
is := is.New(t)
ctx := NewContext(context.Background())
ctx.Set("test-key", []string{"hi", "mom"})
job := &Job{
Handler: "test-handler",
Args: Args{
"foo": "bar",
},
Ctx: &ctx,
}
logger.Info("testing WithJob and expect panic")
err := RunE(func() error {
panic("test panic")
},
WithJob(job),
)
t.Log(job.Ctx.Status())
is.True(job.Ctx.Status() == StatusInternalError)
is.True(err != nil)
t.Log(err)
logger.Info("testing with NO job and expect panic")
err = RunE(func() error {
panic("test panic")
})
is.True(err != nil)
t.Log(err)
logger.Info("expecting no panic")
err = RunE(func() error {
t.Log("success")
return nil
})
is.NoErr(err)
}