From 25a1a6abe0685dce9f641de523f0b641558fe229 Mon Sep 17 00:00:00 2001 From: Tom Bamford Date: Mon, 18 Mar 2024 21:45:40 +0000 Subject: [PATCH] additional tests for parsing invalid nested blob resource IDs --- storage/2020-08-04/blob/blobs/resource_id_test.go | 15 +++++++++++++++ storage/2023-11-03/blob/blobs/resource_id_test.go | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/storage/2020-08-04/blob/blobs/resource_id_test.go b/storage/2020-08-04/blob/blobs/resource_id_test.go index eb453b8..c156b55 100644 --- a/storage/2020-08-04/blob/blobs/resource_id_test.go +++ b/storage/2020-08-04/blob/blobs/resource_id_test.go @@ -181,6 +181,21 @@ func TestFormatNestedBlobIDStandard(t *testing.T) { } } +func TestParseInvalidBlobIDStandard(t *testing.T) { + input := "https://example1.blob.core.windows.net/blobby.vhd" + actual, err := ParseBlobID(input, "core.windows.net") + if err == nil { + if actual != nil { + t.Fatalf("expected an error but got: %#v", *actual) + } else { + t.Fatalf("expected an error but got no error and a nil result") + } + } + if err.Error() != "expected the path to contain at least 2 segments but got 1" { + t.Fatalf("unexpected error received: %+v", err) + } +} + func TestFormatBlobIDInDNSZone(t *testing.T) { actual := BlobId{ AccountId: accounts.AccountId{ diff --git a/storage/2023-11-03/blob/blobs/resource_id_test.go b/storage/2023-11-03/blob/blobs/resource_id_test.go index fe60fd9..d8fc21e 100644 --- a/storage/2023-11-03/blob/blobs/resource_id_test.go +++ b/storage/2023-11-03/blob/blobs/resource_id_test.go @@ -71,6 +71,21 @@ func TestParseNestedBlobIDStandard(t *testing.T) { } } +func TestParseInvalidBlobIDStandard(t *testing.T) { + input := "https://example1.blob.core.windows.net/blobby.vhd" + actual, err := ParseBlobID(input, "core.windows.net") + if err == nil { + if actual != nil { + t.Fatalf("expected an error but got: %#v", *actual) + } else { + t.Fatalf("expected an error but got no error and a nil result") + } + } + if err.Error() != "expected the path to contain at least 2 segments but got 1" { + t.Fatalf("unexpected error received: %+v", err) + } +} + func TestParseBlobIDInADNSZone(t *testing.T) { input := "https://example1.zone1.blob.storage.azure.net/container1/blob1.vhd" expected := BlobId{