-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathget_test.go
79 lines (61 loc) · 1.41 KB
/
get_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
package main
import (
"fmt"
"github.com/benschw/go-todo/client"
"log"
"testing"
)
var _ = fmt.Print // For debugging; delete when done.
var _ = log.Print // For debugging; delete when done.
func TestGetTodo(t *testing.T) {
// given
client := client.TodoClient{Host: "http://localhost:8080"}
todo, _ := client.CreateTodo("foo", "bar")
id := todo.Id
// when
todo, err := client.GetTodo(id)
// then
if err != nil {
t.Error(err)
}
if todo.Title != "foo" && todo.Description != "bar" {
t.Error("returned todo not right")
}
// cleanup
_ = client.DeleteTodo(todo.Id)
}
func TestGetNotFoundTodo(t *testing.T) {
// given
client := client.TodoClient{Host: "http://localhost:8080"}
id := int32(3)
// when
_, err := client.GetTodo(id)
// then
if err == nil {
t.Error(err)
}
}
func TestGetAllTodos(t *testing.T) {
// given
client := client.TodoClient{Host: "http://localhost:8080"}
client.CreateTodo("foo", "bar")
client.CreateTodo("baz", "bing")
// when
todos, err := client.GetAllTodos()
// then
if err != nil {
t.Error(err)
}
if len(todos) != 2 {
t.Errorf("wrong number of todos: %d", len(todos))
}
if todos[0].Title != "foo" && todos[0].Description != "bar" {
t.Error("returned todo not right")
}
if todos[1].Title != "baz" && todos[1].Description != "bing" {
t.Error("returned todo not right")
}
// cleanup
_ = client.DeleteTodo(todos[0].Id)
_ = client.DeleteTodo(todos[1].Id)
}