-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjobscheduler_test.go
76 lines (61 loc) · 1.59 KB
/
jobscheduler_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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"path/filepath"
"testing"
)
func TestNewJobScheduler(t *testing.T) {
jsc := newJobScheduler()
if jsc.byName == nil {
t.Error(`"byName" map should be initialized`)
}
if jsc.mu == nil {
t.Error("mutex should be initialized")
}
}
func TestJobSchedulerUpdate(t *testing.T) {
jsc := newJobScheduler()
configRoot := t.TempDir()
jobDir := filepath.Join(configRoot, "test-job")
jobPath := filepath.Join(jobDir, jobConfigFileName)
// Test updating a job with no job file.
result, _, err := jsc.update(configRoot, jobPath)
if err == nil {
t.Error("expected error when updating non-existent job")
}
if result != jobsNoChanges {
t.Errorf(`expected "jobsNoChanges", got %v`, result)
}
}
func TestJobSchedulerRemove(t *testing.T) {
jsc := newJobScheduler()
// Test removing a non-existent job.
err := jsc.remove("nonexistent")
if err == nil {
t.Error("expected error when removing non-existent job")
}
// Add a mock job and test removal.
jsc.byName["test-job"] = JobConfig{}
err = jsc.remove("test-job")
if err != nil {
t.Errorf("unexpected error removing existing job: %v", err)
}
if _, exists := jsc.byName["test-job"]; exists {
t.Error("job should have been removed")
}
}
func TestJobNameFromPath(t *testing.T) {
tests := []struct {
path string
expected string
}{
{"/path/to/jobdir/config.star", "jobdir"},
{"jobdir/config.star", "jobdir"},
{"config.star", "."},
}
for _, tt := range tests {
result := jobNameFromPath(tt.path)
if result != tt.expected {
t.Errorf("jobNameFromPath(%q) = %q, want %q", tt.path, result, tt.expected)
}
}
}