initial commit from IBM Cloud example
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
commit
4e76f510b3
32 changed files with 1925 additions and 0 deletions
11
routers/health.go
Normal file
11
routers/health.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
package routers
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func HealthGET(c *gin.Context) {
|
||||
c.JSON(200, gin.H{
|
||||
"status": "UP",
|
||||
})
|
||||
}
|
28
routers/health_test.go
Normal file
28
routers/health_test.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package routers
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"net/http/httptest"
|
||||
"net/http"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func TestHealth(t *testing.T) {
|
||||
router := gin.Default()
|
||||
router.GET("/health", HealthGET)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req := httptest.NewRequest("GET", "/health", nil)
|
||||
router.ServeHTTP(w, req)
|
||||
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("You received a %v error.", w.Code)
|
||||
}
|
||||
|
||||
expected := "{\"status\":\"UP\"}"
|
||||
actual := w.Body.String()
|
||||
|
||||
if actual != expected {
|
||||
t.Errorf("Response should be %v, was %v.", expected, actual)
|
||||
}
|
||||
}
|
Reference in a new issue