Skip to content

Commit 0be36a1

Browse files
committed
storage: construct roachpb.Values appropriately in unit tests
Fix unit tests that were improperly constructing roachpb.Values by directly setting roachpb.Value's RawBytes field without the appropriate encoding. Epic: none Release note: none
1 parent 4c2edf3 commit 0be36a1

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

pkg/storage/batch_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func testBatchBasics(t *testing.T, writeOnly bool, commit func(e Engine, b Write
9595
// Write a MVCC value to be deleted with a known value size.
9696
keyF := mvccKey("f")
9797
keyF.Timestamp.WallTime = 1
98-
valueF := MVCCValue{Value: roachpb.Value{RawBytes: []byte("fvalue")}}
98+
valueF := MVCCValue{Value: roachpb.MakeValueFromString("fvalue")}
9999
encodedValueF, err := EncodeMVCCValue(valueF)
100100
require.NoError(t, err)
101101
require.NoError(t, e.PutMVCC(keyF, valueF))
@@ -313,7 +313,7 @@ func TestBatchRepr(t *testing.T) {
313313
"merge(c\x00)",
314314
"put(e\x00,)",
315315
"single_delete(d\x00)",
316-
"delete-sized(f\x00\x00\x00\x00\x00\x00\x00\x00\x01\t,17)",
316+
"delete-sized(f\x00\x00\x00\x00\x00\x00\x00\x00\x01\t,22)",
317317
}
318318
require.Equal(t, expOps, ops)
319319

pkg/storage/engine_key_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ func BenchmarkEngineKeyVerify(b *testing.B) {
414414
Key: roachpb.Key("foobar"),
415415
Timestamp: hlc.Timestamp{WallTime: 1711383740550067000, Logical: 2},
416416
},
417-
MVCCValue{Value: roachpb.Value{RawBytes: []byte("hello world")}},
417+
MVCCValue{Value: roachpb.MakeValueFromBytes([]byte("hello world"))},
418418
),
419419
},
420420
{
@@ -429,7 +429,7 @@ func BenchmarkEngineKeyVerify(b *testing.B) {
429429
LocalTimestamp: hlc.ClockTimestamp{WallTime: 1711383740550069000},
430430
OmitInRangefeeds: true,
431431
},
432-
Value: roachpb.Value{RawBytes: []byte("hello world")},
432+
Value: roachpb.MakeValueFromString("hello world"),
433433
},
434434
),
435435
},
@@ -446,7 +446,7 @@ func BenchmarkEngineKeyVerify(b *testing.B) {
446446
ValBytes: 100,
447447
},
448448
MVCCValue{
449-
Value: roachpb.Value{RawBytes: []byte("hello world")},
449+
Value: roachpb.MakeValueFromString("hello world"),
450450
},
451451
),
452452
},

pkg/storage/engine_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,7 @@ func TestCreateCheckpoint_SpanConstrained(t *testing.T) {
11051105
for i := 1; i <= maxTableID; i++ {
11061106
require.NoError(t, b.PutMVCC(
11071107
MVCCKey{Key: key(i), Timestamp: hlc.Timestamp{WallTime: int64(i)}},
1108-
MVCCValue{Value: roachpb.Value{RawBytes: randutil.RandBytes(rng, 100)}},
1108+
MVCCValue{Value: roachpb.MakeValueFromBytes(randutil.RandBytes(rng, 100))},
11091109
))
11101110
}
11111111
require.NoError(t, b.Commit(true /* sync */))
@@ -1640,7 +1640,7 @@ func TestScanLocks(t *testing.T) {
16401640
for k, str := range locks {
16411641
var err error
16421642
if str == lock.Intent {
1643-
_, err = MVCCPut(ctx, eng, roachpb.Key(k), txn1.ReadTimestamp, roachpb.Value{RawBytes: roachpb.Key(k)}, MVCCWriteOptions{Txn: txn1})
1643+
_, err = MVCCPut(ctx, eng, roachpb.Key(k), txn1.ReadTimestamp, roachpb.MakeValueFromBytes(roachpb.Key(k)), MVCCWriteOptions{Txn: txn1})
16441644
} else {
16451645
err = MVCCAcquireLock(ctx, eng, &txn1.TxnMeta, txn1.IgnoredSeqNums, str, roachpb.Key(k), nil, 0, 0)
16461646
}
@@ -2135,7 +2135,7 @@ func TestScanConflictingIntentsForDroppingLatchesEarly(t *testing.T) {
21352135
keyB := roachpb.Key("b")
21362136
keyC := roachpb.Key("c")
21372137
keyD := roachpb.Key("d")
2138-
val := roachpb.Value{RawBytes: []byte{'v'}}
2138+
val := roachpb.MakeValueFromString("v")
21392139

21402140
testCases := []struct {
21412141
name string
@@ -2356,7 +2356,7 @@ func TestScanConflictingIntentsForDroppingLatchesEarlyReadYourOwnWrites(t *testi
23562356
aboveReadSeqNumber := enginepb.TxnSeq(3)
23572357

23582358
keyA := roachpb.Key("a")
2359-
val := roachpb.Value{RawBytes: []byte{'v'}}
2359+
val := roachpb.MakeValueFromString("v")
23602360

23612361
testCases := []struct {
23622362
name string

pkg/storage/pebble_mvcc_scanner_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func TestMVCCScanWithMemoryAccounting(t *testing.T) {
219219
GlobalUncertaintyLimit: ts1,
220220
}
221221
ui1 := uncertainty.Interval{GlobalLimit: txn1.GlobalUncertaintyLimit}
222-
val := roachpb.Value{RawBytes: bytes.Repeat([]byte("v"), 1000)}
222+
val := roachpb.MakeValueFromBytes(bytes.Repeat([]byte{'v'}, 1000))
223223
func() {
224224
batch := eng.NewBatch()
225225
defer batch.Close()

0 commit comments

Comments
 (0)