-
Notifications
You must be signed in to change notification settings - Fork 11
/
task_test.go
49 lines (45 loc) · 1.07 KB
/
task_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
package harvest
import "testing"
func testTask(t *testing.T) *Task {
a := testAPI()
taskResponse := mockResponse("tasks", "task-example.json")
a.BaseURL = taskResponse.URL
task, err := a.GetTask(2086199, Defaults())
if err != nil {
t.Fatal(err)
}
if task.Name != "Admin" {
t.Errorf("Incorrect Task Name '%s'", task.Name)
}
if task.ID != 2086199 {
t.Errorf("Incorrect Task ID '%v'", task.ID)
}
return task
}
func TestGetTask(t *testing.T) {
task := testTask(t)
if task == nil {
t.Fatal("testTask() returned nil instead of task")
}
if task.ID != 2086199 {
t.Errorf("Incorrect task ID '%v'", task.ID)
}
}
func TestGetTasks(t *testing.T) {
a := testAPI()
taskResponse := mockResponse("tasks", "tasks-example.json")
a.BaseURL = taskResponse.URL
tasks, err := a.GetTasks(Defaults())
if err != nil {
t.Fatal(err)
}
if len(tasks) != 2 {
t.Errorf("Incorrect number of tasks '%v'", len(tasks))
}
if tasks[0].Name != "Admin" {
t.Errorf("Incorrect Task Name '%s'", tasks[0].Name)
}
if tasks[1].ID != 2086200 {
t.Errorf("Incorrect Task ID '%v'", tasks[1].ID)
}
}