mirror of
https://github.com/dolthub/dolt.git
synced 2026-02-10 18:49:02 -06:00
Fixed bats tests with new error messages / behavior, fixed bug for faulty json and added test of same
Signed-off-by: Zach Musgrave <zach@liquidata.co>
This commit is contained in:
@@ -110,8 +110,7 @@ teardown() {
|
||||
[ "$status" -eq 0 ]
|
||||
run dolt table import -r employees `batshelper employees-tbl-bad.json`
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ "Error creating reader" ]] || false
|
||||
[[ "$output" =~ "employees-tbl-bad.json to" ]] || false
|
||||
[[ "$output" =~ "An error occurred moving data" ]] || false
|
||||
}
|
||||
|
||||
@test "replace table using xlsx file" {
|
||||
|
||||
@@ -47,8 +47,8 @@ teardown() {
|
||||
run dolt table create -s `batshelper employees-sch-wrong.json` employees
|
||||
[ "$status" -eq 0 ]
|
||||
run dolt table import -u employees `batshelper employees-tbl.json`
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "Rows Processed: 0, Additions: 0, Modifications: 0, Had No Effect: 0" ]] || false
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ "not found in schema" ]] || false
|
||||
}
|
||||
|
||||
@test "update table using schema with json" {
|
||||
@@ -64,8 +64,8 @@ teardown() {
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "Import completed successfully." ]] || false
|
||||
run dolt table import -u employees `batshelper employees-tbl-schema-wrong.json`
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "Rows Processed: 0, Additions: 0, Modifications: 0, Had No Effect: 0" ]] || false
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ "not found in schema" ]] || false
|
||||
}
|
||||
|
||||
@test "update table with json when table does not exist" {
|
||||
|
||||
@@ -100,12 +100,16 @@ func (r *JSONReader) VerifySchema(sch schema.Schema) (bool, error) {
|
||||
if r.sampleRow == nil {
|
||||
var err error
|
||||
r.sampleRow, err = r.ReadRow(context.Background())
|
||||
return err == nil, err
|
||||
return err == nil, nil
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (r *JSONReader) ReadRow(ctx context.Context) (row.Row, error) {
|
||||
if r.jsonStream.Err() != nil {
|
||||
return nil, r.jsonStream.Err()
|
||||
}
|
||||
|
||||
if r.sampleRow != nil {
|
||||
ret := r.sampleRow
|
||||
r.sampleRow = nil
|
||||
@@ -118,8 +122,12 @@ func (r *JSONReader) ReadRow(ctx context.Context) (row.Row, error) {
|
||||
|
||||
row, ok := <-r.rowChan
|
||||
if !ok {
|
||||
if r.jsonStream.Err() != nil {
|
||||
return nil, r.jsonStream.Err()
|
||||
}
|
||||
return nil, io.EOF
|
||||
}
|
||||
|
||||
m, ok := row.Value.(map[string]interface{})
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("Unexpected json value: %v", row.Value)
|
||||
|
||||
@@ -95,6 +95,71 @@ func TestReader(t *testing.T) {
|
||||
assert.Equal(t, expectedRows, rows)
|
||||
}
|
||||
|
||||
func TestReaderBadJson(t *testing.T) {
|
||||
testJSON := ` {
|
||||
"rows": [
|
||||
{
|
||||
"id": 0,
|
||||
"first name": "tim",
|
||||
"last name": "sehn"
|
||||
bad
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"first name": "aaron",
|
||||
"last name": "son",
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"first name": "brian",
|
||||
"last name": "hendricks",
|
||||
}
|
||||
}
|
||||
]
|
||||
}`
|
||||
|
||||
fs := filesys.EmptyInMemFS(".")
|
||||
require.NoError(t, fs.WriteFile("file.json", []byte(testJSON)))
|
||||
|
||||
colColl, err := schema.NewColCollection(
|
||||
schema.Column{
|
||||
Name: "id",
|
||||
Tag: 0,
|
||||
Kind: types.IntKind,
|
||||
IsPartOfPK: true,
|
||||
},
|
||||
schema.Column{
|
||||
Name: "first name",
|
||||
Tag: 1,
|
||||
Kind: types.StringKind,
|
||||
IsPartOfPK: false,
|
||||
},
|
||||
schema.Column{
|
||||
Name: "last name",
|
||||
Tag: 2,
|
||||
Kind: types.StringKind,
|
||||
IsPartOfPK: false,
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
sch := schema.SchemaFromCols(colColl)
|
||||
|
||||
reader, err := OpenJSONReader(types.Format_LD_1, "file.json", fs, sch, "")
|
||||
require.NoError(t, err)
|
||||
|
||||
err = nil
|
||||
for {
|
||||
_, err = reader.ReadRow(context.Background())
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
assert.NotEqual(t, io.EOF, err)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
|
||||
func newRow(sch schema.Schema, id int, first, last string) row.Row {
|
||||
vals := row.TaggedValues{
|
||||
0: types.Int(id),
|
||||
|
||||
Reference in New Issue
Block a user