Skip to content

Commit

Permalink
Avoid using unexported constants in tests
Browse files Browse the repository at this point in the history
This commit:
- adds new function targetSlabSize() in settings.go
- exports targetSlabSize() to TargetSlabSize() in export_test.go
  for testing
- modifies tests to use exported function instead of unexported
constants targetThreshold.
  • Loading branch information
fxamacker committed Jan 24, 2025
1 parent 47c971a commit 1c177a0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5028,7 +5028,7 @@ func TestArrayMaxInlineElement(t *testing.T) {
// Size of root data slab with two elements of max inlined size is target slab size minus
// slab id size (next slab id is omitted in root slab), and minus 1 byte
// (for rounding when computing max inline array element size).
require.Equal(t, targetThreshold-SlabIDLength-1, uint64(array.root.Header().size))
require.Equal(t, TargetSlabSize()-SlabIDLength-1, uint64(array.root.Header().size))

testArray(t, storage, typeInfo, address, array, values, false)
}
Expand Down
5 changes: 5 additions & 0 deletions export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ var (
GetCBOREncMode = (*PersistentSlabStorage).getCBOREncMode
GetCBORDecMode = (*PersistentSlabStorage).getCBORDecMode
)

// Exported function of slab size settings for testing.
var (
TargetSlabSize = targetSlabSize
)
2 changes: 1 addition & 1 deletion map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14339,7 +14339,7 @@ func TestMapMaxInlineElement(t *testing.T) {
// Size of root data slab with two elements (key+value pairs) of
// max inlined size is target slab size minus
// slab id size (next slab id is omitted in root slab)
require.Equal(t, targetThreshold-SlabIDLength, uint64(m.root.Header().size))
require.Equal(t, TargetSlabSize()-SlabIDLength, uint64(m.root.Header().size))

testMap(t, storage, typeInfo, address, m, keyValues, nil, false)
}
Expand Down
4 changes: 4 additions & 0 deletions settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,7 @@ func MaxInlineMapKeySize() uint64 {
func maxInlineMapValueSize(keySize uint64) uint64 {
return maxInlineMapElementSize - keySize - singleElementPrefixSize
}

func targetSlabSize() uint64 {
return targetThreshold
}

0 comments on commit 1c177a0

Please sign in to comment.