github.com/grafana/pyroscope@v1.18.0/pkg/phlaredb/bucket/tenant_deletion_mark_test.go (about) 1 // SPDX-License-Identifier: AGPL-3.0-only 2 // Provenance-includes-location: https://github.com/cortexproject/cortex/blob/master/pkg/storage/tsdb/tenant_deletion_mark_test.go 3 // Provenance-includes-license: Apache-2.0 4 // Provenance-includes-copyright: The Cortex Authors. 5 6 package bucket 7 8 import ( 9 "bytes" 10 "context" 11 "testing" 12 13 "github.com/stretchr/testify/require" 14 "github.com/thanos-io/objstore" 15 16 phlareobj "github.com/grafana/pyroscope/pkg/objstore" 17 ) 18 19 func TestTenantDeletionMarkExists(t *testing.T) { 20 const username = "user" 21 22 for name, tc := range map[string]struct { 23 objects map[string][]byte 24 exists bool 25 }{ 26 "empty": { 27 objects: nil, 28 exists: false, 29 }, 30 31 "mark doesn't exist": { 32 objects: map[string][]byte{ 33 "user/phlaredb/01EQK4QKFHVSZYVJ908Y7HH9E0/meta.json": []byte("data"), 34 }, 35 exists: false, 36 }, 37 38 "mark exists": { 39 objects: map[string][]byte{ 40 "user/phlaredb/01EQK4QKFHVSZYVJ908Y7HH9E0/meta.json": []byte("data"), 41 "user/phlaredb/" + TenantDeletionMarkPath: []byte("data"), 42 }, 43 exists: true, 44 }, 45 } { 46 t.Run(name, func(t *testing.T) { 47 bkt := objstore.NewInMemBucket() 48 // "upload" objects 49 for objName, data := range tc.objects { 50 require.NoError(t, bkt.Upload(context.Background(), objName, bytes.NewReader(data))) 51 } 52 53 res, err := TenantDeletionMarkExists(context.Background(), phlareobj.NewBucket(bkt), username) 54 require.NoError(t, err) 55 require.Equal(t, tc.exists, res) 56 }) 57 } 58 }