From ada5deb15150e7563566decfe6388602d12edff0 Mon Sep 17 00:00:00 2001 From: Neil Macneale IV Date: Thu, 12 Sep 2024 09:48:15 -0700 Subject: [PATCH] second pass on tests --- .../bats/add-patch-expect/no_then_a.expect | 25 +++++++ .../bats/add-patch-expect/yes_then_d.expect | 26 +++++++ integration-tests/bats/add-patch.bats | 75 ++++++++++++++++++- 3 files changed, 124 insertions(+), 2 deletions(-) create mode 100755 integration-tests/bats/add-patch-expect/no_then_a.expect create mode 100755 integration-tests/bats/add-patch-expect/yes_then_d.expect diff --git a/integration-tests/bats/add-patch-expect/no_then_a.expect b/integration-tests/bats/add-patch-expect/no_then_a.expect new file mode 100755 index 0000000000..329d57c5cc --- /dev/null +++ b/integration-tests/bats/add-patch-expect/no_then_a.expect @@ -0,0 +1,25 @@ +#!/usr/bin/expect + +set timeout 5 +set env(NO_COLOR) 1 + +source "$env(BATS_CWD)/helper/common_expect_functions.tcl" + +spawn dolt add -p + +# This test will reject the first change for each of the 3 tables, then accept the rest. + +expect_with_defaults_2 {| \+ | 0 | Yellow | 255 | 255 | 0 |} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "n\r"; } + +expect_with_defaults_2 {| - | 2 | Green | 0 | 255 | 0 |} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "ar"; } + +expect_with_defaults_2 {| - | 2 | 3.3 | 4.4 |} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "n\r"; } + +expect_with_defaults_2 {| < | 3 | 5.5 | 6.6 |} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "a\r"; } + +expect_with_defaults_2 {| < | 1 | neil |} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "n\r"; } + +expect_with_defaults_2 {| - | 2 | sami |} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "a\r"; } + +expect eof +exit diff --git a/integration-tests/bats/add-patch-expect/yes_then_d.expect b/integration-tests/bats/add-patch-expect/yes_then_d.expect new file mode 100755 index 0000000000..ad2662d7c9 --- /dev/null +++ b/integration-tests/bats/add-patch-expect/yes_then_d.expect @@ -0,0 +1,26 @@ +#!/usr/bin/expect + +set timeout 5 +set env(NO_COLOR) 1 + +source "$env(BATS_CWD)/helper/common_expect_functions.tcl" + +# Verify add -p . gets all the tables. +spawn dolt add -p . + +# This test will accept the first change for each of the 3 tables, then skip the rest. + +expect_with_defaults_2 {| \+ | 0 | Yellow | 255 | 255 | 0 |} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "y\r"; } + +expect_with_defaults_2 {| - | 2 | Green | 0 | 255 | 0 |} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "d\r"; } + +expect_with_defaults_2 {| - | 2 | 3.3 | 4.4 |} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "y\r"; } + +expect_with_defaults_2 {| < | 3 | 5.5 | 6.6 |} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "d\r"; } + +expect_with_defaults_2 {| < | 1 | neil |} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "y\r"; } + +expect_with_defaults_2 {| - | 2 | sami |} {Stage this row \[y,n,q,a,d,s,\?\]\? } { send "d\r"; } + +expect eof +exit diff --git a/integration-tests/bats/add-patch.bats b/integration-tests/bats/add-patch.bats index 426f842946..a0d0eadf69 100644 --- a/integration-tests/bats/add-patch.bats +++ b/integration-tests/bats/add-patch.bats @@ -27,7 +27,7 @@ UPDATE colors SET name = 'SkyBlue', red = 0, green = 128, blue = 255 WHERE pk = UPDATE coordinates SET y = 100.001 WHERE pk = 3; INSERT INTO names VALUES (4,'john'); -INSERT INTO colors VALUES (0, 'Yellow', 255, 255, 0); +INSERT INTO colors VALUES (0, 'Yellow', 255, 255, 0); // use 0 pk to ensure ordering is different from other tables. INSERT INTO coordinates VALUES (4, 42.24, 23.32); DELETE FROM names WHERE pk = 2; @@ -148,6 +148,7 @@ teardown() { [[ ! "$output" =~ "john" ]] || false # Value for inserted row - should not be there. } +# bats test_tags=no_lambda @test "add-patch: y/n repeatedly with restarts" { # This test repeatedly does 'y/n/y/s' until the program exits. run $BATS_TEST_DIRNAME/add-patch-expect/restart_multiple_times.expect @@ -173,7 +174,77 @@ teardown() { [[ ! "$output" =~ "john" ]] || false # last promoted row - should not be staged. } +# bats test_tags=no_lambda +@test "add-patch: y then d" { + # Accept the first change for each table, then skip the rest. + run $BATS_TEST_DIRNAME/add-patch-expect/yes_then_d.expect + [ $status -eq 0 ] + + run dolt sql -q "select name from colors AS OF STAGED" + [ $status -eq 0 ] + [[ "$output" =~ "Yellow" ]] || false + [[ "$output" =~ "Red" ]] || false + [[ "$output" =~ "Green" ]] || false + [[ "$output" =~ "Blue" ]] || false + # verify no extra rows in table we didn't look for. + run dolt sql -q "select sum(pk) as s from colors AS OF STAGED" + [ $status -eq 0 ] + [[ "$output" =~ "| 6 |" ]] || false # Yellow added as pk=0, so 0+1+2+3 + + run dolt sql -q "select pk, y from coordinates AS OF STAGED" + [ $status -eq 0 ] + [[ "$output" =~ "| 1 | 2.2 |" ]] || false + [[ "$output" =~ "| 3 | 6.6 |" ]] || false + # verify no extra rows in table we didn't look for. + run dolt sql -q "select sum(pk) as s from coordinates AS OF STAGED" + [ $status -eq 0 ] + [[ "$output" =~ "| 4 |" ]] || false + + run dolt sql -q "select pk, name from names AS OF STAGED" + [ $status -eq 0 ] + [[ "$output" =~ "| 1 | joey |" ]] || false + [[ "$output" =~ "| 2 | sami |" ]] || false + [[ "$output" =~ "| 3 | jane |" ]] || false + run dolt sql -q "select sum(pk) as s from names AS OF STAGED" + [ $status -eq 0 ] + [[ "$output" =~ "| 6 |" ]] || false +} + +# bats test_tags=no_lambda +@test "add-patch: n then a" { + # Accept the reject fir change, then accept the rest. + run $BATS_TEST_DIRNAME/add-patch-expect/no_then_a.expect + [ $status -eq 0 ] + + run dolt sql -q "select pk,name from colors AS OF STAGED" + [ $status -eq 0 ] + [[ "$output" =~ "| 1 | Red |" ]] || false + [[ "$output" =~ "| 3 | SkyBlue |" ]] || false + # verify no extra rows in table we didn't look for. + run dolt sql -q "select sum(pk) as s from colors AS OF STAGED" + [ $status -eq 0 ] + [[ "$output" =~ "| 4 |" ]] || false + + run dolt sql -q "select pk, y from coordinates AS OF STAGED" + [ $status -eq 0 ] + [[ "$output" =~ "| 1 | 2.2 |" ]] || false + [[ "$output" =~ "| 2 | 4.4 |" ]] || false + [[ "$output" =~ "| 3 | 100.001 |" ]] || false + [[ "$output" =~ "| 4 | 23.32 |" ]] || false + # verify no extra rows in table we didn't look for. + run dolt sql -q "select sum(pk) as s from coordinates AS OF STAGED" + [ $status -eq 0 ] + [[ "$output" =~ "| 10 |" ]] || false + + run dolt sql -q "select pk, name from names AS OF STAGED" + [ $status -eq 0 ] + [[ "$output" =~ "| 1 | neil |" ]] || false + [[ "$output" =~ "| 2 | sami |" ]] || false + [[ "$output" =~ "| 3 | jane |" ]] || false + run dolt sql -q "select sum(pk) as s from names AS OF STAGED" + [ $status -eq 0 ] + [[ "$output" =~ "| 6 |" ]] || false +} # Test needed: -# restart workflow. # add keyless table tests.