22// of this source code is governed by a BSD-style license that can be found in
33// the LICENSE file.
44
5- package testutils
5+ // Package blobtest contains helpers for interacting with value separation and
6+ // blob files in tests.
7+ package blobtest
68
79import (
810 "context"
@@ -12,13 +14,14 @@ import (
1214 "github.com/cockroachdb/errors"
1315 "github.com/cockroachdb/pebble/internal/base"
1416 "github.com/cockroachdb/pebble/internal/strparse"
17+ "github.com/cockroachdb/pebble/internal/testutils"
1518 "github.com/cockroachdb/pebble/sstable/blob"
1619)
1720
18- // BlobValues is a helper for using blob handles in tests. It supports parsing a
21+ // Values is a helper for using blob handles in tests. It supports parsing a
1922// human-readable string describing a blob handle, synthesizing unspecified
2023// fields, and tracking the blob handle to support future fetches.
21- type BlobValues struct {
24+ type Values struct {
2225 mostRecentHandle blob.Handle
2326 // trackedHandles maps from a blob handle to its value. The value may be nil
2427 // if the value was not specified (in which case Fetch will
@@ -27,7 +30,7 @@ type BlobValues struct {
2730}
2831
2932// Fetch returns the value corresponding to the given handle.
30- func (bv * BlobValues ) Fetch (
33+ func (bv * Values ) Fetch (
3134 ctx context.Context , handleSuffix []byte , blobFileNum base.DiskFileNum , valLen uint32 , _ []byte ,
3235) (val []byte , callerOwned bool , err error ) {
3336 if bv .trackedHandles == nil {
@@ -51,14 +54,14 @@ func (bv *BlobValues) Fetch(
5154 // deterministically from the file number, block number and offset in block.
5255 if len (value ) == 0 {
5356 rng := rand .New (rand .NewPCG ((uint64 (decodedHandle .FileNum )<< 32 )| uint64 (decodedHandle .BlockNum ), uint64 (decodedHandle .OffsetInBlock )))
54- return RandBytes (rng , int (decodedHandle .ValueLen )), false , nil
57+ return testutils . RandBytes (rng , int (decodedHandle .ValueLen )), false , nil
5558 }
5659 return []byte (value ), false , nil
5760}
5861
5962// ParseInternalValue parses a debug blob handle from the string, returning the
6063// handle as an InternalValue and recording the handle's corresponding value.
61- func (bv * BlobValues ) ParseInternalValue (input string ) (base.InternalValue , error ) {
64+ func (bv * Values ) ParseInternalValue (input string ) (base.InternalValue , error ) {
6265 h , err := bv .Parse (input )
6366 if err != nil {
6467 return base.InternalValue {}, err
@@ -88,13 +91,13 @@ func (bv *BlobValues) ParseInternalValue(input string) (base.InternalValue, erro
8891
8992// IsBlobHandle returns true if the input string looks like it's a debug blob
9093// handle.
91- func (bv * BlobValues ) IsBlobHandle (input string ) bool {
94+ func (bv * Values ) IsBlobHandle (input string ) bool {
9295 return strings .HasPrefix (input , "blob{" )
9396}
9497
9598// Parse parses a debug blob handle from the string, returning the handle and
9699// recording the handle's corresponding value.
97- func (bv * BlobValues ) Parse (input string ) (h blob.Handle , err error ) {
100+ func (bv * Values ) Parse (input string ) (h blob.Handle , err error ) {
98101 if bv .trackedHandles == nil {
99102 bv .trackedHandles = make (map [blob.Handle ]string )
100103 }
@@ -170,8 +173,8 @@ func (bv *BlobValues) Parse(input string) (h blob.Handle, err error) {
170173// returning an inline handle.
171174//
172175// It's intended for tests that must manually construct inline blob references.
173- func (bv * BlobValues ) ParseInlineHandle (
174- input string , references * BlobReferences ,
176+ func (bv * Values ) ParseInlineHandle (
177+ input string , references * References ,
175178) (h blob.InlineHandle , err error ) {
176179 fullHandle , err := bv .Parse (input )
177180 if err != nil {
@@ -197,16 +200,16 @@ func errFromPanic(r any) error {
197200 return errors .Errorf ("%v" , r )
198201}
199202
200- // BlobReferences is a helper for tests that manually construct inline blob
203+ // References is a helper for tests that manually construct inline blob
201204// references. It tracks the set of file numbers used within a sstable, and maps
202205// each file number to a reference index (encoded within the
203206// blob.InlineHandlePreface).
204- type BlobReferences struct {
207+ type References struct {
205208 fileNums []base.DiskFileNum
206209}
207210
208211// MapToReferenceIndex maps the given file number to a reference index.
209- func (b * BlobReferences ) MapToReferenceIndex (fileNum base.DiskFileNum ) uint32 {
212+ func (b * References ) MapToReferenceIndex (fileNum base.DiskFileNum ) uint32 {
210213 for i , fn := range b .fileNums {
211214 if fn == fileNum {
212215 return uint32 (i )
0 commit comments