-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_test.go
More file actions
142 lines (118 loc) · 2.96 KB
/
command_test.go
File metadata and controls
142 lines (118 loc) · 2.96 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package main
import (
"testing"
)
func TestAddTask(t *testing.T) {
fakeStorage := MockStorage{
FakeData: Tasks{
Tasks: []Task{},
NextAvailableID: 1,
},
}
err := AddTask("TEST1", "Watch test match often in Cinema", &fakeStorage)
if err != nil {
t.Error("AddTask should not return an error, but got:", err)
}
//verify whether it is added or not
tasks, err := fakeStorage.Load()
if err != nil {
t.Error("Could not load task from mock:", err)
return
}
if len(tasks.Tasks) != 1 {
t.Error("Expected 1 task but got:", len(tasks.Tasks))
return
}
task := tasks.Tasks[0]
if task.TaskName != "TEST1" {
t.Error("Expected Task Name: 'TEST1' but got:", task.TaskName)
return
}
if task.TaskID != 1 {
t.Error("Expected TaskID: 1 but got:", task.TaskID)
return
}
t.Log("AddTask test completed successfully - no real files touched!")
}
func TestListTasks(t *testing.T) {
fakeStorage := MockStorage{
FakeData: Tasks{
Tasks: []Task{},
NextAvailableID: 1,
},
}
tasks, err := ListTasks(&fakeStorage)
if err != nil {
t.Error("ListTasks should not return an error, but got:", err)
}
if len(tasks.Tasks) != 0 {
t.Error("Expected 0 task but got:", len(tasks.Tasks))
return
}
t.Log("ListTasks test completed successfully - no real files touched!")
}
func TestDeleteTask(t *testing.T) {
fakeStorage := MockStorage{
FakeData: Tasks{
Tasks: []Task{},
NextAvailableID: 1,
},
}
//lets add dummy test task
err := AddTask("TEST1", "Watch test match often in Cinema", &fakeStorage)
if err != nil {
t.Error("AddTask should not return an error, but got:", err)
}
err = DeleteTask(1, &fakeStorage)
if err != nil {
t.Error("DeleteTask should not return an error")
}
//now verify
tasks, err := fakeStorage.Load()
if err != nil {
t.Error("Could not load task from mock:", err)
return
}
if len(tasks.Tasks) != 0 {
t.Error("Expected 0 task but got:", len(tasks.Tasks))
return
}
t.Log("DeleteTask test completed successfully")
}
func TestMarkComplete(t *testing.T) {
fakeStorage := MockStorage{
FakeData: Tasks{
Tasks: []Task{},
NextAvailableID: 1,
},
}
//lets add dummy test task
err := AddTask("TEST1", "Watch test match often in Cinema", &fakeStorage)
if err != nil {
t.Error("AddTask should not return an error, but got:", err)
}
err = MarkComplete(1, &fakeStorage)
if err != nil {
t.Error("MarkComplete should not return an error")
}
//verfiy whether it is completed or not
tasks, err := fakeStorage.Load()
if err != nil {
t.Error("Could not load task from mock:", err)
return
}
if len(tasks.Tasks) != 1 {
t.Error("Expected 1 task but got:", len(tasks.Tasks))
return
}
task := tasks.Tasks[0]
if task.TaskID != 1 {
t.Error("Expected TaskID: 1 but got:", task.TaskID)
return
}
if !task.IsCompleted {
t.Error("Expected Task is completed but not completd at its status :", task.IsCompleted)
return
}
t.Log("MarkComplete test completed successfully")
}