Files
mesh-sdk/go/seatdef/refs_test.go
T
jschoubben bc6c7a7710 sdk-callers-refused: seatdef refuses callers and drops the checker's copies
A definition naming callers is refused (a field the format does not know); Callers, DefaultCallers, EffectiveCallers, CallerEntryProblem and the Caller constants go. The test seat list's seats lose their callers. The seat mesh-delivery-checker's bootstrap, test and captured copies go.

The copies of git, mesh-delivery and mesh-catalog (bootstrap, test, captured) have only their callers lines taken out by hand so this commit's tests are green: they are replaced by mesh-delivery's contracts files in sdk-seat-copies-h1's remainder.

Builds: design 47 H §752, §764 (The checker, Every seat contract), H-A-41, H-A-42, H-A-57
2026-11-20 02:34:34 +01:00

43 lines
2.1 KiB
Go

package seatdef
import (
"reflect"
"testing"
)
// A verb's schema has its named types in place (the seat list's readers take one schema, not a schema and its types).
func subResolveRefsPutsNamedTypesInPlace(t *testing.T) {
defs := map[string]map[string]any{
"id": {"type": "string"},
"row": {"type": "object", "properties": map[string]any{"id": map[string]any{"$ref": "#/defs/id"}}},
}
bodies := map[string]map[string]any{"Finding": {"type": "object", "properties": map[string]any{"id": map[string]any{"$ref": "#/defs/id"}}}}
cases := []struct {
name string
schema, want map[string]any
}{
{"nothing", nil, nil},
{"a type nested in a type", map[string]any{"type": "array", "items": map[string]any{"$ref": "#/defs/row"}},
map[string]any{"type": "array", "items": map[string]any{"type": "object",
"properties": map[string]any{"id": map[string]any{"type": "string"}}}}},
{"a name it does not define stays", map[string]any{"$ref": "#/defs/gone"}, map[string]any{"$ref": "#/defs/gone"}},
{"a body", map[string]any{"type": "array", "items": map[string]any{"$ref": "#/bodies/Finding"}},
map[string]any{"type": "array", "items": map[string]any{"type": "object",
"properties": map[string]any{"id": map[string]any{"type": "string"}}}}},
{"a body it does not define stays", map[string]any{"$ref": "#/bodies/Gone"}, map[string]any{"$ref": "#/bodies/Gone"}},
{"a list of schemas", map[string]any{"oneOf": []any{map[string]any{"$ref": "#/defs/id"}}},
map[string]any{"oneOf": []any{map[string]any{"type": "string"}}}},
}
for _, c := range cases {
if got := ResolveRefs(c.schema, defs, bodies); !reflect.DeepEqual(got, c.want) {
t.Errorf("%s: %v, want %v", c.name, got, c.want)
}
}
}
// TestResolveRefsPutsNamedTypesInPlace runs the tests of this package that were merged to keep the module within its test budget (design 47 G §419), each as a subtest.
func TestResolveRefsPutsNamedTypesInPlace(t *testing.T) {
t.Run("ResolveRefsPutsNamedTypesInPlace", subResolveRefsPutsNamedTypesInPlace)
t.Run("AKeptEventsStreamIsNamedAndBoundedByItsKeep", subAKeptEventsStreamIsNamedAndBoundedByItsKeep)
}