Skip to content

Commit c3f4cff

Browse files
committed
Add regression test for diffs that occur immediately at the start of chunks.
1 parent b3853f6 commit c3f4cff

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

go/store/prolly/tree/json_diff_test.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/dolthub/go-mysql-server/sql/expression/function/json"
2727

2828
"github.com/dolthub/go-mysql-server/sql/types"
29+
"github.com/stretchr/testify/assert"
2930
"github.com/stretchr/testify/require"
3031
)
3132

@@ -415,6 +416,34 @@ func largeJsonDiffTests(t *testing.T) []jsonDiffTest {
415416
from: largeObject,
416417
to: insert(emptyDocument, "$.level6", insert(emptyDocument, "$.level4", lookup(largeObject, "$.level6.level4"))),
417418
},
419+
{
420+
// This is a regression test.
421+
//
422+
// If:
423+
// - A chunk begins with an object "A"
424+
// - If a value "A.b" within this object was modified
425+
// - The previous chunk was also modified
426+
// Then the differ would incorrectly report that the entire "A" object had been modified, instead of the sub-value "A.b"
427+
// The values in this test case are specifically chosen to meet these conditions,
428+
// as there is a chunk boundary immediately before "$.level5.level3.level1"
429+
name: "correctly diff object that begins on chunk boundary",
430+
from: largeObject,
431+
to: set(set(largeObject, "$.level5.level2.number", 2), "$.level5.level3.level1.number", 2),
432+
expectedDiffs: []JsonDiff{
433+
{
434+
Key: makeJsonPathKey(`level5`, `level2`, `number`),
435+
From: types.JSONDocument{Val: 1},
436+
To: types.JSONDocument{Val: 2},
437+
Type: ModifiedDiff,
438+
},
439+
{
440+
Key: makeJsonPathKey(`level5`, `level3`, `level1`, `number`),
441+
From: types.JSONDocument{Val: 1},
442+
To: types.JSONDocument{Val: 2},
443+
Type: ModifiedDiff,
444+
},
445+
},
446+
},
418447
}
419448
}
420449

@@ -489,7 +518,10 @@ func runTest(t *testing.T, test jsonDiffTest) {
489518
return cmp == 0
490519
}
491520
if test.expectedDiffs != nil {
492-
require.Equal(t, len(test.expectedDiffs), len(actualDiffs))
521+
522+
if !assert.Equal(t, len(test.expectedDiffs), len(actualDiffs)) {
523+
require.Fail(t, "Diffs don't match", "Expected: %v\nActual: %v", test.expectedDiffs, actualDiffs)
524+
}
493525
for i, expected := range test.expectedDiffs {
494526
actual := actualDiffs[i]
495527
require.True(t, diffsEqual(expected, actual), fmt.Sprintf("Expected: %v\nActual: %v", expected, actual))

0 commit comments

Comments
 (0)