TestByLengthWithAliasArray tests that alias array types with length validations generate examples correctly.
(t *testing.T)
| 118 | // TestByLengthWithAliasArray tests that alias array types with length |
| 119 | // validations generate examples correctly. |
| 120 | func 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 | } |