azureblob: case insensitive access tier

This commit is contained in:
Rob Pickerill 2022-05-21 19:36:18 +01:00 committed by Nick Craig-Wood
parent 336051870e
commit 6d342a3c5b
2 changed files with 25 additions and 9 deletions

View file

@ -373,15 +373,9 @@ func (o *Object) split() (container, containerPath string) {
// validateAccessTier checks if azureblob supports user supplied tier // validateAccessTier checks if azureblob supports user supplied tier
func validateAccessTier(tier string) bool { func validateAccessTier(tier string) bool {
switch tier { return strings.EqualFold(tier, string(azblob.AccessTierHot)) ||
case string(azblob.AccessTierHot), strings.EqualFold(tier, string(azblob.AccessTierCool)) ||
string(azblob.AccessTierCool), strings.EqualFold(tier, string(azblob.AccessTierArchive))
string(azblob.AccessTierArchive):
// valid cases
return true
default:
return false
}
} }
// validatePublicAccess checks if azureblob supports use supplied public access level // validatePublicAccess checks if azureblob supports use supplied public access level

View file

@ -61,3 +61,25 @@ func TestServicePrincipalFileFailure(t *testing.T) {
assert.Error(t, err) assert.Error(t, err)
assert.EqualError(t, err, "error creating service principal token: parameter 'secret' cannot be empty") 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)
})
}
}