test(diff): add tests for renamed filter and removed alias

Add tests for the --filter=renamed option and the --filter=removed alias
that maps to dropped.

Go tests:
- Tests for filter=renamed checking all diff types
- Tests for "removed" alias mapping to dropped internally
- Verify renamed filter only includes renamed tables

BATS tests:
- Test --filter=renamed with table rename scenario
- Test --filter=dropped with table drop scenario
- Verify --filter=removed alias works same as dropped
- Verify other filters correctly exclude renamed/dropped tables

Refs: #1430
This commit is contained in:
David Dansby
2025-11-28 19:47:31 -08:00
parent 3c9fb41e10
commit b89f07b82c
2 changed files with 82 additions and 1 deletions

View File

@@ -78,7 +78,19 @@ func TestDiffTypeFilter_ShouldInclude(t *testing.T) {
// Testing with filter=dropped
{"filter=dropped, check added", diff.DiffTypeDropped, diff.DiffTypeAdded, false},
{"filter=dropped, check modified", diff.DiffTypeDropped, diff.DiffTypeModified, false},
{"filter=dropped, check removed", diff.DiffTypeDropped, diff.DiffTypeDropped, true},
{"filter=dropped, check dropped", diff.DiffTypeDropped, diff.DiffTypeDropped, true},
{"filter=dropped, check renamed", diff.DiffTypeDropped, diff.DiffTypeRenamed, false},
// Testing with filter=renamed
{"filter=renamed, check added", diff.DiffTypeRenamed, diff.DiffTypeAdded, false},
{"filter=renamed, check modified", diff.DiffTypeRenamed, diff.DiffTypeModified, false},
{"filter=renamed, check dropped", diff.DiffTypeRenamed, diff.DiffTypeDropped, false},
{"filter=renamed, check renamed", diff.DiffTypeRenamed, diff.DiffTypeRenamed, true},
// Testing with "removed" alias (should map to dropped)
{"filter=removed (alias), check dropped", "removed", diff.DiffTypeDropped, true},
{"filter=removed (alias), check added", "removed", diff.DiffTypeAdded, false},
{"filter=removed (alias), check renamed", "removed", diff.DiffTypeRenamed, false},
// Testing with filter=all
{"filter=all, check added", diff.DiffTypeAll, diff.DiffTypeAdded, true},

View File

@@ -2396,3 +2396,72 @@ EOF
[ $status -eq 1 ]
[[ $output =~ "invalid filter" ]] || false
}
@test "diff: --filter=renamed filters to only renamed tables" {
dolt sql -q "create table t(pk int primary key, val int)"
dolt sql -q "INSERT INTO t VALUES (1, 10)"
dolt add . && dolt commit -m "create table with data"
# Rename the table
dolt sql -q "RENAME TABLE t TO t_renamed"
dolt add . && dolt commit -m "rename table"
# filter=renamed should show the renamed table (shows different from/to names)
run dolt diff HEAD~1 --filter=renamed
[ $status -eq 0 ]
[[ $output =~ 'diff --dolt a/t b/t_renamed' ]] || false
[[ $output =~ '--- a/t' ]] || false
[[ $output =~ '+++ b/t_renamed' ]] || false
# filter=added should not show the renamed table
run dolt diff HEAD~1 --filter=added
[ $status -eq 0 ]
[[ $output = '' ]] || false
# filter=modified should not show the renamed table
run dolt diff HEAD~1 --filter=modified
[ $status -eq 0 ]
[[ $output = '' ]] || false
# filter=dropped should not show the renamed table
run dolt diff HEAD~1 --filter=dropped
[ $status -eq 0 ]
[[ $output = '' ]] || false
}
@test "diff: --filter=dropped filters to only dropped tables" {
dolt sql -q "create table t(pk int primary key, val int)"
dolt sql -q "INSERT INTO t VALUES (1, 10)"
dolt add . && dolt commit -m "create table with data"
# Drop the table
dolt sql -q "DROP TABLE t"
dolt add . && dolt commit -m "drop table"
# filter=dropped should show the dropped table
run dolt diff HEAD~1 --filter=dropped
[ $status -eq 0 ]
[[ $output =~ 'diff --dolt a/t b/t' ]] || false
[[ $output =~ 'deleted table' ]] || false
# filter=removed (alias for dropped) should also show the dropped table
run dolt diff HEAD~1 --filter=removed
[ $status -eq 0 ]
[[ $output =~ 'diff --dolt a/t b/t' ]] || false
[[ $output =~ 'deleted table' ]] || false
# filter=added should not show the dropped table
run dolt diff HEAD~1 --filter=added
[ $status -eq 0 ]
[[ $output = '' ]] || false
# filter=modified should not show the dropped table
run dolt diff HEAD~1 --filter=modified
[ $status -eq 0 ]
[[ $output = '' ]] || false
# filter=renamed should not show the dropped table
run dolt diff HEAD~1 --filter=renamed
[ $status -eq 0 ]
[[ $output = '' ]] || false
}