mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-08 00:39:48 -06:00
bats: Created bats tests for replace-table and updated update-table tests
This commit is contained in:
20
bats/helper/1pk5col-ints.json
Normal file
20
bats/helper/1pk5col-ints.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"rows": [
|
||||
{
|
||||
"pk": 0,
|
||||
"c1": 1,
|
||||
"c2": 2,
|
||||
"c3": 3,
|
||||
"c4": 4,
|
||||
"c5": 5
|
||||
},
|
||||
{
|
||||
"pk": 1,
|
||||
"c1": 1,
|
||||
"c2": 2,
|
||||
"c3": 3,
|
||||
"c4": 4,
|
||||
"c5": 5
|
||||
}
|
||||
]
|
||||
}
|
||||
36
bats/helper/employees-tbl-new.json
Normal file
36
bats/helper/employees-tbl-new.json
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"rows": [
|
||||
{
|
||||
"id": 0,
|
||||
"first name": "tim",
|
||||
"last name": "sehn",
|
||||
"title": "ceo",
|
||||
"start date": "",
|
||||
"end date": ""
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"first name": "aaron",
|
||||
"last name": "son",
|
||||
"title": "founder",
|
||||
"start date": "",
|
||||
"end date": ""
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"first name": "brian",
|
||||
"last name": "hendricks",
|
||||
"title": "founder",
|
||||
"start date": "",
|
||||
"end date": ""
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"first name": "matt",
|
||||
"last name": "jesuele",
|
||||
"title": "software engineer",
|
||||
"start date": "",
|
||||
"end date": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
3
bats/helper/employees-tbl-schema-wrong.csv
Normal file
3
bats/helper/employees-tbl-schema-wrong.csv
Normal file
@@ -0,0 +1,3 @@
|
||||
id, first name, last name, position
|
||||
0, "tim", "sehn", "ceo"
|
||||
1, "aaron", "son", "founder"
|
||||
|
32
bats/helper/employees-tbl-schema-wrong.json
Normal file
32
bats/helper/employees-tbl-schema-wrong.json
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"rows": [
|
||||
{
|
||||
"id": "0",
|
||||
"first name": "tim",
|
||||
"last name": "sehn",
|
||||
"position": "ceo",
|
||||
"children": true
|
||||
},
|
||||
{
|
||||
"id": "1",
|
||||
"first name": "aaron",
|
||||
"last name": "son",
|
||||
"position": "founder",
|
||||
"children": true
|
||||
},
|
||||
{
|
||||
"id": "2",
|
||||
"first name": "brian",
|
||||
"last name": "hendricks",
|
||||
"position": "founder",
|
||||
"children": true
|
||||
},
|
||||
{
|
||||
"id": "3",
|
||||
"first name": "matt",
|
||||
"last name": "jesuele",
|
||||
"position": "software engineer",
|
||||
"children": false
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -26,7 +26,59 @@ teardown() {
|
||||
@test "replace table using schema with csv" {
|
||||
run dolt table create -s `batshelper 1pk5col-ints.schema` test
|
||||
[ "$status" -eq 0 ]
|
||||
run dolt table import -u -s `batshelper 1pk5col-ints.schema` test `batshelper 1pk5col-ints.csv`
|
||||
run dolt table import -r -s `batshelper 1pk5col-ints.schema` test `batshelper 1pk5col-ints.csv`
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ "schema is not supported for update or replace operations" ]] || false
|
||||
}
|
||||
|
||||
@test "replace table using json" {
|
||||
run dolt table create -s `batshelper employees-sch.json` employees
|
||||
[ "$status" -eq 0 ]
|
||||
run dolt table import -r employees `batshelper employees-tbl.json`
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "Rows Processed: 3, Additions: 3, Modifications: 0, Had No Effect: 0" ]] || false
|
||||
[[ "$output" =~ "Import completed successfully." ]] || false
|
||||
}
|
||||
|
||||
@test "replace table using wrong json" {
|
||||
run dolt table create -s `batshelper employees-sch-wrong.json` employees
|
||||
[ "$status" -eq 0 ]
|
||||
run dolt table import -r employees `batshelper employees-tbl.json`
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ "Error replacing table" ]] || false
|
||||
[[ "$output" =~ "cause: Schema from file does not match existing table schema" ]] || false
|
||||
}
|
||||
|
||||
@test "replace table using schema with json" {
|
||||
run dolt table create -s `batshelper employees-sch-wrong.json` employees
|
||||
[ "$status" -eq 0 ]
|
||||
run dolt table import -r -s `batshelper employees-sch.json` employees `batshelper employees-tbl.json`
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ "fatal: schema is not supported for update or replace operations" ]] || false
|
||||
}
|
||||
|
||||
@test "replace table with json when table does not exist" {
|
||||
run dolt table import -r employees `batshelper employees-tbl.json`
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ "The following table could not be found:" ]] || false
|
||||
}
|
||||
|
||||
@test "replace table with existing imported data" {
|
||||
run dolt table import -c -s `batshelper employees-sch.json` employees `batshelper employees-tbl.json`
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "Import completed successfully." ]] || false
|
||||
run dolt table import -r employees `batshelper employees-tbl-new.json`
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "Rows Processed: 4, Additions: 4, Modifications: 0, Had No Effect: 0" ]] || false
|
||||
[[ "$output" =~ "Import completed successfully." ]] || false
|
||||
}
|
||||
|
||||
@test "replace table with existing imported data with different schema" {
|
||||
run dolt table import -c -s `batshelper employees-sch.json` employees `batshelper employees-tbl.json`
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "Import completed successfully." ]] || false
|
||||
run dolt table import -r employees `batshelper employees-tbl-schema-wrong.json`
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ "Error replacing table" ]] || false
|
||||
[[ "$output" =~ "cause: Schema from file does not match existing table schema" ]] || false
|
||||
}
|
||||
@@ -28,7 +28,7 @@ teardown() {
|
||||
[ "$status" -eq 0 ]
|
||||
run dolt table import -u -s `batshelper 1pk5col-ints.schema` test `batshelper 1pk5col-ints.csv`
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ "schema is not supported for update operations" ]] || false
|
||||
[[ "$output" =~ "fatal: schema is not supported for update or replace operations" ]] || false
|
||||
}
|
||||
|
||||
@test "update table using csv with newlines" {
|
||||
@@ -61,7 +61,16 @@ teardown() {
|
||||
[ "$status" -eq 0 ]
|
||||
run dolt table import -u -s `batshelper employees-sch.json` employees `batshelper employees-tbl.json`
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ "schema is not supported for update operations" ]] || false
|
||||
[[ "$output" =~ "fatal: schema is not supported for update or replace operations" ]] || false
|
||||
}
|
||||
|
||||
@test "update table with existing imported data with different schema" {
|
||||
run dolt table import -c -s `batshelper employees-sch.json` employees `batshelper employees-tbl.json`
|
||||
[ "$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
|
||||
}
|
||||
|
||||
@test "update table with json when table does not exist" {
|
||||
|
||||
Reference in New Issue
Block a user