-
-
Notifications
You must be signed in to change notification settings - Fork 242
Expand file tree
/
Copy pathgin_test.go
More file actions
32 lines (28 loc) · 739 Bytes
/
Copy pathgin_test.go
File metadata and controls
32 lines (28 loc) · 739 Bytes
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
package examples
import (
"net/http"
"testing"
"github.com/gavv/httpexpect/v2"
"github.com/gin-gonic/gin"
)
func TestGinHandler(t *testing.T) {
// Create new gin instance
engine := gin.New()
// Add /example route via handler function to the gin instance
handler := GinHandler(engine)
// Create httpexpect instance
e := httpexpect.WithConfig(httpexpect.Config{
Client: &http.Client{
Transport: httpexpect.NewBinder(handler),
Jar: httpexpect.NewCookieJar(),
},
Reporter: httpexpect.NewAssertReporter(t),
Printers: []httpexpect.Printer{
httpexpect.NewDebugPrinter(t, true),
},
})
// Assert response
e.GET("/example").
Expect().
Status(http.StatusOK).JSON().Object().HasValue("message", "pong")
}