github.com/petermattis/pebble@v0.0.0-20190905164901-ab51a2166067/internal/rangedel/truncate_test.go (about) 1 // Copyright 2019 The LevelDB-Go and Pebble Authors. All rights reserved. Use 2 // of this source code is governed by a BSD-style license that can be found in 3 // the LICENSE file. 4 5 package rangedel 6 7 import ( 8 "fmt" 9 "strings" 10 "testing" 11 12 "github.com/petermattis/pebble/internal/base" 13 "github.com/petermattis/pebble/internal/datadriven" 14 ) 15 16 func TestTruncate(t *testing.T) { 17 cmp := base.DefaultComparer.Compare 18 var iter iterator 19 20 datadriven.RunTest(t, "testdata/truncate", func(d *datadriven.TestData) string { 21 switch d.Cmd { 22 case "build": 23 tombstones := buildTombstones(t, cmp, d.Input) 24 iter = NewIter(cmp, tombstones) 25 return formatTombstones(tombstones) 26 27 case "truncate": 28 if len(d.Input) > 0 { 29 t.Fatalf("unexpected input: %s", d.Input) 30 } 31 if len(d.CmdArgs) != 1 { 32 t.Fatalf("expected 1 argument: %s", d.CmdArgs) 33 } 34 parts := strings.Split(d.CmdArgs[0].String(), "-") 35 if len(parts) != 2 { 36 t.Fatalf("malformed arg: %s", d.CmdArgs[0]) 37 } 38 lower := []byte(parts[0]) 39 upper := []byte(parts[1]) 40 41 truncated := Truncate(cmp, iter, lower, upper) 42 return formatTombstones(truncated.tombstones) 43 44 default: 45 return fmt.Sprintf("unknown command: %s", d.Cmd) 46 } 47 }) 48 }