github.com/containerd/nerdctl/v2@v2.0.0-beta.5.0.20240520001846-b5758f54fa28/pkg/logging/tail/tail_test.go (about) 1 /* 2 Copyright The containerd Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 /* 18 Forked from https://github.com/kubernetes/kubernetes/blob/master/pkg/util/tail/tail_test.go 19 Copyright The Kubernetes Authors. 20 Licensed under the Apache License, Version 2.0 21 */ 22 23 package tail 24 25 import ( 26 "bytes" 27 "strings" 28 "testing" 29 ) 30 31 func TestTail(t *testing.T) { 32 line := strings.Repeat("a", blockSize) 33 testBytes := []byte(line + "\n" + 34 line + "\n" + 35 line + "\n" + 36 line + "\n" + 37 line[blockSize/2:]) // incomplete line 38 39 for c, test := range []struct { 40 n uint32 41 start int64 42 }{ 43 {n: 0, start: 0}, 44 {n: 1, start: int64(len(line)+1) * 3}, 45 {n: 9999, start: 0}, 46 } { 47 t.Logf("TestCase #%d: %+v", c, test) 48 r := bytes.NewReader(testBytes) 49 s, err := FindTailLineStartIndex(r, uint(test.n)) 50 if err != nil { 51 t.Error(err) 52 } 53 if s != test.start { 54 t.Errorf("%d != %d", s, test.start) 55 } 56 } 57 }