-
Notifications
You must be signed in to change notification settings - Fork 1
/
report_test.go
68 lines (53 loc) · 1.67 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
package spectest
import (
"net/http"
"testing"
)
func TestRecorderResponseStatusRecordsFinalResponseStatus(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.Equal(t, true, err == nil)
assert.Equal(t, http.StatusBadRequest, status)
}
func TestRecorderResponseStatusErrorsIfNoEventsDefined(t *testing.T) {
_, err := NewTestRecorder().
ResponseStatus()
assert.Equal(t, "no events are defined", err.Error())
}
func TestRecorderResponseStatusErrorsIfFinalEventNotAResponse(t *testing.T) {
_, err := NewTestRecorder().
AddHTTPRequest(HTTPRequest{}).
ResponseStatus()
assert.Equal(t, "final event should be a response type", err.Error())
}
func TestRecorderResponseStatusHandlesEventTypes(t *testing.T) {
rec := NewTestRecorder().
AddMessageRequest(MessageRequest{}).
AddMessageResponse(MessageResponse{})
status, _ := rec.ResponseStatus()
assert.Equal(t, -1, status)
assert.Equal(t, 2, len(rec.Events))
}
func TestRecorderAddsTitle(t *testing.T) {
rec := NewTestRecorder().
AddTitle("title")
assert.Equal(t, rec.Title, "title")
}
func TestRecorderAddsSubTitle(t *testing.T) {
rec := NewTestRecorder().
AddSubTitle("subTitle")
assert.Equal(t, rec.SubTitle, "subTitle")
}
func TestRecorderReset(t *testing.T) {
rec := NewTestRecorder().
AddTitle("title").
AddSubTitle("subTitle").
AddMeta(newMeta()).
AddMessageRequest(MessageRequest{})
rec.Reset()
assert.Equal(t, &Recorder{}, rec)
}