From bdd987f246b72c86fd0520d9cd3a45200fead802 Mon Sep 17 00:00:00 2001 From: Ulysses Souza Date: Tue, 19 May 2020 15:26:59 +0200 Subject: [PATCH] Refactor placement and method name Signed-off-by: Ulysses Souza --- azure/convert/volume.go | 14 ++--- azure/storage/storage_test.go | 67 --------------------- tests/aci-e2e/e2e-aci.go | 2 +- {azure => tests/aci-e2e}/storage/storage.go | 0 4 files changed, 8 insertions(+), 75 deletions(-) delete mode 100644 azure/storage/storage_test.go rename {azure => tests/aci-e2e}/storage/storage.go (100%) diff --git a/azure/convert/volume.go b/azure/convert/volume.go index 1a6598f6..0368aa37 100644 --- a/azure/convert/volume.go +++ b/azure/convert/volume.go @@ -49,7 +49,7 @@ type volumeInput struct { target string } -func scapeKeySlashes(rawURL string) (string, error) { +func escapeKeySlashes(rawURL string) (string, error) { urlSplit := strings.Split(rawURL, "@") if len(urlSplit) < 1 { return "", errors.New("invalid url format " + rawURL) @@ -60,13 +60,13 @@ func scapeKeySlashes(rawURL string) (string, error) { return scaped, nil } -func unscapeKey(passwd string) string { - return strings.ReplaceAll(passwd, "_", "/") +func unescapeKey(key string) string { + return strings.ReplaceAll(key, "_", "/") } // Removes the second ':' that separates the source from target func volumeURL(pathURL string) (*url.URL, error) { - scapedURL, err := scapeKeySlashes(pathURL) + scapedURL, err := escapeKeySlashes(pathURL) if err != nil { return nil, err } @@ -92,11 +92,11 @@ func (v *volumeInput) parse(name string, s string) error { if v.username == "" { return fmt.Errorf("volume specification %q does not include a storage username", v) } - passwd, ok := volumeURL.User.Password() - if !ok || passwd == "" { + key, ok := volumeURL.User.Password() + if !ok || key == "" { return fmt.Errorf("volume specification %q does not include a storage key", v) } - v.key = unscapeKey(passwd) + v.key = unescapeKey(key) v.share = volumeURL.Host if v.share == "" { return fmt.Errorf("volume specification %q does not include a storage file share", v) diff --git a/azure/storage/storage_test.go b/azure/storage/storage_test.go deleted file mode 100644 index 3cfa4347..00000000 --- a/azure/storage/storage_test.go +++ /dev/null @@ -1,67 +0,0 @@ -package storage - -import ( - "context" - "fmt" - "net/url" - "testing" - - "github.com/Azure/azure-storage-file-go/azfile" - . "github.com/onsi/gomega" - - "github.com/docker/api/azure" - "github.com/docker/api/context/store" -) - -const ( - resourceGroupName = "rgulyssessouza" - location = "westeurope" - - testAccountName = "dockertestaccountname" - testShareName = "dockertestsharename" - testContent = "test content!" -) - -func TestGetContainerName(t *testing.T) { - RegisterTestingT(t) - - subscriptionID, err := azure.GetSubscriptionID(context.TODO()) - Expect(err).To(BeNil()) - aciContext := store.AciContext{ - SubscriptionID: subscriptionID, - Location: location, - ResourceGroup: resourceGroupName, - } - - storageAccount, err := CreateStorageAccount(context.TODO(), aciContext, testAccountName) - Expect(err).To(BeNil()) - Expect(*storageAccount.Name).To(Equal(testAccountName)) - - list, err := ListKeys(context.TODO(), aciContext, *storageAccount.Name) - Expect(err).To(BeNil()) - - firstKey := *(*list.Keys)[0].Value - - // Create a ShareURL object that wraps a soon-to-be-created share's URL and a default pipeline. - u, _ := url.Parse(fmt.Sprintf("https://%s.file.core.windows.net/%s", testAccountName, testShareName)) - credential, err := azfile.NewSharedKeyCredential(testAccountName, firstKey) - Expect(err).To(BeNil()) - - shareURL := azfile.NewShareURL(*u, azfile.NewPipeline(credential, azfile.PipelineOptions{})) - _, err = shareURL.Create(context.TODO(), azfile.Metadata{}, 0) - Expect(err).To(BeNil()) - - fURL, err := url.Parse(u.String() + "/testfile") - Expect(err).To(BeNil()) - fileURL := azfile.NewFileURL(*fURL, azfile.NewPipeline(credential, azfile.PipelineOptions{})) - err = azfile.UploadBufferToAzureFile(context.TODO(), []byte(testContent), fileURL, azfile.UploadToAzureFileOptions{}) - Expect(err).To(BeNil()) - - b := make([]byte, len(testContent)) - _, err = azfile.DownloadAzureFileToBuffer(context.TODO(), fileURL, b, azfile.DownloadFromAzureFileOptions{}) - Expect(err).To(BeNil()) - Expect(string(b)).To(Equal(testContent)) - - _, err = DeleteStorageAccount(context.TODO(), aciContext, testAccountName) - Expect(err).To(BeNil()) -} diff --git a/tests/aci-e2e/e2e-aci.go b/tests/aci-e2e/e2e-aci.go index 5c59c9f8..cec3edfb 100644 --- a/tests/aci-e2e/e2e-aci.go +++ b/tests/aci-e2e/e2e-aci.go @@ -16,8 +16,8 @@ import ( . "github.com/onsi/gomega" "github.com/docker/api/azure" - "github.com/docker/api/azure/storage" "github.com/docker/api/context/store" + "github.com/docker/api/tests/aci-e2e/storage" . "github.com/docker/api/tests/framework" ) diff --git a/azure/storage/storage.go b/tests/aci-e2e/storage/storage.go similarity index 100% rename from azure/storage/storage.go rename to tests/aci-e2e/storage/storage.go