-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.go
More file actions
98 lines (95 loc) · 3.1 KB
/
test.go
File metadata and controls
98 lines (95 loc) · 3.1 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
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
package coco
import "fmt"
// ShouldEqualJob checks that given two jobs (got, want) are equal.
// It returns an error which tell which member is different, when find a difference.
// It doesn't compare pointer addresses, but their values if possible.
// It doesn't compare it's subtasks except the root task.
func ShouldEqualJob(got, want *Job) error {
if got == nil && want == nil {
return nil
}
if got == nil {
return fmt.Errorf("only got is nil")
}
if want == nil {
return fmt.Errorf("only want is nil")
}
if got.ID != want.ID {
return fmt.Errorf("ID: got %v, want %v", got.ID, want.ID)
}
if got.Target != want.Target {
return fmt.Errorf("Target: got %v, want %v", got.Target, want.Target)
}
if got.AutoRetry != want.AutoRetry {
return fmt.Errorf("AutoRetry: got %v, want %v", got.AutoRetry, want.AutoRetry)
}
if len(got.tasks) != len(want.tasks) {
return fmt.Errorf("len(tasks): got %v, want %v", len(got.tasks), len(want.tasks))
}
if got.CurrentPriority != want.CurrentPriority {
return fmt.Errorf("CurrentPriority: got %v, want %v", got.CurrentPriority, want.CurrentPriority)
}
for i := range got.tasks {
g := got.tasks[i]
w := want.tasks[i]
err := ShouldEqualTask(g, w)
if err != nil {
return fmt.Errorf("task[%v]: %v", i, err)
}
}
return nil
}
// ShouldEqualTask checks that given two tasks are equal and raises an error
// about which parts are different between two.
// It considers the first is 'got' and the second is 'want'.
// It's doesn't compare pointer to pointer directly, but their values.
func ShouldEqualTask(got, want *Task) error {
if got == nil && want == nil {
return nil
}
if got == nil {
return fmt.Errorf("only got is nil")
}
if want == nil {
return fmt.Errorf("only want is nil")
}
if got.ID != want.ID {
return fmt.Errorf("ID: got %v, want %v", got.ID, want.ID)
}
if !(got.parent == nil && want.parent == nil) {
if got.parent != nil && want.parent != nil {
if got.parent.ID != want.parent.ID {
return fmt.Errorf("parent: got %v, want %v", got.parent.ID, want.parent.ID)
}
} else if got.parent == nil {
return fmt.Errorf("only got.parent is nil")
} else {
return fmt.Errorf("only want.parent is nil")
}
}
if got.Title != want.Title {
return fmt.Errorf("Title: got %v, want %v", got.Title, want.Title)
}
if got.Priority != want.Priority {
return fmt.Errorf("Priority: got %v, want %v", got.Priority, want.Priority)
}
if got.nthChild != want.nthChild {
return fmt.Errorf("nthChild: got %v, want %v", got.nthChild, want.nthChild)
}
if got.popIdx != want.popIdx {
return fmt.Errorf("popIdx: got %v, want %v", got.popIdx, want.popIdx)
}
if got.isLeaf != want.isLeaf {
return fmt.Errorf("isLeaf: got %v, want %v", got.isLeaf, want.isLeaf)
}
if got.retry != want.retry {
return fmt.Errorf("retry: got %v, want %v", got.retry, want.retry)
}
if len(got.Subtasks) != len(want.Subtasks) {
return fmt.Errorf("len(Subtasks): got %v, want %v", len(got.Subtasks), len(want.Subtasks))
}
if len(got.Commands) != len(want.Commands) {
return fmt.Errorf("len(Commands): got %v, want %v", len(got.Commands), len(want.Commands))
}
return nil
}