Download internal/apierrors/errors_test.go from qwen2api/aurora: direct link, hf CLI and curl.
- Browser
- Download file 1.84 kB
-
https://huggingface.co/spaces/qwen2api/aurora/resolve/main/internal/apierrors/errors_test.go
- Command line
-
hf download hf://spaces/qwen2api/aurora/internal/apierrors/errors_test.go
-
curl -L -o errors_test.go https://huggingface.co/spaces/qwen2api/aurora/resolve/main/internal/apierrors/errors_test.go
1.84 kB
| package apierrors | |
| import ( | |
| "net/http" | |
| "net/http/httptest" | |
| "testing" | |
| "github.com/gin-gonic/gin" | |
| ) | |
| func setupTestContext() (*gin.Context, *httptest.ResponseRecorder) { | |
| gin.SetMode(gin.TestMode) | |
| w := httptest.NewRecorder() | |
| c, _ := gin.CreateTestContext(w) | |
| c.Request, _ = http.NewRequest("POST", "/test", nil) | |
| return c, w | |
| } | |
| func TestInvalidRequest(t *testing.T) { | |
| c, w := setupTestContext() | |
| InvalidRequest(c, "bad input", "test_error") | |
| if w.Code != http.StatusBadRequest { | |
| t.Errorf("expected status %d, got %d", http.StatusBadRequest, w.Code) | |
| } | |
| body := w.Body.String() | |
| if body == "" { | |
| t.Error("expected non-empty response body") | |
| } | |
| } | |
| func TestMissingParam(t *testing.T) { | |
| c, w := setupTestContext() | |
| MissingParam(c, "prompt", "missing_required_parameter") | |
| if w.Code != http.StatusBadRequest { | |
| t.Errorf("expected status %d, got %d", http.StatusBadRequest, w.Code) | |
| } | |
| } | |
| func TestAuthError(t *testing.T) { | |
| c, w := setupTestContext() | |
| AuthError(c, http.StatusUnauthorized, "invalid token") | |
| if w.Code != http.StatusUnauthorized { | |
| t.Errorf("expected status %d, got %d", http.StatusUnauthorized, w.Code) | |
| } | |
| } | |
| func TestInternalError(t *testing.T) { | |
| c, w := setupTestContext() | |
| InternalError(c, "server_error", "something broke", 500) | |
| if w.Code != http.StatusInternalServerError { | |
| t.Errorf("expected status %d, got %d", http.StatusInternalServerError, w.Code) | |
| } | |
| } | |
| func TestBadRequest(t *testing.T) { | |
| c, w := setupTestContext() | |
| BadRequest(c, "invalid_type", "bad request", "test_code") | |
| if w.Code != http.StatusBadRequest { | |
| t.Errorf("expected status %d, got %d", http.StatusBadRequest, w.Code) | |
| } | |
| } | |
| func TestNotFoundAccount(t *testing.T) { | |
| c, w := setupTestContext() | |
| NotFoundAccount(c) | |
| if w.Code != http.StatusBadRequest { | |
| t.Errorf("expected status %d, got %d", http.StatusBadRequest, w.Code) | |
| } | |
| } | |