forked from gavv/httpexpect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe2e_report_test.go
77 lines (56 loc) · 1.46 KB
/
e2e_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
75
76
77
package httpexpect
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
type recordingReporter struct {
reported string
}
func (r *recordingReporter) Errorf(msg string, args ...interface{}) {
r.reported += fmt.Sprintf(msg, args...)
}
func TestE2EReport_Names(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("/test", func(w http.ResponseWriter, r *http.Request) {
})
server := httptest.NewServer(mux)
defer server.Close()
rep := &recordingReporter{}
e := WithConfig(Config{
TestName: "TestExample",
BaseURL: server.URL,
Reporter: rep,
})
e.GET("/test").
WithName("RequestExample").
Expect().
JSON() // will fail
t.Logf("%s", rep.reported)
assert.Contains(t, rep.reported, "TestExample")
assert.Contains(t, rep.reported, "RequestExample")
}
func TestE2EReport_Aliases(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("/test", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"foo":123}`))
})
server := httptest.NewServer(mux)
defer server.Close()
rep := &recordingReporter{}
e := WithConfig(Config{
TestName: "TestExample",
BaseURL: server.URL,
Reporter: rep,
})
foo := e.GET("/test").
WithName("RequestExample").
Expect().
JSON().Alias("foo")
foo.Object().ContainsKey("bar") // will fail
t.Logf("%s", rep.reported)
assert.Contains(t, rep.reported, "foo.Object().ContainsKey()")
}