Skip to content

Commit

Permalink
add basic test for statsd.go
Browse files Browse the repository at this point in the history
  • Loading branch information
amalfra committed Jun 8, 2022
1 parent 0ed6018 commit 65f4f64
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions middleware/statsd_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package middleware

import (
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"

"github.com/gin-gonic/gin"
)

func TestDefaultRecorded(t *testing.T) {
r := gin.New()
r.Use(New(Options{}))
r.GET("/ping", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "pong",
})
})
req, _ := http.NewRequest("GET", "/ping", nil)
w := httptest.NewRecorder()
r.ServeHTTP(w, req)

responseData, _ := ioutil.ReadAll(w.Body)
if w.Code != http.StatusOK {
t.Error("Incorrect HTTP status")
}
if string(responseData) != "{\"message\":\"pong\"}" {
t.Error("Incorrect HTTP body")
}
}

0 comments on commit 65f4f64

Please sign in to comment.