forked from benschw/go-todo
/
update_test.go
98 lines (74 loc) · 1.75 KB
/
update_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
package main
import (
"fmt"
"github.com/benschw/go-todo/api"
"github.com/benschw/go-todo/client"
"log"
"reflect"
"testing"
)
var _ = fmt.Print // For debugging; delete when done.
var _ = log.Print // For debugging; delete when done.
func TestUpdateTodo(t *testing.T) {
// given
client := client.TodoClient{Host: "http://localhost:8080"}
todo, _ := client.CreateTodo("foo", "bar")
// when
todo.Status = "doing"
todo.Title = "baz"
todo.Description = "bing"
_, err := client.UpdateTodo(todo)
// then
if err != nil {
t.Error(err)
}
todoResult, _ := client.GetTodo(todo.Id)
if !reflect.DeepEqual(todo, todoResult) {
t.Error("returned todo not updated")
}
// cleanup
_ = client.DeleteTodo(todo.Id)
}
func TestUpdateNonExistantTodo(t *testing.T) {
// given
client := client.TodoClient{Host: "http://localhost:8080"}
todo, _ := client.CreateTodo("foo", "bar")
_ = client.DeleteTodo(todo.Id)
// when
todo.Status = "doing"
todo.Title = "baz"
todo.Description = "bing"
_, err := client.UpdateTodo(todo)
// then
if err == nil {
t.Error(err)
}
}
func TestUpdateTodosStatus(t *testing.T) {
// given
client := client.TodoClient{Host: "http://localhost:8080"}
todo, _ := client.CreateTodo("foo", "bar")
// when
_, err := client.UpdateTodoStatus(todo.Id, api.DoingStatus)
// then
if err != nil {
t.Error(err)
}
todoResult, _ := client.GetTodo(todo.Id)
if todoResult.Status != "doing" {
t.Error("returned todo status not updated")
}
// cleanup
_ = client.DeleteTodo(todo.Id)
}
func TestUpdateNotFoundTodosStatus(t *testing.T) {
// given
client := client.TodoClient{Host: "http://localhost:8080"}
id := int32(3)
// when
_, err := client.UpdateTodoStatus(id, api.DoingStatus)
// then
if err == nil {
t.Error(err)
}
}