micrach/controllers/threads_controller_test.go
Yanislav Igonin db8a46cdf1
build: modernize Wave 1 baseline (#16)
* 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
2026-07-16 16:08:54 +09:00

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)
}
}