1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
package files
import (
"context"
"fmt"
"strings"
"testing"
"github.com/Azure/azure-sdk-for-go/profiles/latest/storage/mgmt/storage"
"github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/shares"
"github.com/tombuildsstuff/giovanni/storage/internal/auth"
"github.com/tombuildsstuff/giovanni/storage/internal/endpoints"
"github.com/tombuildsstuff/giovanni/testhelpers"
)
func TestFilesCopyAndWaitFromURL(t *testing.T) {
client, err := testhelpers.Build(t)
if err != nil {
t.Fatal(err)
}
ctx := context.TODO()
resourceGroup := fmt.Sprintf("acctestrg-%d", testhelpers.RandomInt())
accountName := fmt.Sprintf("acctestsa%s", testhelpers.RandomString())
shareName := fmt.Sprintf("share-%d", testhelpers.RandomInt())
testData, err := client.BuildTestResources(ctx, resourceGroup, accountName, storage.Storage)
if err != nil {
t.Fatal(err)
}
defer client.DestroyTestResources(ctx, resourceGroup, accountName)
storageAuth := auth.NewSharedKeyLiteAuthorizer(accountName, testData.StorageAccountKey)
sharesClient := shares.NewWithEnvironment(client.Environment)
sharesClient.Client = client.PrepareWithAuthorizer(sharesClient.Client, storageAuth)
input := shares.CreateInput{
QuotaInGB: 10,
}
_, err = sharesClient.Create(ctx, accountName, shareName, input)
if err != nil {
t.Fatalf("Error creating fileshare: %s", err)
}
defer sharesClient.Delete(ctx, accountName, shareName, false)
filesClient := NewWithEnvironment(client.Environment)
filesClient.Client = client.PrepareWithAuthorizer(filesClient.Client, storageAuth)
copiedFileName := "ubuntu.iso"
copyInput := CopyInput{
CopySource: "http://releases.ubuntu.com/14.04/ubuntu-14.04.6-desktop-amd64.iso",
}
t.Logf("[DEBUG] Copy And Waiting..")
if _, err := filesClient.CopyAndWait(ctx, accountName, shareName, "", copiedFileName, copyInput, DefaultCopyPollDuration); err != nil {
t.Fatalf("Error copy & waiting: %s", err)
}
t.Logf("[DEBUG] Asserting that the file's ready..")
props, err := filesClient.GetProperties(ctx, accountName, shareName, "", copiedFileName)
if err != nil {
t.Fatalf("Error retrieving file: %s", err)
}
if !strings.EqualFold(props.CopyStatus, "success") {
t.Fatalf("Expected the Copy Status to be `Success` but got %q", props.CopyStatus)
}
}
func TestFilesCopyAndWaitFromBlob(t *testing.T) {
client, err := testhelpers.Build(t)
if err != nil {
t.Fatal(err)
}
ctx := context.TODO()
resourceGroup := fmt.Sprintf("acctestrg-%d", testhelpers.RandomInt())
accountName := fmt.Sprintf("acctestsa%s", testhelpers.RandomString())
shareName := fmt.Sprintf("share-%d", testhelpers.RandomInt())
testData, err := client.BuildTestResources(ctx, resourceGroup, accountName, storage.Storage)
if err != nil {
t.Fatal(err)
}
defer client.DestroyTestResources(ctx, resourceGroup, accountName)
storageAuth := auth.NewSharedKeyLiteAuthorizer(accountName, testData.StorageAccountKey)
sharesClient := shares.NewWithEnvironment(client.Environment)
sharesClient.Client = client.PrepareWithAuthorizer(sharesClient.Client, storageAuth)
input := shares.CreateInput{
QuotaInGB: 10,
}
_, err = sharesClient.Create(ctx, accountName, shareName, input)
if err != nil {
t.Fatalf("Error creating fileshare: %s", err)
}
defer sharesClient.Delete(ctx, accountName, shareName, false)
filesClient := NewWithEnvironment(client.Environment)
filesClient.Client = client.PrepareWithAuthorizer(filesClient.Client, storageAuth)
originalFileName := "ubuntu.iso"
copiedFileName := "ubuntu-copied.iso"
copyInput := CopyInput{
CopySource: "http://releases.ubuntu.com/14.04/ubuntu-14.04.6-desktop-amd64.iso",
}
t.Logf("[DEBUG] Copy And Waiting the original file..")
if _, err := filesClient.CopyAndWait(ctx, accountName, shareName, "", originalFileName, copyInput, DefaultCopyPollDuration); err != nil {
t.Fatalf("Error copy & waiting: %s", err)
}
t.Logf("[DEBUG] Now copying that blob..")
duplicateInput := CopyInput{
CopySource: fmt.Sprintf("%s/%s/%s", endpoints.GetFileEndpoint(filesClient.BaseURI, accountName), shareName, originalFileName),
}
if _, err := filesClient.CopyAndWait(ctx, accountName, shareName, "", copiedFileName, duplicateInput, DefaultCopyPollDuration); err != nil {
t.Fatalf("Error copying duplicate: %s", err)
}
t.Logf("[DEBUG] Asserting that the file's ready..")
props, err := filesClient.GetProperties(ctx, accountName, shareName, "", copiedFileName)
if err != nil {
t.Fatalf("Error retrieving file: %s", err)
}
if !strings.EqualFold(props.CopyStatus, "success") {
t.Fatalf("Expected the Copy Status to be `Success` but got %q", props.CopyStatus)
}
}
|