From 42366c8bb29cf323ac8f3f276a2054a65584b9ee Mon Sep 17 00:00:00 2001 From: Ben Foster Date: Wed, 6 Mar 2024 08:46:22 -0500 Subject: [PATCH] Add test for prefixes when listing blocks from Azure --- tempodb/backend/azure/azure_test.go | 144 ++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) diff --git a/tempodb/backend/azure/azure_test.go b/tempodb/backend/azure/azure_test.go index 8e028de00af..93dd9579a0a 100644 --- a/tempodb/backend/azure/azure_test.go +++ b/tempodb/backend/azure/azure_test.go @@ -252,6 +252,150 @@ func TestObjectWithPrefix(t *testing.T) { } } +func TestListBlocksWithPrefix(t *testing.T) { + tests := []struct { + name string + prefix string + objectName string + keyPath backend.KeyPath + httpHandler func(t *testing.T) http.HandlerFunc + }{ + { + name: "with prefix", + prefix: "a/b/c/", + keyPath: backend.KeyPath{"test"}, + httpHandler: func(t *testing.T) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + if r.Method == "GET" { + _, _ = w.Write([]byte(` + + + a/b/c/ + 100 + + + a/b/c/single-tenant/00000000-0000-0000-0000-000000000000/meta.json + https://myaccount.blob.core.windows.net/mycontainer/a/b/c/single-tenant/00000000-0000-0000-0000-000000000000/meta.json + + Fri, 01 Mar 2024 00:00:00 GMT + 0x8CBFF45D8A29A19 + 100 + text/html + + en-US + + no-cache + BlockBlob + unlocked + + + + + a/b/c/single-tenant/00000000-0000-0000-0000-000000000001/meta.compacted.json + https://myaccount.blob.core.windows.net/mycontainer/a/b/c/single-tenant/00000000-0000-0000-0000-000000000001/meta.compacted.json + + Fri, 01 Mar 2024 00:00:00 GMT + 0x8CBFF45D8A29A19 + 100 + text/html + + en-US + + no-cache + BlockBlob + unlocked + + + + + + `)) + return + } + } + }, + }, + { + name: "without prefix", + prefix: "", + keyPath: backend.KeyPath{"test"}, + httpHandler: func(t *testing.T) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + if r.Method == "GET" { + _, _ = w.Write([]byte(` + + + + 100 + + + single-tenant/00000000-0000-0000-0000-000000000000/meta.json + https://myaccount.blob.core.windows.net/mycontainer/single-tenant/00000000-0000-0000-0000-000000000000/meta.json + + Fri, 01 Mar 2024 00:00:00 GMT + 0x8CBFF45D8A29A19 + 100 + text/html + + en-US + + no-cache + BlockBlob + unlocked + + + + + single-tenant/00000000-0000-0000-0000-000000000001/meta.compacted.json + https://myaccount.blob.core.windows.net/mycontainer/single-tenant/00000000-0000-0000-0000-000000000001/meta.compacted.json + + Fri, 01 Mar 2024 00:00:00 GMT + 0x8CBFF45D8A29A19 + 100 + text/html + + en-US + + no-cache + BlockBlob + unlocked + + + + + + `)) + return + } + } + }, + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + server := testServer(t, tc.httpHandler(t)) + r, _, _, err := New(&config.Config{ + StorageAccountName: "testing_account", + StorageAccountKey: flagext.SecretWithValue("YQo="), + MaxBuffers: 3, + BufferSize: 1000, + ContainerName: "blerg", + Prefix: tc.prefix, + Endpoint: server.URL[7:], // [7:] -> strip http://, + }) + require.NoError(t, err) + + ctx := context.Background() + blockIDs, compactedBlockIDs, err2 := r.ListBlocks(ctx, "single-tenant") + assert.NoError(t, err2) + + assert.Equal(t, 1, len(blockIDs)) + assert.Equal(t, 1, len(compactedBlockIDs)) + }) + } +} + func testServer(t *testing.T, httpHandler http.HandlerFunc) *httptest.Server { t.Helper() assert.NotNil(t, httpHandler)