It always felt wrong that the method uploaded the blob under a different name than the one specified in the blob metadata. This commit moves the responsibility of specifying the right extension to the callers. azure.EnsureVHDExtension helper was added to simplify this. Signed-off-by: Ondřej Budai <ondrej@budai.cz>
33 lines
757 B
Go
33 lines
757 B
Go
package azure
|
|
|
|
import (
|
|
"regexp"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestRandomStorageAccountName(t *testing.T) {
|
|
randomName := RandomStorageAccountName("ib")
|
|
|
|
assert.Len(t, randomName, 24)
|
|
|
|
r := regexp.MustCompile(`^[\d\w]{24}$`)
|
|
assert.True(t, r.MatchString(randomName), "the returned name should be 24 characters long and contain only alphanumerical characters")
|
|
}
|
|
|
|
func TestEnsureVHDExtension(t *testing.T) {
|
|
tests := []struct {
|
|
s string
|
|
want string
|
|
}{
|
|
{s: "toucan.zip", want: "toucan.zip.vhd"},
|
|
{s: "kingfisher.vhd", want: "kingfisher.vhd"},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.s, func(t *testing.T) {
|
|
require.Equal(t, tt.want, EnsureVHDExtension(tt.s))
|
|
})
|
|
}
|
|
}
|