Skip to content

Commit

Permalink
More test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-artie committed Jun 14, 2024
1 parent a2e1790 commit afa50e3
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions clients/bigquery/storagewrite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func TestRowToMessage(t *testing.T) {
columns.NewColumn("c_float64", typing.Float),
columns.NewColumn("c_numeric", typing.EDecimal),
columns.NewColumn("c_string", typing.String),
columns.NewColumn("c_string_decimal", typing.String),
columns.NewColumn("c_time", typing.NewKindDetailsFromTemplate(typing.ETime, ext.TimeKindType)),
columns.NewColumn("c_date", typing.NewKindDetailsFromTemplate(typing.ETime, ext.DateKindType)),
columns.NewColumn("c_datetime", typing.NewKindDetailsFromTemplate(typing.ETime, ext.DateTimeKindType)),
Expand All @@ -45,19 +46,20 @@ func TestRowToMessage(t *testing.T) {
}

row := map[string]any{
"c_bool": true,
"c_int": int(1234),
"c_int32": int32(1234),
"c_int64": int64(1234),
"c_float32": float32(1234.567),
"c_float64": float64(1234.567),
"c_numeric": decimal.NewDecimal(nil, 5, big.NewFloat(3.1415926)),
"c_string": "foo bar",
"c_time": ext.NewExtendedTime(time.Date(0, 0, 0, 4, 5, 6, 7, time.UTC), ext.TimeKindType, ""),
"c_date": ext.NewExtendedTime(time.Date(2001, 2, 3, 0, 0, 0, 0, time.UTC), ext.DateKindType, ""),
"c_datetime": ext.NewExtendedTime(time.Date(2001, 2, 3, 4, 5, 6, 7, time.UTC), ext.DateTimeKindType, ""),
"c_struct": map[string]any{"baz": []string{"foo", "bar"}},
"c_array": []string{"foo", "bar"},
"c_bool": true,
"c_int": int(1234),
"c_int32": int32(1234),
"c_int64": int64(1234),
"c_float32": float32(1234.567),
"c_float64": float64(1234.567),
"c_numeric": decimal.NewDecimal(nil, 5, big.NewFloat(3.1415926)),
"c_string": "foo bar",
"c_string_decimal": decimal.NewDecimal(nil, 5, big.NewFloat(1.618033)),
"c_time": ext.NewExtendedTime(time.Date(0, 0, 0, 4, 5, 6, 7, time.UTC), ext.TimeKindType, ""),
"c_date": ext.NewExtendedTime(time.Date(2001, 2, 3, 0, 0, 0, 0, time.UTC), ext.DateKindType, ""),
"c_datetime": ext.NewExtendedTime(time.Date(2001, 2, 3, 4, 5, 6, 7, time.UTC), ext.DateTimeKindType, ""),
"c_struct": map[string]any{"baz": []string{"foo", "bar"}},
"c_array": []string{"foo", "bar"},
}

desc, err := columnsToMessageDescriptor(columns)
Expand All @@ -73,18 +75,19 @@ func TestRowToMessage(t *testing.T) {
assert.NoError(t, json.Unmarshal(bytes, &result))

assert.Equal(t, map[string]any{
"cBool": true,
"cFloat32": 1234.5670166015625,
"cFloat64": 1234.567,
"cInt": "1234",
"cInt32": "1234",
"cInt64": "1234",
"cNumeric": "3.14159",
"cString": "foo bar",
"cTime": "17521704960",
"cDate": float64(11356),
"cDatetime": "981173106000000",
"cStruct": `{"baz":["foo","bar"]}`,
"cArray": []any{"foo", "bar"},
"cBool": true,
"cFloat32": 1234.5670166015625,
"cFloat64": 1234.567,
"cInt": "1234",
"cInt32": "1234",
"cInt64": "1234",
"cNumeric": "3.14159",
"cString": "foo bar",
"cStringDecimal": "1.61803",
"cTime": "17521704960",
"cDate": float64(11356),
"cDatetime": "981173106000000",
"cStruct": `{"baz":["foo","bar"]}`,
"cArray": []any{"foo", "bar"},
}, result)
}

0 comments on commit afa50e3

Please sign in to comment.