-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathlifecycle_test.go
99 lines (85 loc) · 3.13 KB
/
lifecycle_test.go
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
package filesystems
import (
"context"
"fmt"
"testing"
"time"
"github.com/hashicorp/go-azure-sdk/resource-manager/storage/2023-01-01/storageaccounts"
"github.com/hashicorp/go-azure-sdk/sdk/auth"
"github.com/tombuildsstuff/giovanni/storage/internal/testhelpers"
)
func TestLifecycle(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Hour)
defer cancel()
client, err := testhelpers.Build(ctx, t)
if err != nil {
t.Fatal(err)
}
resourceGroup := fmt.Sprintf("acctestrg-%d", testhelpers.RandomInt())
accountName := fmt.Sprintf("acctestsa%s", testhelpers.RandomString())
fileSystemName := fmt.Sprintf("acctestfs-%s", testhelpers.RandomString())
testData, err := client.BuildTestResources(ctx, resourceGroup, accountName, storageaccounts.KindBlobStorage)
if err != nil {
t.Fatal(err)
}
defer client.DestroyTestResources(ctx, resourceGroup, accountName)
domainSuffix, ok := client.Environment.Storage.DomainSuffix()
if !ok {
t.Fatalf("storage didn't return a domain suffix for this environment")
}
fileSystemsClient, err := NewWithBaseUri(fmt.Sprintf("https://%s.%s.%s", accountName, "dfs", *domainSuffix))
if err != nil {
t.Fatalf("building client for environment: %+v", err)
}
if err := client.PrepareWithSharedKeyAuth(fileSystemsClient.Client, testData, auth.SharedKey); err != nil {
t.Fatalf("adding authorizer to client: %+v", err)
}
t.Logf("[DEBUG] Creating an empty File System..")
input := CreateInput{
Properties: map[string]string{
"hello": "aGVsbG8=",
},
}
if _, err = fileSystemsClient.Create(ctx, fileSystemName, input); err != nil {
t.Fatal(fmt.Errorf("Error creating: %s", err))
}
t.Logf("[DEBUG] Retrieving the Properties..")
props, err := fileSystemsClient.GetProperties(ctx, fileSystemName)
if err != nil {
t.Fatal(fmt.Errorf("Error getting properties: %s", err))
}
if len(props.Properties) != 1 {
t.Fatalf("Expected 1 properties by default but got %d", len(props.Properties))
}
if props.Properties["hello"] != "aGVsbG8=" {
t.Fatalf("Expected `hello` to be `aGVsbG8=` but got %q", props.Properties["hello"])
}
t.Logf("[DEBUG] Updating the properties..")
setInput := SetPropertiesInput{
Properties: map[string]string{
"hello": "d29uZGVybGFuZA==",
"private": "ZXll",
},
}
if _, err := fileSystemsClient.SetProperties(ctx, fileSystemName, setInput); err != nil {
t.Fatalf("Error setting properties: %s", err)
}
t.Logf("[DEBUG] Re-Retrieving the Properties..")
props, err = fileSystemsClient.GetProperties(ctx, fileSystemName)
if err != nil {
t.Fatal(fmt.Errorf("Error getting properties: %s", err))
}
if len(props.Properties) != 2 {
t.Fatalf("Expected 2 properties by default but got %d", len(props.Properties))
}
if props.Properties["hello"] != "d29uZGVybGFuZA==" {
t.Fatalf("Expected `hello` to be `d29uZGVybGFuZA==` but got %q", props.Properties["hello"])
}
if props.Properties["private"] != "ZXll" {
t.Fatalf("Expected `private` to be `ZXll` but got %q", props.Properties["private"])
}
t.Logf("[DEBUG] Deleting File System..")
if _, err := fileSystemsClient.Delete(ctx, fileSystemName); err != nil {
t.Fatalf("Error deleting: %s", err)
}
}