MCPcopy Create free account
hub / github.com/github/gh-aw / TestTranslateSchemaConstraintMessage

Function TestTranslateSchemaConstraintMessage

pkg/parser/schema_errors_test.go:335–385  ·  view source on GitHub ↗

TestTranslateSchemaConstraintMessage tests that minimum/maximum messages are translated to plain English

(t *testing.T)

Source from the content-addressed store, hash-verified

333
334// TestTranslateSchemaConstraintMessage tests that minimum/maximum messages are translated to plain English
335func TestTranslateSchemaConstraintMessage(t *testing.T) {
336 tests := []struct {
337 name string
338 input string
339 want string
340 }{
341 {
342 name: "minimum violation negative value",
343 input: "minimum: got -45, want 1",
344 want: "must be at least 1 (got -45)",
345 },
346 {
347 name: "minimum violation zero",
348 input: "minimum: got 0, want 1",
349 want: "must be at least 1 (got 0)",
350 },
351 {
352 name: "minimum violation decimal",
353 input: "minimum: got -1.5, want 0",
354 want: "must be at least 0 (got -1.5)",
355 },
356 {
357 name: "maximum violation",
358 input: "maximum: got 120, want 60",
359 want: "must be at most 60 (got 120)",
360 },
361 {
362 name: "maximum violation decimal",
363 input: "maximum: got 100.5, want 60",
364 want: "must be at most 60 (got 100.5)",
365 },
366 {
367 name: "unrelated message is unchanged",
368 input: "value must be one of 'a', 'b'",
369 want: "value must be one of 'a', 'b'",
370 },
371 {
372 name: "already plain English message is unchanged",
373 input: "must be at least 1",
374 want: "must be at least 1",
375 },
376 }
377
378 for _, tt := range tests {
379 t.Run(tt.name, func(t *testing.T) {
380 got := translateSchemaConstraintMessage(tt.input)
381 assert.Equal(t, tt.want, got,
382 "translateSchemaConstraintMessage(%q) = %q, want %q", tt.input, got, tt.want)
383 })
384 }
385}
386
387func TestRewriteAdditionalPropertiesErrorOrdering(t *testing.T) {
388 tests := []struct {

Callers

nothing calls this directly

Calls 2

RunMethod · 0.45

Tested by

no test coverage detected