| 1 |
package filesscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/files`/ |
| 2 |
|
| 3 |
import ( |
| 4 |
"contextscip-go gomod github.com/golang/go/src go1.13 context/" |
| 5 |
"fmtscip-go gomod github.com/golang/go/src go1.13 fmt/" |
| 6 |
"osscip-go gomod github.com/golang/go/src go1.13 os/" |
| 7 |
"testingscip-go gomod github.com/golang/go/src go1.13 testing/" |
| 8 |
|
| 9 |
"github.com/Azure/azure-sdk-for-go/profiles/latest/storage/mgmt/storagescip-go gomod github.com/Azure/azure-sdk-for-go v68.0.0 `github.com/Azure/azure-sdk-for-go/profiles/latest/storage/mgmt/storage`/" |
| 10 |
"github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/sharesscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/shares`/" |
| 11 |
"github.com/tombuildsstuff/giovanni/storage/internal/authscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/" |
| 12 |
"github.com/tombuildsstuff/giovanni/testhelpersscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/" |
| 13 |
) |
| 14 |
|
| 15 |
func TestPutSmallFilescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/files`/TestPutSmallFile().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 16 |
// the purpose of this test is to ensure that a small file (< 4MB) is a single chunk |
| 17 |
testPutFilescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/files`/testPutFile().(t, "small-file.png", "image/png") |
| 18 |
} |
| 19 |
|
| 20 |
func TestPutLargeFilescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/files`/TestPutLargeFile().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 21 |
// the purpose of this test is to ensure that large files (> 4MB) are chunked |
| 22 |
testPutFilescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/files`/testPutFile().(t, "blank-large-file.dmg", "application/x-apple-diskimage") |
| 23 |
} |
| 24 |
|
| 25 |
func TestPutVerySmallFilescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/files`/TestPutVerySmallFile().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 26 |
// the purpose of this test is to ensure that a very small file (< 4KB) is a single chunk |
| 27 |
testPutFilescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/files`/testPutFile().(t, "very-small.json", "application/json") |
| 28 |
} |
| 29 |
|
| 30 |
func testPutFilescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/files`/testPutFile().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#, fileName string, contentType string) { |
| 31 |
client, err := testhelpersscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/.Buildscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/Build().(t) |
| 32 |
if err != nil { |
| 33 |
t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().(err) |
| 34 |
} |
| 35 |
ctx := contextscip-go gomod github.com/golang/go/src go1.13 context/.TODOscip-go gomod github.com/golang/go/src go1.13 context/TODO().() |
| 36 |
resourceGroup := fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("acctestrg-%d", testhelpersscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/.RandomIntscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/RandomInt().()) |
| 37 |
accountName := fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("acctestsa%s", testhelpersscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/.RandomStringscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/RandomString().()) |
| 38 |
shareName := fmtscip-go gomod github.com/golang/go/src go1.13 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.13 fmt/Sprintf().("share-%d", testhelpersscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/.RandomIntscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/RandomInt().()) |
| 39 |
|
| •40 |
testData, err := client.BuildTestResourcesscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/Client#BuildTestResources().(ctx, resourceGroup, accountName, storagescip-go gomod github.com/Azure/azure-sdk-for-go v68.0.0 `github.com/Azure/azure-sdk-for-go/profiles/latest/storage/mgmt/storage`/.Storagescip-go gomod github.com/Azure/azure-sdk-for-go v68.0.0 `github.com/Azure/azure-sdk-for-go/profiles/latest/storage/mgmt/storage`/Storage.) |
| 41 |
if err != nil { |
| 42 |
t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().(err) |
| 43 |
} |
| 44 |
defer client.DestroyTestResourcesscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/Client#DestroyTestResources().(ctx, resourceGroup, accountName) |
| 45 |
|
| 46 |
storageAuth := authscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/.NewSharedKeyLiteAuthorizerscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/internal/auth`/NewSharedKeyLiteAuthorizer().(accountName, testData.StorageAccountKeyscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/TestResources#StorageAccountKey.) |
| 47 |
sharesClient := sharesscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/shares`/.NewWithEnvironmentscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/shares`/NewWithEnvironment().(client.Environmentscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/Client#Environment.) |
| 48 |
sharesClient.Clientscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/shares`/Client#Client. = client.PrepareWithAuthorizerscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/Client#PrepareWithAuthorizer().(sharesClient.Clientscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/shares`/Client#Client., storageAuth) |
| 49 |
|
| 50 |
input := sharesscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/shares`/.CreateInputscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/shares`/CreateInput#{ |
| 51 |
QuotaInGBscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/shares`/CreateInput#QuotaInGB.: 10, |
| 52 |
} |
| 53 |
_, err = sharesClient.Createscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/shares`/Client#Create().(ctx, accountName, shareName, input) |
| 54 |
if err != nil { |
| 55 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Error creating fileshare: %s", err) |
| 56 |
} |
| 57 |
defer sharesClient.Deletescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/shares`/Client#Delete().(ctx, accountName, shareName, false) |
| 58 |
|
| 59 |
filesClient := NewWithEnvironmentscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/files`/NewWithEnvironment().(client.Environmentscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/Client#Environment.) |
| 60 |
filesClient.Clientscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/files`/Client#Client. = client.PrepareWithAuthorizerscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/testhelpers`/Client#PrepareWithAuthorizer().(filesClient.Clientscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/files`/Client#Client., storageAuth) |
| 61 |
|
| 62 |
// store files outside of this directory, since they're reused |
| 63 |
file, err := osscip-go gomod github.com/golang/go/src go1.13 os/.Openscip-go gomod github.com/golang/go/src go1.13 os/Open().("../../../testdata/" + fileName) |
| 64 |
if err != nil { |
| 65 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Error opening: %s", err) |
| 66 |
} |
| 67 |
|
| 68 |
info, err := file.Statscip-go gomod github.com/golang/go/src go1.13 os/File#Stat().() |
| 69 |
if err != nil { |
| 70 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Error 'stat'-ing: %s", err) |
| 71 |
} |
| 72 |
|
| 73 |
t.Logfscip-go gomod github.com/golang/go/src go1.13 testing/common#Logf().("[DEBUG] Creating Top Level File..") |
| 74 |
createFileInput := CreateInputscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/files`/CreateInput#{ |
| 75 |
ContentLengthscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/files`/CreateInput#ContentLength.: info.Sizescip-go gomod github.com/golang/go/src go1.13 `io/fs`/FileInfo#Size().(), |
| 76 |
ContentTypescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/files`/CreateInput#ContentType.: &contentType, |
| 77 |
} |
| 78 |
if _, err := filesClient.Createscip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/files`/Client#Create().(ctx, accountName, shareName, "", fileName, createFileInput); err != nil { |
| 79 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Error creating Top-Level File: %s", err) |
| 80 |
} |
| 81 |
|
| 82 |
t.Logfscip-go gomod github.com/golang/go/src go1.13 testing/common#Logf().("[DEBUG] Uploading File..") |
| 83 |
if err := filesClient.PutFilescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/files`/Client#PutFile().(ctx, accountName, shareName, "", fileName, file, 4); err != nil { |
| 84 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Error uploading File: %s", err) |
| 85 |
} |
| 86 |
|
| 87 |
t.Logfscip-go gomod github.com/golang/go/src go1.13 testing/common#Logf().("[DEBUG] Deleting Top Level File..") |
| 88 |
if _, err := filesClient.Deletescip-go gomod github.com/tombuildsstuff/giovanni . `github.com/tombuildsstuff/giovanni/storage/2020-08-04/file/files`/Client#Delete().(ctx, accountName, shareName, "", fileName); err != nil { |
| 89 |
t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Error deleting Top-Level File: %s", err) |
| 90 |
} |
| 91 |
} |