Skip to content

Commit 9290e96

Browse files
committed
add ValidateMappings to tests
1 parent 5a240fc commit 9290e96

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

packages/shared/pkg/storage/header/mapping_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ func TestNormalizeMappingsSingleMapping(t *testing.T) {
309309
assert.Equal(t, uint64(0), m[0].Offset)
310310
assert.Equal(t, 2*blockSize, m[0].Length)
311311
assert.Equal(t, baseID, m[0].BuildId)
312+
313+
err := ValidateMappings(m, 2*blockSize, blockSize)
314+
require.NoError(t, err)
312315
}
313316

314317
func TestNormalizeMappingsNoAdjacentSameBuildId(t *testing.T) {
@@ -343,6 +346,9 @@ func TestNormalizeMappingsNoAdjacentSameBuildId(t *testing.T) {
343346
assert.Equal(t, id1, m[0].BuildId)
344347
assert.Equal(t, id2, m[1].BuildId)
345348
assert.Equal(t, id3, m[2].BuildId)
349+
350+
err := ValidateMappings(m, 6*blockSize, blockSize)
351+
require.NoError(t, err)
346352
}
347353

348354
func TestNormalizeMappingsTwoAdjacentSameBuildId(t *testing.T) {
@@ -368,6 +374,9 @@ func TestNormalizeMappingsTwoAdjacentSameBuildId(t *testing.T) {
368374
assert.Equal(t, 5*blockSize, m[0].Length)
369375
assert.Equal(t, baseID, m[0].BuildId)
370376
assert.Equal(t, uint64(0), m[0].BuildStorageOffset)
377+
378+
err := ValidateMappings(m, 5*blockSize, blockSize)
379+
require.NoError(t, err)
371380
}
372381

373382
func TestNormalizeMappingsAllSameBuildId(t *testing.T) {
@@ -405,6 +414,9 @@ func TestNormalizeMappingsAllSameBuildId(t *testing.T) {
405414
assert.Equal(t, 8*blockSize, m[0].Length)
406415
assert.Equal(t, baseID, m[0].BuildId)
407416
assert.Equal(t, uint64(0), m[0].BuildStorageOffset)
417+
418+
err := ValidateMappings(m, size, blockSize)
419+
require.NoError(t, err)
408420
}
409421

410422
func TestNormalizeMappingsMultipleGroupsSameBuildId(t *testing.T) {
@@ -447,6 +459,9 @@ func TestNormalizeMappingsMultipleGroupsSameBuildId(t *testing.T) {
447459
assert.Equal(t, 4*blockSize, m[1].Offset)
448460
assert.Equal(t, 4*blockSize, m[1].Length)
449461
assert.Equal(t, id2, m[1].BuildId)
462+
463+
err := ValidateMappings(m, size, blockSize)
464+
require.NoError(t, err)
450465
}
451466

452467
func TestNormalizeMappingsAlternatingBuildIds(t *testing.T) {
@@ -488,6 +503,9 @@ func TestNormalizeMappingsAlternatingBuildIds(t *testing.T) {
488503
assert.Equal(t, id2, m[1].BuildId)
489504
assert.Equal(t, id1, m[2].BuildId)
490505
assert.Equal(t, id2, m[3].BuildId)
506+
507+
err := ValidateMappings(m, size, blockSize)
508+
require.NoError(t, err)
491509
}
492510

493511
func TestNormalizeMappingsThreeConsecutiveSameBuildId(t *testing.T) {
@@ -519,6 +537,9 @@ func TestNormalizeMappingsThreeConsecutiveSameBuildId(t *testing.T) {
519537
assert.Equal(t, 6*blockSize, m[0].Length)
520538
assert.Equal(t, baseID, m[0].BuildId)
521539
assert.Equal(t, uint64(0), m[0].BuildStorageOffset)
540+
541+
err := ValidateMappings(m, 6*blockSize, blockSize)
542+
require.NoError(t, err)
522543
}
523544

524545
func TestNormalizeMappingsMixedPattern(t *testing.T) {
@@ -580,6 +601,9 @@ func TestNormalizeMappingsMixedPattern(t *testing.T) {
580601
assert.Equal(t, 3*blockSize, m[2].Offset)
581602
assert.Equal(t, 3*blockSize, m[2].Length)
582603
assert.Equal(t, id3, m[2].BuildId)
604+
605+
err := ValidateMappings(m, 6*blockSize, blockSize)
606+
require.NoError(t, err)
583607
}
584608

585609
func TestNormalizeMappingsZeroLengthMapping(t *testing.T) {
@@ -611,6 +635,9 @@ func TestNormalizeMappingsZeroLengthMapping(t *testing.T) {
611635
assert.Equal(t, uint64(0), m[0].Offset)
612636
assert.Equal(t, 4*blockSize, m[0].Length)
613637
assert.Equal(t, baseID, m[0].BuildId)
638+
639+
err := ValidateMappings(m, 4*blockSize, blockSize)
640+
require.NoError(t, err)
614641
}
615642

616643
func TestNormalizeMappingsDoesNotModifyInput(t *testing.T) {
@@ -655,4 +682,7 @@ func TestNormalizeMappingsDoesNotModifyInput(t *testing.T) {
655682
assert.Equal(t, originalLength0, input[0].Length, "Input[0].Length should not change")
656683
assert.Equal(t, originalOffset1, input[1].Offset, "Input[1].Offset should not change")
657684
assert.Equal(t, originalLength1, input[1].Length, "Input[1].Length should not change")
685+
686+
err := ValidateMappings(m, 6*blockSize, blockSize)
687+
require.NoError(t, err)
658688
}

0 commit comments

Comments
 (0)