Debian Codegraph @

storage/2020-08-04/blob/accounts/set_service_properties_test.go

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 package accounts
2
3 import (
4 "context"
5 "fmt"
6 "testing"
7 "time"
8
9 "github.com/Azure/azure-sdk-for-go/profiles/latest/storage/mgmt/storage"
10 "github.com/tombuildsstuff/giovanni/testhelpers"
11 )
12
13 func TestContainerLifecycle(t *testing.T) {
14 client, err := testhelpers.Build(t)
15 if err != nil {
16 t.Fatal(err)
17 }
18 ctx := context.TODO()
19
20 resourceGroup := fmt.Sprintf("acctestrg-%d", testhelpers.RandomInt())
21 accountName := fmt.Sprintf("acctestsa%s", testhelpers.RandomString())
22
•23 _, err = client.BuildTestResources(ctx, resourceGroup, accountName, storage.StorageV2)
24 if err != nil {
25 t.Fatal(err)
26 }
27 defer client.DestroyTestResources(ctx, resourceGroup, accountName)
28
29 accountsClient := NewWithEnvironment(client.Environment)
30 accountsClient.Client = client.PrepareWithStorageResourceManagerAuth(accountsClient.Client)
31
32 input := StorageServiceProperties{}
33 _, err = accountsClient.SetServiceProperties(ctx, accountName, input)
34 if err != nil {
35 t.Fatal(fmt.Errorf("error setting properties: %s", err))
36 }
37
38 var index = "index.html"
39 //var enabled = true
40 var errorDocument = "404.html"
41
42 input = StorageServiceProperties{
43 StaticWebsite: &StaticWebsite{
44 Enabled: true,
45 IndexDocument: index,
46 ErrorDocument404Path: errorDocument,
47 },
48 Logging: &Logging{
49 Version: "2.0",
50 Delete: true,
51 Read: true,
52 Write: true,
53 RetentionPolicy: DeleteRetentionPolicy{
54 Enabled: true,
55 Days: 7,
56 },
57 },
58 }
59
60 _, err = accountsClient.SetServiceProperties(ctx, accountName, input)
61 if err != nil {
62 t.Fatal(fmt.Errorf("error setting properties: %s", err))
63 }
64
65 t.Log("[DEBUG] Waiting 2 seconds..")
66 time.Sleep(2 * time.Second)
67
68 result, err := accountsClient.GetServiceProperties(ctx, accountName)
69 if err != nil {
70 t.Fatal(fmt.Errorf("error getting properties: %s", err))
71 }
72
73 website := result.StorageServiceProperties.StaticWebsite
74 if website.Enabled != true {
75 t.Fatalf("Expected the StaticWebsite %t but got %t", true, website.Enabled)
76 }
77
78 logging := result.StorageServiceProperties.Logging
79 if logging.Version != "2.0" {
80 t.Fatalf("Expected the Logging Version %s but got %s", "2.0", logging.Version)
81 }
82 if !logging.Read {
83 t.Fatalf("Expected the Logging Read %t but got %t", true, logging.Read)
84 }
85 if !logging.Write {
86 t.Fatalf("Expected the Logging Write %t but got %t", true, logging.Write)
87 }
88 if !logging.Delete {
89 t.Fatalf("Expected the Logging Delete %t but got %t", true, logging.Delete)
90 }
91 if !logging.RetentionPolicy.Enabled {
92 t.Fatalf("Expected the Logging RetentionPolicy.Enabled %t but got %t", true, logging.RetentionPolicy.Enabled)
93 }
94 if logging.RetentionPolicy.Days != 7 {
95 t.Fatalf("Expected the Logging RetentionPolicy.Enabled %d but got %d", 7, logging.RetentionPolicy.Days)
96 }
97 }