diff --git a/sdk/framework/backend.go b/sdk/framework/backend.go index 3a6b0d80428b..d06e8a489d5b 100644 --- a/sdk/framework/backend.go +++ b/sdk/framework/backend.go @@ -753,7 +753,7 @@ func (t FieldType) Zero() interface{} { case TypeInt: return 0 case TypeInt64: - return int64(0) + return int64(0) case TypeBool: return false case TypeMap: diff --git a/sdk/framework/backend_test.go b/sdk/framework/backend_test.go index 9a2b5941457a..fd3d44e94c71 100644 --- a/sdk/framework/backend_test.go +++ b/sdk/framework/backend_test.go @@ -2,6 +2,7 @@ package framework import ( "context" + "fmt" "net/http" "reflect" "strings" @@ -811,3 +812,23 @@ func TestInitializeBackend(t *testing.T) { t.Fatal("backend should be open") } } + +// TestFieldTypeMethods tries to ensure our switch-case statements for the +// FieldType "enum" are complete. +func TestFieldTypeMethods(t *testing.T) { + unknownFormat := convertType(TypeInvalid).format + + for i := TypeInvalid + 1; i < typeInvalidMax; i++ { + t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { + if i.String() == TypeInvalid.String() { + t.Errorf("unknown type string for %d", i) + } + + if convertType(i).format == unknownFormat { + t.Errorf("unknown schema for %d", i) + } + + _ = i.Zero() + }) + } +} diff --git a/sdk/framework/field_type.go b/sdk/framework/field_type.go index ef7f08191e1a..fa67f454af2f 100644 --- a/sdk/framework/field_type.go +++ b/sdk/framework/field_type.go @@ -63,6 +63,10 @@ const ( // formatted as a string or a number. The resulting time.Time // is converted to UTC. TypeTime + + // DO NOT USE. Any new values must be inserted before this value. + // Used to write tests that ensure type methods handle all possible values. + typeInvalidMax ) func (t FieldType) String() string { @@ -75,6 +79,8 @@ func (t FieldType) String() string { return "name string" case TypeInt: return "int" + case TypeInt64: + return "int64" case TypeBool: return "bool" case TypeMap: