MCPcopy Create free account
hub / github.com/goadesign/goa / TestByLengthWithAliasType

Function TestByLengthWithAliasType

expr/example_test.go:93–116  ·  view source on GitHub ↗

TestByLengthWithAliasType tests that alias types with length validations can generate examples correctly. Previously, this would panic because the code checked a.Type.Kind() instead of the underlying type's kind.

(t *testing.T)

Source from the content-addressed store, hash-verified

91// can generate examples correctly. Previously, this would panic because the
92// code checked a.Type.Kind() instead of the underlying type's kind.
93func TestByLengthWithAliasType(t *testing.T) {
94 r := expr.NewRandom("test")
95
96 // Create an alias type based on String with length validation
97 // We need to use the DSL package properly
98 root := expr.RunDSL(t, testdata.AliasLengthValidationDSL)
99
100 aliasType := root.UserType("ValidatedString")
101 att := aliasType.Attribute()
102
103 // This should not panic and should generate a string example
104 // The key test is that byLength handles alias types correctly by unaliasing
105 // before checking the kind. Previously this would panic with:
106 // "invalid type for length validation: ValidatedString"
107 example := att.Example(r)
108 str, ok := example.(string)
109 if !ok {
110 t.Fatalf("Expected string example, got %T", example)
111 }
112 // Verify it's a valid non-empty string (exact length may vary due to randomness)
113 if len(str) == 0 {
114 t.Error("Expected non-empty string example")
115 }
116}
117
118// TestByLengthWithAliasArray tests that alias array types with length
119// validations generate examples correctly.

Callers

nothing calls this directly

Calls 6

NewRandomFunction · 0.92
RunDSLFunction · 0.92
UserTypeMethod · 0.80
AttributeMethod · 0.65
ExampleMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected