Added simple testing documentation and examples (#1156)
This commit is contained in:
@ -6,7 +6,7 @@ import (
|
||||
|
||||
var DB = make(map[string]string)
|
||||
|
||||
func main() {
|
||||
func setupRouter() *gin.Engine {
|
||||
// Disable Console Color
|
||||
// gin.DisableConsoleColor()
|
||||
r := gin.Default()
|
||||
@ -53,6 +53,11 @@ func main() {
|
||||
}
|
||||
})
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func main() {
|
||||
r := setupRouter()
|
||||
// Listen and Server in 0.0.0.0:8080
|
||||
r.Run(":8080")
|
||||
}
|
||||
|
20
examples/basic/main_test.go
Normal file
20
examples/basic/main_test.go
Normal file
@ -0,0 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestPingRoute(t *testing.T) {
|
||||
router := setupRouter()
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", "/ping", nil)
|
||||
router.ServeHTTP(w, req)
|
||||
|
||||
assert.Equal(t, 200, w.Code)
|
||||
assert.Equal(t, "pong", w.Body.String())
|
||||
}
|
Reference in New Issue
Block a user