forked from steinfletcher/apitest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
report_test.go
74 lines (57 loc) · 1.73 KB
/
report_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
package apitest
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRecorder_ResponseStatus_RecordsFinalResponseStatus(t *testing.T) {
status, err := NewTestRecorder().
AddHttpRequest(HttpRequest{}).
AddHttpResponse(HttpResponse{Value: &http.Response{StatusCode: http.StatusAccepted}}).
AddHttpRequest(HttpRequest{}).
AddHttpResponse(HttpResponse{Value: &http.Response{StatusCode: http.StatusBadRequest}}).
ResponseStatus()
assert.Nil(t, err)
assert.Equal(t, http.StatusBadRequest, status)
}
func TestRecorder_ResponseStatus_ErrorsIfNoEventsDefined(t *testing.T) {
_, err := NewTestRecorder().
ResponseStatus()
assert.Error(t, err, "no events are defined")
}
func TestRecorder_ResponseStatus_ErrorsIfFinalEventNotAResponse(t *testing.T) {
_, err := NewTestRecorder().
AddHttpRequest(HttpRequest{}).
ResponseStatus()
assert.Error(t, err, "final event should be a response type")
}
func TestRecorder_ResponseStatus_HandlesEventTypes(t *testing.T) {
rec := NewTestRecorder().
AddMessageRequest(MessageRequest{}).
AddMessageResponse(MessageResponse{})
status, _ := rec.ResponseStatus()
assert.Equal(t, -1, status)
assert.Len(t, rec.Events, 2)
}
func TestRecorder_AddsTitle(t *testing.T) {
rec := NewTestRecorder().
AddTitle("title")
assert.Equal(t, rec.Title, "title")
}
func TestRecorder_AddsSubTitle(t *testing.T) {
rec := NewTestRecorder().
AddSubTitle("subTitle")
assert.Equal(t, rec.SubTitle, "subTitle")
}
func TestRecorder_Reset(t *testing.T) {
meta := map[string]interface{}{
"test": "meta",
}
rec := NewTestRecorder().
AddTitle("title").
AddSubTitle("subTitle").
AddMeta(meta).
AddMessageRequest(MessageRequest{})
rec.Reset()
assert.Equal(t, &Recorder{}, rec)
}