micrach/gateway/controllers_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

34 lines
748 B
Go

package gateway
import (
"net/http/httptest"
"testing"
"github.com/gofiber/fiber/v2"
"micrach/config"
)
func TestPingUsesLastAuthorizationHeader(t *testing.T) {
previousConfig := config.App
t.Cleanup(func() {
config.App = previousConfig
})
config.App.Gateway.ApiKey = "configured-key"
app := fiber.New()
app.Get("/api/ping", Ping)
req := httptest.NewRequest("GET", "/api/ping", nil)
req.Header.Add("Authorization", "wrong-key")
req.Header.Add("Authorization", "configured-key")
resp, err := app.Test(req)
if err != nil {
t.Fatalf("test ping request: %v", err)
}
if resp.StatusCode != fiber.StatusOK {
t.Fatalf("expected status %d when final Authorization header matches, got %d", fiber.StatusOK, resp.StatusCode)
}
}