39 lines
977 B
Go
39 lines
977 B
Go
package httpapi
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/sundynix/pets-be/internal/config"
|
|
)
|
|
|
|
func TestLoginRoute(t *testing.T) {
|
|
gin.SetMode(gin.TestMode)
|
|
router := gin.New()
|
|
New(nil, nil, &config.Config{}).Register(router)
|
|
for _, route := range router.Routes() {
|
|
if !strings.HasPrefix(route.Path, "/api/") {
|
|
t.Errorf("API route %q does not have /api/ prefix", route.Path)
|
|
}
|
|
}
|
|
|
|
for _, test := range []struct {
|
|
path string
|
|
want int
|
|
}{
|
|
{path: "/api/auth/login", want: http.StatusBadRequest},
|
|
{path: "/api/auth/wechat", want: http.StatusNotFound},
|
|
} {
|
|
recorder := httptest.NewRecorder()
|
|
request := httptest.NewRequest(http.MethodPost, test.path, strings.NewReader(`{}`))
|
|
request.Header.Set("Content-Type", "application/json")
|
|
router.ServeHTTP(recorder, request)
|
|
if recorder.Code != test.want {
|
|
t.Errorf("POST %s: got %d, want %d", test.path, recorder.Code, test.want)
|
|
}
|
|
}
|
|
}
|