github.com/portworx/kvdb@v0.0.0-20241107215734-a185a966f535/common/common_test.go (about) 1 package common 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestPrunePrefixes(t *testing.T) { 10 inputPrefixes := []string{"snapshot/", "snapshot/test", "snapshot1/"} 11 expectedPrefixes := []string{"snapshot/", "snapshot1/"} 12 13 testPrunePrefixes(t, expectedPrefixes, inputPrefixes) 14 15 inputPrefixes = []string{"", "snapshot/test", "snapshot1/"} 16 expectedPrefixes = []string{""} 17 18 testPrunePrefixes(t, expectedPrefixes, inputPrefixes) 19 20 inputPrefixes = []string{"snapshot", "snapshot/test", "snapshot1"} 21 expectedPrefixes = []string{"snapshot"} 22 23 testPrunePrefixes(t, expectedPrefixes, inputPrefixes) 24 25 } 26 27 func testPrunePrefixes(t *testing.T, expectedPrefixes, inputPrefixes []string) { 28 e := PrunePrefixes(inputPrefixes) 29 assert.Equal(t, len(e), len(expectedPrefixes), "Unexpected no. of prefixes") 30 for i := 0; i < len(e); i++ { 31 found := false 32 for j := 0; j < len(expectedPrefixes); j++ { 33 if e[i] == expectedPrefixes[j] { 34 found = true 35 } 36 } 37 assert.True(t, found, "Expected prefix not found") 38 } 39 40 }