From 7eda96bea49cb81597f4dde0dfde5b2eee6757bd Mon Sep 17 00:00:00 2001
From: Guillaume Tardif <guillaume.tardif@docker.com>
Date: Thu, 24 Sep 2020 09:52:17 +0200
Subject: [PATCH] =?UTF-8?q?Fix=20nil=20pointer=20when=20creating=20volume?=
 =?UTF-8?q?=20with=20=E2=80=9C=E2=80=9D=20storage=20account?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Guillaume Tardif <guillaume.tardif@docker.com>
---
 aci/volumes.go                | 7 +++----
 tests/aci-e2e/e2e-aci_test.go | 9 +++++++++
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/aci/volumes.go b/aci/volumes.go
index a07af69f7..8eb804deb 100644
--- a/aci/volumes.go
+++ b/aci/volumes.go
@@ -92,10 +92,9 @@ func (cs *aciVolumeService) Create(ctx context.Context, options interface{}) (vo
 	account, err := accountClient.GetProperties(ctx, cs.aciContext.ResourceGroup, opts.Account, "")
 	if err == nil {
 		w.Event(event(opts.Account, progress.Done, "Use existing"))
+	} else if !account.HasHTTPStatus(http.StatusNotFound) {
+		return volumes.Volume{}, err
 	} else {
-		if account.StatusCode != http.StatusNotFound {
-			return volumes.Volume{}, err
-		}
 		result, err := accountClient.CheckNameAvailability(ctx, storage.AccountCheckNameAvailabilityParameters{
 			Name: to.StringPtr(opts.Account),
 			Type: to.StringPtr("Microsoft.Storage/storageAccounts"),
@@ -137,7 +136,7 @@ func (cs *aciVolumeService) Create(ctx context.Context, options interface{}) (vo
 		w.Event(errorEvent(opts.Fileshare))
 		return volumes.Volume{}, errors.Wrapf(errdefs.ErrAlreadyExists, "Azure fileshare %q already exists", opts.Fileshare)
 	}
-	if fileShare.StatusCode != http.StatusNotFound {
+	if !fileShare.HasHTTPStatus(http.StatusNotFound) {
 		w.Event(errorEvent(opts.Fileshare))
 		return volumes.Volume{}, err
 	}
diff --git a/tests/aci-e2e/e2e-aci_test.go b/tests/aci-e2e/e2e-aci_test.go
index 3456ffc6e..3f6c2ff0b 100644
--- a/tests/aci-e2e/e2e-aci_test.go
+++ b/tests/aci-e2e/e2e-aci_test.go
@@ -150,6 +150,15 @@ func TestContainerRunVolume(t *testing.T) {
 		accountName = "e2e" + strconv.Itoa(int(time.Now().UnixNano()))
 	)
 
+	t.Run("check empty volume name validity", func(t *testing.T) {
+		invalidName := ""
+		res := c.RunDockerOrExitError("volume", "create", "--storage-account", invalidName, "--fileshare", fileshareName)
+		res.Assert(t, icmd.Expected{
+			ExitCode: 1,
+			Err:      `parameter=accountName constraint=MinLength value="" details: value length must be greater than or equal to 3`,
+		})
+	})
+
 	t.Run("check volume name validity", func(t *testing.T) {
 		invalidName := "some-storage-123"
 		res := c.RunDockerOrExitError("volume", "create", "--storage-account", invalidName, "--fileshare", fileshareName)