forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql/types: types.EnumMetadata implements encoding.TextMarshaler inter…
…face Fixes cockroachdb#63379 `types.EnumMetadata` needs to implement `encoding.TextMarshaler` interface so that goto/protobuf won't panic when text marshaling protobuf struct has child field of type `types.EnumMetadata`. See the issue for more details why it would fail without this fix. Release note: None
- Loading branch information
1 parent
d7e3ceb
commit 309f765
Showing
4 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package types_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" | ||
"github.com/cockroachdb/cockroach/pkg/sql/catalog/typedesc" | ||
"github.com/cockroachdb/cockroach/pkg/sql/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestDescriptorProtoString is to make sure gogo/protobuf is able to text | ||
// marshal a protobuf struct has child field of type EnumMetadata | ||
func TestDescriptorProtoString(t *testing.T) { | ||
enumMembers := []string{"hi", "hello"} | ||
enumType := types.MakeEnum(typedesc.TypeIDToOID(500), typedesc.TypeIDToOID(100500)) | ||
enumType.TypeMeta = types.UserDefinedTypeMetadata{ | ||
Name: &types.UserDefinedTypeName{ | ||
Schema: "test", | ||
Name: "greeting", | ||
}, | ||
EnumData: &types.EnumMetadata{ | ||
LogicalRepresentations: enumMembers, | ||
PhysicalRepresentations: [][]byte{ | ||
{0x42, 0x1}, | ||
{0x42}, | ||
}, | ||
IsMemberReadOnly: make([]bool, len(enumMembers)), | ||
}, | ||
} | ||
desc := &descpb.ColumnDescriptor{ | ||
Name: "c", | ||
ID: 1, | ||
Type: enumType, | ||
} | ||
require.NotPanics(t, func() { _ = desc.String() }) | ||
} |