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

Function TestByLengthWithAliasArray

expr/example_test.go:120–139  ·  view source on GitHub ↗

TestByLengthWithAliasArray tests that alias array types with length validations generate examples correctly.

(t *testing.T)

Source from the content-addressed store, hash-verified

118// TestByLengthWithAliasArray tests that alias array types with length
119// validations generate examples correctly.
120func TestByLengthWithAliasArray(t *testing.T) {
121 r := expr.NewRandom("test")
122
123 root := expr.RunDSL(t, testdata.AliasArrayLengthValidationDSL)
124
125 aliasType := root.UserType("StringArray")
126 att := aliasType.Attribute()
127
128 // This should not panic and should generate an array example
129 example := att.Example(r)
130 arr, ok := example.([]string)
131 if !ok {
132 t.Fatalf("Expected []string example, got %T", example)
133 }
134
135 // Verify the length is within the validation constraints
136 if len(arr) < 2 || len(arr) > 5 {
137 t.Errorf("Generated example has length %d, expected between 2 and 5", len(arr))
138 }
139}

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected