github.com/matrixorigin/matrixone@v1.2.0/pkg/fileservice/io_entry_test.go (about) 1 // Copyright 2022 Matrix Origin 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 fileservice 16 17 import ( 18 "bytes" 19 "context" 20 "testing" 21 "testing/iotest" 22 23 "github.com/stretchr/testify/assert" 24 ) 25 26 func TestIOEntriesReader(t *testing.T) { 27 ctx := context.Background() 28 29 entries := []IOEntry{ 30 { 31 Offset: 0, 32 Size: 1, 33 Data: []byte("a"), 34 }, 35 } 36 assert.Nil(t, iotest.TestReader(newIOEntriesReader(ctx, entries), []byte("a"))) 37 38 entries = []IOEntry{ 39 { 40 Offset: 1, 41 Size: 1, 42 Data: []byte("a"), 43 }, 44 } 45 assert.Nil(t, iotest.TestReader(newIOEntriesReader(ctx, entries), []byte("\x00a"))) 46 47 entries = []IOEntry{ 48 { 49 Offset: 0, 50 Size: 1024, 51 Data: bytes.Repeat([]byte("a"), 1024), 52 }, 53 } 54 assert.Nil(t, iotest.TestReader(newIOEntriesReader(ctx, entries), bytes.Repeat([]byte("a"), 1024))) 55 56 entries = []IOEntry{ 57 { 58 Size: -1, 59 ReaderForWrite: bytes.NewReader([]byte("abc")), 60 }, 61 } 62 assert.Nil(t, iotest.TestReader(newIOEntriesReader(ctx, entries), []byte("abc"))) 63 64 } 65 66 func TestIOEntryString(t *testing.T) { 67 entry := IOEntry{ 68 Size: 90, 69 Offset: -1, 70 } 71 str := entry.String() 72 if str != "IOEntry(offset = -1, size = 90)" { 73 t.Fatalf("got %v", str) 74 } 75 }