MCPcopy Create free account
hub / github.com/DoNewsCode/core / TestJobOption

Function TestJobOption

cron/options_test.go:31–241  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

29}
30
31func TestJobOption(t *testing.T) {
32 t.Parallel()
33 var buf bytes.Buffer
34 logger := log.NewSyncLogger(log.NewLogfmtLogger(&buf))
35 hist := stub.Histogram{}
36 count := stub.Counter{}
37 metric := NewCronJobMetrics(&hist, &count)
38 tracer := mocktracer.MockTracer{}
39 entryCount := 0
40 concurrentCount := 0
41 var concurrentAccess bool
42
43 for _, ca := range []struct {
44 name string
45 stacks []JobOption
46 job func(context.Context) error
47 asserts func(t *testing.T)
48 }{
49 {
50 "name and logging",
51 []JobOption{
52 WithName("test"),
53 WithLogging(logger),
54 },
55 func(ctx context.Context) error {
56 return nil
57 },
58 func(t *testing.T) {
59 t.Log(buf.String())
60 if buf.String() == "" {
61 t.Error("Expected logging output")
62 }
63 if strings.Contains(buf.String(), "test") == false {
64 t.Error("Expected test to be in the log output")
65 }
66 buf = bytes.Buffer{}
67 },
68 },
69 {
70 "error and logging",
71 []JobOption{
72 WithLogging(logger),
73 },
74 func(ctx context.Context) error {
75 return errors.New("test")
76 },
77 func(t *testing.T) {
78 t.Log(buf.String())
79 if buf.String() == "" {
80 t.Error("Expected logging output")
81 }
82 if strings.Contains(buf.String(), "error") == false {
83 t.Error("Expected error to be in the log output")
84 }
85 buf = bytes.Buffer{}
86 },
87 },
88 {

Callers

nothing calls this directly

Calls 15

NewCronJobMetricsFunction · 0.85
WithLoggingFunction · 0.85
WithMetricsFunction · 0.85
WithTracingFunction · 0.85
RecoverFunction · 0.85
SkipIfOverlapFunction · 0.85
DelayIfOverlapFunction · 0.85
TimeoutIfOverlapFunction · 0.85
LogMethod · 0.80
DoneMethod · 0.80
WithNameFunction · 0.70
NewFunction · 0.70

Tested by

no test coverage detected