From 76770e8a52db80228b9da057a7bea8d98d3fe60c Mon Sep 17 00:00:00 2001 From: MasseElch <12862103+masseelch@users.noreply.github.com> Date: Sat, 11 Dec 2021 13:25:02 +0100 Subject: [PATCH] entc/gen: don't rely on descriptor when retrieving enum values or names to ease extension testibility (#2211) Trying to add tests to some extensions and this is complicating things a lot because `Field.def` is unexported. Not taking the length of `def.Enums` but `Enums` directly fixes this. It technically is also more correct, because `f.Enums` could be greater than `f.def.Enums`. --- entc/gen/type.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/entc/gen/type.go b/entc/gen/type.go index 67bbda0fa..f5cf05582 100644 --- a/entc/gen/type.go +++ b/entc/gen/type.go @@ -896,7 +896,7 @@ func (f Field) StructField() string { // EnumNames returns the enum values of a field. func (f Field) EnumNames() []string { - names := make([]string, 0, len(f.def.Enums)) + names := make([]string, 0, len(f.Enums)) for _, e := range f.Enums { names = append(names, e.Name) } @@ -905,7 +905,7 @@ func (f Field) EnumNames() []string { // EnumValues returns the values of the enum field. func (f Field) EnumValues() []string { - values := make([]string, 0, len(f.def.Enums)) + values := make([]string, 0, len(f.Enums)) for _, e := range f.Enums { values = append(values, e.Value) }