go fmt
This commit is contained in:
parent
b433e690b6
commit
8c7c5c4287
4
main.go
4
main.go
@ -39,7 +39,7 @@ func main() {
|
||||
|
||||
// 获取端口
|
||||
port := getEnv("PORT", "8080")
|
||||
|
||||
|
||||
// 创建HTTP服务器
|
||||
srv := &http.Server{
|
||||
Addr: ":" + port,
|
||||
@ -192,4 +192,4 @@ func ginZapLogger(logger *zap.Logger) gin.HandlerFunc {
|
||||
|
||||
func ginZapRecovery(logger *zap.Logger, stack bool) gin.HandlerFunc {
|
||||
return gin.Recovery()
|
||||
}
|
||||
}
|
||||
|
26
main_test.go
26
main_test.go
@ -17,68 +17,68 @@ func TestMain(m *testing.M) {
|
||||
|
||||
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.Contains(t, w.Body.String(), "pong")
|
||||
}
|
||||
|
||||
func TestHealthRoute(t *testing.T) {
|
||||
router := setupRouter()
|
||||
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", "/health", nil)
|
||||
router.ServeHTTP(w, req)
|
||||
|
||||
|
||||
assert.Equal(t, 200, w.Code)
|
||||
assert.Contains(t, w.Body.String(), "healthy")
|
||||
}
|
||||
|
||||
func TestHomeRoute(t *testing.T) {
|
||||
router := setupRouter()
|
||||
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", "/", nil)
|
||||
router.ServeHTTP(w, req)
|
||||
|
||||
|
||||
assert.Equal(t, 200, w.Code)
|
||||
assert.Contains(t, w.Body.String(), "Welcome to Golang Demo API")
|
||||
}
|
||||
|
||||
func TestVersionRoute(t *testing.T) {
|
||||
router := setupRouter()
|
||||
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", "/version", nil)
|
||||
router.ServeHTTP(w, req)
|
||||
|
||||
|
||||
assert.Equal(t, 200, w.Code)
|
||||
assert.Contains(t, w.Body.String(), "version")
|
||||
}
|
||||
|
||||
func TestAPIStatusRoute(t *testing.T) {
|
||||
router := setupRouter()
|
||||
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", "/api/v1/status", nil)
|
||||
router.ServeHTTP(w, req)
|
||||
|
||||
|
||||
assert.Equal(t, 200, w.Code)
|
||||
assert.Contains(t, w.Body.String(), "v1")
|
||||
}
|
||||
|
||||
func TestEchoRoute(t *testing.T) {
|
||||
router := setupRouter()
|
||||
|
||||
|
||||
body := `{"message": "test message"}`
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("POST", "/api/v1/echo", strings.NewReader(body))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
router.ServeHTTP(w, req)
|
||||
|
||||
|
||||
assert.Equal(t, 200, w.Code)
|
||||
assert.Contains(t, w.Body.String(), "test message")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user