From 6d342a3c5b0386adcf261020c323aad84449e32b Mon Sep 17 00:00:00 2001 From: Rob Pickerill Date: Sat, 21 May 2022 19:36:18 +0100 Subject: [PATCH] azureblob: case insensitive access tier --- backend/azureblob/azureblob.go | 12 +++--------- backend/azureblob/azureblob_test.go | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/backend/azureblob/azureblob.go b/backend/azureblob/azureblob.go index f03ff72ef..f94c1ea00 100644 --- a/backend/azureblob/azureblob.go +++ b/backend/azureblob/azureblob.go @@ -373,15 +373,9 @@ func (o *Object) split() (container, containerPath string) { // validateAccessTier checks if azureblob supports user supplied tier func validateAccessTier(tier string) bool { - switch tier { - case string(azblob.AccessTierHot), - string(azblob.AccessTierCool), - string(azblob.AccessTierArchive): - // valid cases - return true - default: - return false - } + return strings.EqualFold(tier, string(azblob.AccessTierHot)) || + strings.EqualFold(tier, string(azblob.AccessTierCool)) || + strings.EqualFold(tier, string(azblob.AccessTierArchive)) } // validatePublicAccess checks if azureblob supports use supplied public access level diff --git a/backend/azureblob/azureblob_test.go b/backend/azureblob/azureblob_test.go index 92af6ac43..f9ebd7b3d 100644 --- a/backend/azureblob/azureblob_test.go +++ b/backend/azureblob/azureblob_test.go @@ -61,3 +61,25 @@ func TestServicePrincipalFileFailure(t *testing.T) { assert.Error(t, err) assert.EqualError(t, err, "error creating service principal token: parameter 'secret' cannot be empty") } + +func TestValidateAccessTier(t *testing.T) { + tests := map[string]struct { + accessTier string + want bool + }{ + "hot": {"hot", true}, + "HOT": {"HOT", true}, + "Hot": {"Hot", true}, + "cool": {"cool", true}, + "archive": {"archive", true}, + "empty": {"", false}, + "unknown": {"unknown", false}, + } + + for name, test := range tests { + t.Run(name, func(t *testing.T) { + got := validateAccessTier(test.accessTier) + assert.Equal(t, test.want, got) + }) + } +}