...
1 package storage
2
3
4
5
6 import (
7 "github.com/Azure/go-autorest/autorest/to"
8 chk "gopkg.in/check.v1"
9 )
10
11 type StorageSuite struct{}
12
13 var _ = chk.Suite(&StorageSuite{})
14
15
16
17 func (s *StorageSuite) TestGetServiceProperties(c *chk.C) {
18 cli := getTableClient(c)
19 rec := cli.client.appendRecorder(c)
20 defer rec.Stop()
21
22 sp, err := cli.GetServiceProperties()
23 c.Assert(err, chk.IsNil)
24 c.Assert(sp, chk.NotNil)
25 }
26
27 func (s *StorageSuite) TestSetServiceProperties(c *chk.C) {
28 cli := getBlobClient(c)
29 rec := cli.client.appendRecorder(c)
30 defer rec.Stop()
31
32 t := true
33 num := 7
34 rp := RetentionPolicy{
35 Enabled: true,
36 Days: &num,
37 }
38 m := Metrics{
39 Version: "1.0",
40 Enabled: true,
41 IncludeAPIs: &t,
42 RetentionPolicy: &rp,
43 }
44 spInput := ServiceProperties{
45 Logging: &Logging{
46 Version: "1.0",
47 Delete: true,
48 Read: false,
49 Write: true,
50 RetentionPolicy: &rp,
51 },
52 HourMetrics: &m,
53 MinuteMetrics: &m,
54 Cors: &Cors{
55 CorsRule: []CorsRule{
56 {
57 AllowedOrigins: "*",
58 AllowedMethods: "GET,PUT",
59 MaxAgeInSeconds: 500,
60 ExposedHeaders: "x-ms-meta-customheader,x-ms-meta-data*",
61 AllowedHeaders: "x-ms-meta-customheader,x-ms-meta-target*",
62 },
63 },
64 },
65 DeleteRetentionPolicy: &RetentionPolicy{
66 Enabled: true,
67 Days: to.IntPtr(5),
68 },
69 StaticWebsite: &StaticWebsite{
70 Enabled: true,
71 IndexDocument: to.StringPtr("index.html"),
72 ErrorDocument404Path: to.StringPtr("error.html"),
73 },
74 }
75
76 err := cli.SetServiceProperties(spInput)
77 c.Assert(err, chk.IsNil)
78
79 spOutput, err := cli.GetServiceProperties()
80 c.Assert(err, chk.IsNil)
81 c.Assert(spOutput, chk.NotNil)
82 c.Assert(*spOutput, chk.DeepEquals, spInput)
83
84
85 defaultRP := RetentionPolicy{
86 Enabled: false,
87 Days: nil,
88 }
89 m.Enabled = false
90 m.IncludeAPIs = nil
91 m.RetentionPolicy = &defaultRP
92 spInput.Logging.Delete = false
93 spInput.Logging.Read = false
94 spInput.Logging.Write = false
95 spInput.Logging.RetentionPolicy = &defaultRP
96 spInput.Cors = &Cors{nil}
97
98 cli.SetServiceProperties(spInput)
99 }
100
View as plain text