github.com/muhammadn/cortex@v1.9.1-0.20220510110439-46bb7000d03d/pkg/storage/tsdb/tenant_deletion_mark_test.go (about)

     1  package tsdb
     2  
     3  import (
     4  	"bytes"
     5  	"context"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/require"
     9  	"github.com/thanos-io/thanos/pkg/objstore"
    10  )
    11  
    12  func TestTenantDeletionMarkExists(t *testing.T) {
    13  	const username = "user"
    14  
    15  	for name, tc := range map[string]struct {
    16  		objects map[string][]byte
    17  		exists  bool
    18  	}{
    19  		"empty": {
    20  			objects: nil,
    21  			exists:  false,
    22  		},
    23  
    24  		"mark doesn't exist": {
    25  			objects: map[string][]byte{
    26  				"user/01EQK4QKFHVSZYVJ908Y7HH9E0/meta.json": []byte("data"),
    27  			},
    28  			exists: false,
    29  		},
    30  
    31  		"mark exists": {
    32  			objects: map[string][]byte{
    33  				"user/01EQK4QKFHVSZYVJ908Y7HH9E0/meta.json": []byte("data"),
    34  				"user/" + TenantDeletionMarkPath:            []byte("data"),
    35  			},
    36  			exists: true,
    37  		},
    38  	} {
    39  		t.Run(name, func(t *testing.T) {
    40  			bkt := objstore.NewInMemBucket()
    41  			// "upload" objects
    42  			for objName, data := range tc.objects {
    43  				require.NoError(t, bkt.Upload(context.Background(), objName, bytes.NewReader(data)))
    44  			}
    45  
    46  			res, err := TenantDeletionMarkExists(context.Background(), bkt, username)
    47  			require.NoError(t, err)
    48  			require.Equal(t, tc.exists, res)
    49  		})
    50  	}
    51  }