This repository has been archived by the owner on Sep 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
/
job_status_test.go
95 lines (90 loc) · 2.57 KB
/
job_status_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
// Copyright 2015 Alex Browne. All rights reserved.
// Use of this source code is governed by the MIT
// license, which can be found in the LICENSE file.
package jobs
import (
"reflect"
"testing"
)
func TestStatusCount(t *testing.T) {
testingSetUp()
defer testingTeardown()
jobs, err := createAndSaveTestJobs(5)
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}
for _, status := range possibleStatuses {
if status == StatusDestroyed {
// Skip this one, since destroying a job means erasing all records from the database
continue
}
for _, job := range jobs {
job.setStatus(status)
}
count, err := status.Count()
if err != nil {
t.Errorf("Unexpected error in status.Count(): %s", err.Error())
}
if count != len(jobs) {
t.Errorf("Expected %s.Count() to return %d after setting job statuses to %s, but got %d", status, len(jobs), status, count)
}
}
}
func TestStatusJobIds(t *testing.T) {
testingSetUp()
defer testingTeardown()
jobs, err := createAndSaveTestJobs(5)
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}
jobIds := make([]string, len(jobs))
for i, job := range jobs {
jobIds[i] = job.id
}
for _, status := range possibleStatuses {
if status == StatusDestroyed {
// Skip this one, since destroying a job means erasing all records from the database
continue
}
for _, job := range jobs {
job.setStatus(status)
}
gotIds, err := status.JobIds()
if err != nil {
t.Errorf("Unexpected error in status.JobIds(): %s", err.Error())
}
if len(gotIds) != len(jobIds) {
t.Errorf("%s.JobIds() was incorrect. Expected slice of length %d but got %d", len(jobIds), len(gotIds))
}
if !reflect.DeepEqual(jobIds, gotIds) {
t.Errorf("%s.JobIds() was incorrect. Expected %v but got %v", status, jobIds, gotIds)
}
}
}
func TestStatusJobs(t *testing.T) {
testingSetUp()
defer testingTeardown()
jobs, err := createAndSaveTestJobs(5)
if err != nil {
t.Fatalf("Unexpected error: %s", err)
}
for _, status := range possibleStatuses {
if status == StatusDestroyed {
// Skip this one, since destroying a job means erasing all records from the database
continue
}
for _, job := range jobs {
job.setStatus(status)
}
gotJobs, err := status.Jobs()
if err != nil {
t.Errorf("Unexpected error in status.Jobs(): %s", err.Error())
}
if len(gotJobs) != len(jobs) {
t.Errorf("%s.Jobs() was incorrect. Expected slice of length %d but got %d", len(jobs), len(gotJobs))
}
if !reflect.DeepEqual(jobs, gotJobs) {
t.Errorf("%s.Jobs() was incorrect. Expected %v but got %v", status, jobs, gotJobs)
}
}
}