File: storageservice_test.go

package info (click to toggle)
golang-github-azure-azure-sdk-for-go 68.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 556,256 kB
  • sloc: javascript: 196; sh: 96; makefile: 7
file content (99 lines) | stat: -rw-r--r-- 2,336 bytes parent folder | download
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 storage

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

import (
	"github.com/Azure/go-autorest/autorest/to"
	chk "gopkg.in/check.v1"
)

type StorageSuite struct{}

var _ = chk.Suite(&StorageSuite{})

// This tests use the Table service, but could also use any other service

func (s *StorageSuite) TestGetServiceProperties(c *chk.C) {
	cli := getTableClient(c)
	rec := cli.client.appendRecorder(c)
	defer rec.Stop()

	sp, err := cli.GetServiceProperties()
	c.Assert(err, chk.IsNil)
	c.Assert(sp, chk.NotNil)
}

func (s *StorageSuite) TestSetServiceProperties(c *chk.C) {
	cli := getBlobClient(c)
	rec := cli.client.appendRecorder(c)
	defer rec.Stop()

	t := true
	num := 7
	rp := RetentionPolicy{
		Enabled: true,
		Days:    &num,
	}
	m := Metrics{
		Version:         "1.0",
		Enabled:         true,
		IncludeAPIs:     &t,
		RetentionPolicy: &rp,
	}
	spInput := ServiceProperties{
		Logging: &Logging{
			Version:         "1.0",
			Delete:          true,
			Read:            false,
			Write:           true,
			RetentionPolicy: &rp,
		},
		HourMetrics:   &m,
		MinuteMetrics: &m,
		Cors: &Cors{
			CorsRule: []CorsRule{
				{
					AllowedOrigins:  "*",
					AllowedMethods:  "GET,PUT",
					MaxAgeInSeconds: 500,
					ExposedHeaders:  "x-ms-meta-customheader,x-ms-meta-data*",
					AllowedHeaders:  "x-ms-meta-customheader,x-ms-meta-target*",
				},
			},
		},
		DeleteRetentionPolicy: &RetentionPolicy{
			Enabled: true,
			Days:    to.IntPtr(5),
		},
		StaticWebsite: &StaticWebsite{
			Enabled:              true,
			IndexDocument:        to.StringPtr("index.html"),
			ErrorDocument404Path: to.StringPtr("error.html"),
		},
	}

	err := cli.SetServiceProperties(spInput)
	c.Assert(err, chk.IsNil)

	spOutput, err := cli.GetServiceProperties()
	c.Assert(err, chk.IsNil)
	c.Assert(spOutput, chk.NotNil)
	c.Assert(*spOutput, chk.DeepEquals, spInput)

	// Back to defaults
	defaultRP := RetentionPolicy{
		Enabled: false,
		Days:    nil,
	}
	m.Enabled = false
	m.IncludeAPIs = nil
	m.RetentionPolicy = &defaultRP
	spInput.Logging.Delete = false
	spInput.Logging.Read = false
	spInput.Logging.Write = false
	spInput.Logging.RetentionPolicy = &defaultRP
	spInput.Cors = &Cors{nil}

	cli.SetServiceProperties(spInput)
}