diff --git a/encoding/protobq/integration_test.go b/encoding/protobq/integration_test.go index 11c5291..b48d23d 100644 --- a/encoding/protobq/integration_test.go +++ b/encoding/protobq/integration_test.go @@ -41,21 +41,23 @@ func Test_Integration_PublicDataSets(t *testing.T) { Message: &publicv1.FilmLocation{}, }, - { - ProjectID: "bigquery-public-data", - DatasetID: "hacker_news", - TableID: "stories", - Limit: 10, - Message: &publicv1.HackerNewsStory{}, - }, + // no longer accessible + // { + // ProjectID: "bigquery-public-data", + // DatasetID: "hacker_news", + // TableID: "stories", + // Limit: 10, + // Message: &publicv1.HackerNewsStory{}, + // }, - { - ProjectID: "bigquery-public-data", - DatasetID: "london_bicycles", - TableID: "cycle_hire", - Limit: 10, - Message: &publicv1.LondonBicycleRental{}, - }, + // no longer accessible + // { + // ProjectID: "bigquery-public-data", + // DatasetID: "london_bicycles", + // TableID: "cycle_hire", + // Limit: 10, + // Message: &publicv1.LondonBicycleRental{}, + // }, { ProjectID: "bigquery-public-data", @@ -65,16 +67,17 @@ func Test_Integration_PublicDataSets(t *testing.T) { Message: &publicv1.SanFransiscoTransitStopTime{}, }, - { - ProjectID: "bigquery-public-data", - DatasetID: "london_bicycles", - TableID: "cycle_stations", - Limit: 10, - Message: &publicv1.LondonBicycleStation{}, - UnmarshalOptions: protobq.UnmarshalOptions{ - DiscardUnknown: true, // Ignore non-snake case field "nbEmptyDocks". - }, - }, + // no longer accessible + // { + // ProjectID: "bigquery-public-data", + // DatasetID: "london_bicycles", + // TableID: "cycle_stations", + // Limit: 10, + // Message: &publicv1.LondonBicycleStation{}, + // UnmarshalOptions: protobq.UnmarshalOptions{ + // DiscardUnknown: true, // Ignore non-snake case field "nbEmptyDocks". + // }, + // }, { ProjectID: "bigquery-public-data", diff --git a/encoding/protobq/marshal.go b/encoding/protobq/marshal.go index 194e46d..d8ec633 100644 --- a/encoding/protobq/marshal.go +++ b/encoding/protobq/marshal.go @@ -272,7 +272,8 @@ func (o MarshalOptions) marshalEnumValue( // Use 'null' for BQ rows to indicate that no value could be determined. return nil, nil } - return nil, fmt.Errorf("unknown enum number: %v", value.Enum()) + path := fmt.Sprintf("%s.%s", field.Parent().FullName(), field.Name()) + return nil, fmt.Errorf("unknown enum number: %v, fieldname: %v", value.Enum(), path) } func (o MarshalOptions) marshalWellKnownTypeValue( diff --git a/encoding/protobq/marshal_test.go b/encoding/protobq/marshal_test.go index 4451ad2..f901f3b 100644 --- a/encoding/protobq/marshal_test.go +++ b/encoding/protobq/marshal_test.go @@ -1,6 +1,7 @@ package protobq import ( + "fmt" "testing" "time" @@ -380,12 +381,25 @@ func TestMarshalOptions_Marshal(t *testing.T) { "enum_value": nil, }, }, + { + name: "disallow unknown enum values", + msg: &examplev1.ExampleEnum{ + EnumValue: examplev1.ExampleEnum_Enum(100), + }, + opt: MarshalOptions{Schema: SchemaOptions{UseOneofFields: true}, DiscardUnknownEnumValues: false}, + expected: nil, + }, } { tt := tt t.Run(tt.name, func(t *testing.T) { actual, err := tt.opt.Marshal(tt.msg) - assert.NilError(t, err) - assert.DeepEqual(t, tt.expected, actual) + if tt.expected == nil { + fmt.Println(err) + assert.Error(t, err, "unknown enum number: 100, fieldname: einride.bigquery.example.v1.ExampleEnum.enum_value") + } else { + assert.NilError(t, err) + assert.DeepEqual(t, tt.expected, actual) + } }) } }