-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers_test.go
More file actions
70 lines (51 loc) · 1.29 KB
/
Copy pathhelpers_test.go
File metadata and controls
70 lines (51 loc) · 1.29 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package cron
import (
"context"
"testing"
"time"
)
func testParserWithSeconds() SpecParser {
return NewSpecParser(Second | Minute | Hour | Dom | Month | DowOptional | Descriptor)
}
func mustAddFunc(t *testing.T, cron *Cron, spec string, cmd func(context.Context) error) EntryID {
t.Helper()
entryID, err := cron.AddFunc(spec, cmd)
if err != nil {
t.Fatalf("add func %q: %v", spec, err)
}
return entryID
}
func mustAddNamedFunc(t *testing.T, cron *Cron, name, spec string, cmd func(context.Context) error) EntryID {
t.Helper()
entryID, err := cron.AddNamedFunc(name, spec, cmd)
if err != nil {
t.Fatalf("add named func %q (%s): %v", name, spec, err)
}
return entryID
}
func mustAddJob(t *testing.T, cron *Cron, spec string, job Job) EntryID {
t.Helper()
entryID, err := cron.AddJob(spec, job)
if err != nil {
t.Fatalf("add job %q: %v", spec, err)
}
return entryID
}
func mustLoadLocation(t *testing.T, name string) *time.Location {
t.Helper()
location, err := time.LoadLocation(name)
if err != nil {
t.Fatalf("load location %q: %v", name, err)
}
return location
}
func requireType[T any](t *testing.T, value any) T {
t.Helper()
typedValue, ok := value.(T)
if !ok {
var zeroValue T
t.Fatalf("unexpected type %T", value)
return zeroValue
}
return typedValue
}