leanovate / gopter

GOlang Property TestER
MIT License
599 stars 40 forks source link

Check paniced when using OneGenOf #83

Open vedujoshi opened 3 years ago

vedujoshi commented 3 years ago

Sometimes we get a failure with the below code

Error on property evaluation after 1 passed
   tests: Check paniced: reflect: Call using *schema.PathMatcherType_Prefix
   as type *schema.PathMatcherType_Path

Could you please suggest if you see any issue ?

Code:

func genPathMatcherType() gopter.Gen {
    return gen.StructPtr(reflect.TypeOf(&pb_schema.PathMatcherType{}), map[string]gopter.Gen{
        "PathMatch": gen.OneGenOf(genPathMatcherType_Prefix(), genPathMatcherType_Path(), genPathMatcherType_Regex()),
    })
}
func genPathMatcherType_Prefix() gopter.Gen {
    return gen.StructPtr(reflect.TypeOf(&pb_schema.PathMatcherType_Prefix{}), map[string]gopter.Gen{
        "Prefix": gen.AlphaString(),
    })
}
func genPathMatcherType_Path() gopter.Gen {
    return gen.StructPtr(reflect.TypeOf(&pb_schema.PathMatcherType_Path{}), map[string]gopter.Gen{
        "Path": gen.AlphaString(),
    })
}
func genPathMatcherType_Regex() gopter.Gen {
    return gen.StructPtr(reflect.TypeOf(&pb_schema.PathMatcherType_Regex{}), map[string]gopter.Gen{
        "Regex": gen.AlphaString(),
    })
}
untoldwind commented 3 years ago

It looks right to me (provided the structs have these string fields). Do you have more information where the panic occurs?