Debian Codegraph @

storage/2019-12-12/file/files/range_put_file_test.go

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 package files
2
3 import (
4 "context"
5 "fmt"
6 "os"
7 "testing"
8
9 "github.com/Azure/azure-sdk-for-go/profiles/latest/storage/mgmt/storage"
10 "github.com/tombuildsstuff/giovanni/storage/2019-12-12/file/shares"
11 "github.com/tombuildsstuff/giovanni/storage/internal/auth"
12 "github.com/tombuildsstuff/giovanni/testhelpers"
13 )
14
15 func TestPutSmallFile(t *testing.T) {
16 // the purpose of this test is to ensure that a small file (< 4MB) is a single chunk
17 testPutFile(t, "small-file.png", "image/png")
18 }
19
20 func TestPutLargeFile(t *testing.T) {
21 // the purpose of this test is to ensure that large files (> 4MB) are chunked
22 testPutFile(t, "blank-large-file.dmg", "application/x-apple-diskimage")
23 }
24
25 func TestPutVerySmallFile(t *testing.T) {
26 // the purpose of this test is to ensure that a very small file (< 4KB) is a single chunk
27 testPutFile(t, "very-small.json", "application/json")
28 }
29
30 func testPutFile(t *testing.T, fileName string, contentType string) {
31 client, err := testhelpers.Build(t)
32 if err != nil {
33 t.Fatal(err)
34 }
35 ctx := context.TODO()
36 resourceGroup := fmt.Sprintf("acctestrg-%d", testhelpers.RandomInt())
37 accountName := fmt.Sprintf("acctestsa%s", testhelpers.RandomString())
38 shareName := fmt.Sprintf("share-%d", testhelpers.RandomInt())
39
•40 testData, err := client.BuildTestResources(ctx, resourceGroup, accountName, storage.Storage)
41 if err != nil {
42 t.Fatal(err)
43 }
44 defer client.DestroyTestResources(ctx, resourceGroup, accountName)
45
46 storageAuth := auth.NewSharedKeyLiteAuthorizer(accountName, testData.StorageAccountKey)
47 sharesClient := shares.NewWithEnvironment(client.Environment)
48 sharesClient.Client = client.PrepareWithAuthorizer(sharesClient.Client, storageAuth)
49
50 input := shares.CreateInput{
51 QuotaInGB: 10,
52 }
53 _, err = sharesClient.Create(ctx, accountName, shareName, input)
54 if err != nil {
55 t.Fatalf("Error creating fileshare: %s", err)
56 }
57 defer sharesClient.Delete(ctx, accountName, shareName, false)
58
59 filesClient := NewWithEnvironment(client.Environment)
60 filesClient.Client = client.PrepareWithAuthorizer(filesClient.Client, storageAuth)
61
62 // store files outside of this directory, since they're reused
63 file, err := os.Open("../../../testdata/" + fileName)
64 if err != nil {
65 t.Fatalf("Error opening: %s", err)
66 }
67
68 info, err := file.Stat()
69 if err != nil {
70 t.Fatalf("Error 'stat'-ing: %s", err)
71 }
72
73 t.Logf("[DEBUG] Creating Top Level File..")
74 createFileInput := CreateInput{
75 ContentLength: info.Size(),
76 ContentType: &contentType,
77 }
78 if _, err := filesClient.Create(ctx, accountName, shareName, "", fileName, createFileInput); err != nil {
79 t.Fatalf("Error creating Top-Level File: %s", err)
80 }
81
82 t.Logf("[DEBUG] Uploading File..")
83 if err := filesClient.PutFile(ctx, accountName, shareName, "", fileName, file, 4); err != nil {
84 t.Fatalf("Error uploading File: %s", err)
85 }
86
87 t.Logf("[DEBUG] Deleting Top Level File..")
88 if _, err := filesClient.Delete(ctx, accountName, shareName, "", fileName); err != nil {
89 t.Fatalf("Error deleting Top-Level File: %s", err)
90 }
91 }