github.com/grafana/pyroscope@v1.18.0/pkg/objstore/bucket_util_test.go (about) 1 // SPDX-License-Identifier: AGPL-3.0-only 2 // Provenance-includes-location: https://github.com/cortexproject/cortex/blob/master/pkg/storage/bucket/bucket_util_test.go 3 // Provenance-includes-license: Apache-2.0 4 // Provenance-includes-copyright: The Cortex Authors. 5 6 package objstore 7 8 import ( 9 "context" 10 "strings" 11 "testing" 12 13 "github.com/go-kit/log" 14 "github.com/stretchr/testify/assert" 15 "github.com/stretchr/testify/require" 16 "github.com/thanos-io/objstore" 17 ) 18 19 func TestDeletePrefix(t *testing.T) { 20 mem := objstore.NewInMemBucket() 21 22 require.NoError(t, mem.Upload(context.Background(), "obj", strings.NewReader("hello"))) 23 require.NoError(t, mem.Upload(context.Background(), "prefix/1", strings.NewReader("hello"))) 24 require.NoError(t, mem.Upload(context.Background(), "prefix/2", strings.NewReader("hello"))) 25 require.NoError(t, mem.Upload(context.Background(), "prefix/sub1/3", strings.NewReader("hello"))) 26 require.NoError(t, mem.Upload(context.Background(), "prefix/sub2/4", strings.NewReader("hello"))) 27 require.NoError(t, mem.Upload(context.Background(), "outside/obj", strings.NewReader("hello"))) 28 29 del, err := DeletePrefix(context.Background(), mem, "prefix", log.NewNopLogger()) 30 require.NoError(t, err) 31 assert.Equal(t, 4, del) 32 assert.Equal(t, 2, len(mem.Objects())) 33 }