-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem_test.go
87 lines (72 loc) · 1.8 KB
/
problem_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
package problem
import (
"encoding/json"
"testing"
)
func TestAPIProblem(t *testing.T) {
t.Run("test API Problem Title", func(t *testing.T) {
problem := APIProblem{
Title: "Test Problem",
Detail: "This is a test problem",
Status: "123",
Code: "PRO-123",
Meta: &map[string]interface{}{"key": "val"},
}
want := "Test Problem"
if want != problem.Title {
t.Error("want does not equal problem.Title")
}
})
t.Run("test API Problem Detail", func(t *testing.T) {
problem := APIProblem{
Title: "Test Problem",
Detail: "This is a test problem",
Status: "123",
Code: "PRO-123",
Meta: &map[string]interface{}{"key": "val"},
}
want := "This is a test problem"
if want != problem.Detail {
t.Error("want does not equal problem.Title")
}
})
t.Run("test API Problem Status", func(t *testing.T) {
problem := APIProblem{
Title: "Test Problem",
Detail: "This is a test problem",
Status: "123",
Code: "PRO-123",
Meta: &map[string]interface{}{"key": "val"},
}
want := "123"
if want != problem.Status {
t.Error("want does not equal problem.Title")
}
})
t.Run("test API Problem Code", func(t *testing.T) {
problem := APIProblem{
Title: "Test Problem",
Detail: "This is a test problem",
Status: "123",
Code: "PRO-123",
Meta: &map[string]interface{}{"key": "val"},
}
want := "PRO-123"
if want != problem.Code {
t.Error("want does not equal problem.Title")
}
})
t.Run("test Marshal API Problem to JSON", func(t *testing.T) {
problem := APIProblem{
Title: "Test Problem",
Detail: "This is a test problem",
Status: "123",
Code: "PRO-123",
Meta: &map[string]interface{}{"key": "val"},
}
_, err := json.Marshal(&problem)
if err != nil {
t.Error("Failed to Marshal JSON")
}
})
}