internal/server/api/spec/direction_internal_test.go
Ref: Size: 856 B History
package spec
import (
"reflect"
"testing"
"github.com/a73x/eitri/internal/server/api/types"
)
// TestSharedTypeAcrossDirectionsPanics bite-proves the direction guard: a
// contract struct memoized response-side must refuse to also serve
// request-side (the two sides get different schemas — required vs not — and
// silent first-wins would ship whichever the route order happened to pick).
func TestSharedTypeAcrossDirectionsPanics(t *testing.T) {
g := &generator{schemas: map[string]any{}, direction: map[string]bool{}}
g.schemaFor(reflect.TypeFor[types.Capacity](), false) // response side first
defer func() {
if recover() == nil {
t.Fatal("reusing a response-side schema request-side did not panic; the sides get different required treatment and must stay disjoint")
}
}()
g.schemaFor(reflect.TypeFor[types.Capacity](), true)
}