github.com/dolthub/dolt/go@v0.40.5-0.20240520175717-68db7794bea6/store/nbs/table_reader_test.go (about) 1 // Copyright 2019 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package nbs 16 17 import ( 18 "testing" 19 20 "github.com/stretchr/testify/assert" 21 ) 22 23 func TestCompressedChunkIsEmpty(t *testing.T) { 24 if !EmptyCompressedChunk.IsEmpty() { 25 t.Fatal("EmptyCompressedChunkIsEmpty() should equal true.") 26 } 27 if !(CompressedChunk{}).IsEmpty() { 28 t.Fatal("CompressedChunk{}.IsEmpty() should equal true.") 29 } 30 } 31 32 func TestCanReadAhead(t *testing.T) { 33 type expected struct { 34 end uint64 35 can bool 36 } 37 type testCase struct { 38 rec offsetRec 39 start uint64 40 end uint64 41 blockSize uint64 42 ex expected 43 } 44 for _, c := range []testCase{ 45 testCase{offsetRec{offset: 8191, length: 2048}, 0, 4096, 4096, expected{end: 10239, can: true}}, 46 testCase{offsetRec{offset: 8191, length: 2048}, 0, 4096, 2048, expected{end: 4096, can: false}}, 47 testCase{offsetRec{offset: 2048, length: 2048}, 0, 4096, 2048, expected{end: 4096, can: true}}, 48 testCase{offsetRec{offset: (1 << 27), length: 2048}, 0, 128 * 1024 * 1024, 4096, expected{end: 134217728, can: false}}, 49 } { 50 end, can := canReadAhead(c.rec, c.start, c.end, c.blockSize) 51 assert.Equal(t, c.ex.end, end) 52 assert.Equal(t, c.ex.can, can) 53 } 54 }