-
Notifications
You must be signed in to change notification settings - Fork 0
/
project_test.go
110 lines (86 loc) · 2.38 KB
/
project_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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package main
import (
"os"
"path/filepath"
"testing"
)
func TestProject(t *testing.T) {
tmpdir, err := os.MkdirTemp(os.TempDir(), "lurch-test-workdir")
if err != nil {
panic(err)
}
defer os.RemoveAll(tmpdir)
projectPath := filepath.Join(tmpdir, "test-project")
if err := os.Mkdir(projectPath, 0755); err != nil {
panic(err)
}
p := &Project{name: "test-project", dir: projectPath}
if p.LastCount() != 0 {
t.Fatalf("TestProject: unexpected last count %d", p.LastCount())
}
i, err := p.RotateCount()
if err != nil || i != 1 {
t.Fatal("TestProject: rotate count failed")
}
if p.LastCount() != 1 {
t.Fatalf("TestProject: unexpected last count %d", p.LastCount())
}
_, err = p.NewJob()
if err != nil {
panic(err)
}
if p.LastCount() != 2 {
t.Fatalf("TestProject: unexpected last count %d", p.LastCount())
}
}
func TestSetParamsOnProject(t *testing.T) {
tmpdir, err := os.MkdirTemp(os.TempDir(), "lurch-test-workdir")
if err != nil {
panic(err)
}
defer os.RemoveAll(tmpdir)
projectPath := filepath.Join(tmpdir, "test-project")
if err := os.Mkdir(projectPath, 0755); err != nil {
panic(err)
}
p := &Project{name: "test-project", dir: projectPath}
p.SetParams(map[string]string{
"1": "value1",
"k2": "value2",
"k-3": "value3",
"k_4": "value4",
})
if v := p.params["1"]; v != "" {
t.Fatalf("TestSetParamsOnProject: unexpected value for key 1: '%s'", v)
}
if v := p.params["K2"]; v != "value2" {
t.Fatalf("TestSetParamsOnProject: unexpected value for key k2: '%s'", v)
}
if v := p.params["K-3"]; v != "" {
t.Fatalf("TestSetParamsOnProject: unexpected value for key k-3: '%s'", v)
}
if v := p.params["K_4"]; v != "value4" {
t.Fatalf("TestSetParamsOnProject: unexpected value for key k_4: '%s'", v)
}
}
func TestSaveLoadParamsOnProject(t *testing.T) {
tmpdir, err := os.MkdirTemp(os.TempDir(), "lurch-test-workdir")
if err != nil {
panic(err)
}
defer os.RemoveAll(tmpdir)
projectPath := filepath.Join(tmpdir, "test-project")
if err := os.Mkdir(projectPath, 0755); err != nil {
panic(err)
}
p := &Project{name: "test-project", dir: projectPath}
p.SetParams(map[string]string{"k1": "v1", "k2": "v2"})
if err := p.SaveParams(); err != nil {
t.Fatal("TestSaveParams: unexpected error", err)
}
p2 := &Project{dir: projectPath}
p2.LoadParams()
if len(p2.params) != 2 {
t.Fatal("TestSaveParams: unexpected length of loaded params")
}
}