2022-08-30 02:30:36 +00:00
|
|
|
package base
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func GetTestHandler(t *testing.T) *BaseController {
|
2022-09-03 18:38:35 +00:00
|
|
|
return NewBaseController(nil)
|
2022-08-30 02:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestHandlersv1_HandleBase(t *testing.T) {
|
|
|
|
// Setup
|
|
|
|
hdlrFunc := GetTestHandler(t).HandleBase(func() bool { return true }, "v1")
|
|
|
|
|
|
|
|
// Call Handler Func
|
|
|
|
rr := httptest.NewRecorder()
|
|
|
|
hdlrFunc(rr, nil)
|
|
|
|
|
|
|
|
// Validate Status Code
|
|
|
|
if rr.Code != http.StatusOK {
|
|
|
|
t.Errorf("Expected status code to be %d, got %d", http.StatusOK, rr.Code)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate Json Payload
|
|
|
|
expected := `{"item":{"health":true,"versions":["v1"],"title":"Go API Template","message":"Welcome to the Go API Template Application!"}}`
|
|
|
|
|
|
|
|
if rr.Body.String() != expected {
|
|
|
|
t.Errorf("Expected json to be %s, got %s", expected, rr.Body.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|