Skip to content

Commit

Permalink
yaml: add a test case for all data types
Browse files Browse the repository at this point in the history
  • Loading branch information
apstndb committed Jul 26, 2022
1 parent 225da12 commit 6252bb8
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
14 changes: 14 additions & 0 deletions internal/spanner/testdata/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,17 @@ CREATE TABLE Boo (
Name STRING(MAX),
CONSTRAINT FK_BooBaz FOREIGN KEY (BazID) REFERENCES Baz (BazID)
) PRIMARY KEY(BooID);

CREATE TABLE AllTypes (
ID STRING(MAX) NOT NULL,
BoolValue BOOL,
Int64Value INT64,
Float64Value FLOAT64,
TimestampValue TIMESTAMP,
DateValue DATE,
StringValue STRING(MAX),
BytesValue BYTES(MAX),
NumericValue NUMERIC,
JSONValue JSON,
StringArray ARRAY<STRING(MAX)>,
) PRIMARY KEY(ID);
16 changes: 16 additions & 0 deletions internal/yaml/testdata/seeds/AllTypes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
# Values are need to be encoded as documented.
# https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.TypeCode
- ID: "All_Type_Values"
BoolValue: true
BytesValue: "aG9nZQ==" # base64("hoge")
DateValue: "2022-04-01"
Float64Value: 3.14159
Int64Value: 42
JSONValue: '{"test": 1}'
NumericValue: "-12345678901234567890123456789.123456789"
StringValue: "FooBar"
TimestampValue: "2022-04-01T00:00:00Z"
# StringArray:
# - "Foo"
# - "Bar"
20 changes: 20 additions & 0 deletions internal/yaml/yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@ func TestLoad(t *testing.T) {
}

expected := []*model.Table{
{
Name: "AllTypes",
Records: []*model.Record{
{
Values: map[string]interface{}{
"DateValue": "2022-04-01",
"Float64Value": float64(3.14159),
"ID": "All_Type_Values",
"Int64Value": int64(42),
"JSONValue": `{"test": 1}`,
"NumericValue": string("-12345678901234567890123456789.123456789"),
"StringValue": "FooBar",
"TimestampValue": "2022-04-01T00:00:00Z",
// "StringArray": []interface{}{"Foo", "Bar"},
"BoolValue": true,
"BytesValue": "aG9nZQ==",
},
},
},
},
{
Name: "Bar",
Records: []*model.Record{
Expand Down

0 comments on commit 6252bb8

Please sign in to comment.