MCPcopy
hub / github.com/usememos/memos / TestJobValidation

Function TestJobValidation

internal/scheduler/job_test.go:32–90  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

30}
31
32func TestJobValidation(t *testing.T) {
33 tests := []struct {
34 name string
35 job *Job
36 wantErr bool
37 }{
38 {
39 name: "valid job",
40 job: &Job{
41 Name: "valid",
42 Schedule: "0 * * * *",
43 Handler: func(_ context.Context) error { return nil },
44 },
45 wantErr: false,
46 },
47 {
48 name: "missing name",
49 job: &Job{
50 Schedule: "0 * * * *",
51 Handler: func(_ context.Context) error { return nil },
52 },
53 wantErr: true,
54 },
55 {
56 name: "missing schedule",
57 job: &Job{
58 Name: "test",
59 Handler: func(_ context.Context) error { return nil },
60 },
61 wantErr: true,
62 },
63 {
64 name: "invalid cron expression",
65 job: &Job{
66 Name: "test",
67 Schedule: "invalid cron",
68 Handler: func(_ context.Context) error { return nil },
69 },
70 wantErr: true,
71 },
72 {
73 name: "missing handler",
74 job: &Job{
75 Name: "test",
76 Schedule: "0 * * * *",
77 },
78 wantErr: true,
79 },
80 }
81
82 for _, tt := range tests {
83 t.Run(tt.name, func(t *testing.T) {
84 err := tt.job.Validate()
85 if (err != nil) != tt.wantErr {
86 t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr)
87 }
88 })
89 }

Callers

nothing calls this directly

Calls 2

RunMethod · 0.65
ValidateMethod · 0.45

Tested by

no test coverage detected