github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/logtail/service/chunk_test.go (about) 1 // Copyright 2021 Matrix Origin 2 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // you may not use this file except in compliance with the License. 4 // You may obtain a copy of the License at 5 // 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package service 15 16 import ( 17 "bytes" 18 "testing" 19 20 "github.com/stretchr/testify/require" 21 ) 22 23 func TestChunk(t *testing.T) { 24 data := []byte("hello, world") 25 26 for limit := 1; limit <= len(data)+1; limit++ { 27 chunks := Split(data, limit) 28 29 merged := make([]byte, 0, len(data)) 30 merged = AppendChunk(merged, chunks...) 31 32 require.True(t, bytes.Equal(data, merged)) 33 } 34 } 35 36 func TestSplit(t *testing.T) { 37 buf := make([]byte, 11) 38 chunks := Split(buf, 5) 39 require.Equal(t, 3, len(chunks)) 40 require.Equal(t, 5, len(chunks[0])) 41 require.Equal(t, 5, len(chunks[1])) 42 require.Equal(t, 1, len(chunks[2])) 43 }