(t *testing.T)
| 29 | } |
| 30 | |
| 31 | func 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 | { |
nothing calls this directly
no test coverage detected