mirror of
https://github.com/yanislav-igonin/micrach
synced 2026-07-27 05:14:17 +03:00
* chore: add agents md * docs: expand repository and setup guides * docs: plan project modernization * docs: add Wave 1 implementation plan * test: characterize legacy behavior * build: update Go and Fiber v2 * fix(gateway): preserve duplicate auth behavior * refactor(db): migrate to pgx v5 * refactor: replace deprecated I/O APIs * build: add local PostgreSQL compose * build: add multi-stage image * ci: replace legacy deployment workflow * fix(deps): update vulnerable Go modules * docs: document modern development workflow
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package controllers
|
|
|
|
import (
|
|
"io"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
type testViews struct{}
|
|
|
|
func (testViews) Load() error { return nil }
|
|
|
|
func (testViews) Render(out io.Writer, name string, _ interface{}, _ ...string) error {
|
|
_, err := io.WriteString(out, name)
|
|
return err
|
|
}
|
|
|
|
func TestGetThreadsRejectsInvalidPage(t *testing.T) {
|
|
app := fiber.New(fiber.Config{Views: testViews{}})
|
|
app.Get("/", GetThreads)
|
|
|
|
resp, err := app.Test(httptest.NewRequest("GET", "/?page=0", nil))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer resp.Body.Close()
|
|
if resp.StatusCode != fiber.StatusNotFound {
|
|
t.Fatalf("status = %d, want %d", resp.StatusCode, fiber.StatusNotFound)
|
|
}
|
|
}
|
|
|
|
func TestGetThreadRejectsInvalidID(t *testing.T) {
|
|
app := fiber.New(fiber.Config{Views: testViews{}})
|
|
app.Get("/:threadID", GetThread)
|
|
|
|
resp, err := app.Test(httptest.NewRequest("GET", "/invalid", nil))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer resp.Body.Close()
|
|
if resp.StatusCode != fiber.StatusNotFound {
|
|
t.Fatalf("status = %d, want %d", resp.StatusCode, fiber.StatusNotFound)
|
|
}
|
|
}
|