-
Notifications
You must be signed in to change notification settings - Fork 62
/
microsoft_test.go
108 lines (88 loc) · 3.47 KB
/
microsoft_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
100
101
102
103
104
105
106
107
108
/*
Copyright The Helm Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package storage
import (
"fmt"
"os"
"testing"
"github.com/stretchr/testify/suite"
)
type MicrosoftTestSuite struct {
suite.Suite
BrokenAzureBlobBackend *MicrosoftBlobBackend
NoPrefixAzureBlobBackend *MicrosoftBlobBackend
}
func (suite *MicrosoftTestSuite) SetupSuite() {
backend := NewMicrosoftBlobBackend("fake-container-cant-exist-fbce123", "")
suite.BrokenAzureBlobBackend = backend
containerName := os.Getenv("TEST_STORAGE_AZURE_CONTAINER")
backend = NewMicrosoftBlobBackend(containerName, "")
suite.NoPrefixAzureBlobBackend = backend
data := []byte("some object")
path := "deleteme.txt"
err := suite.NoPrefixAzureBlobBackend.PutObject(path, data)
suite.Nil(err, "no error putting deleteme.txt using Azure backend")
}
func (suite *MicrosoftTestSuite) TearDownSuite() {
err := suite.NoPrefixAzureBlobBackend.DeleteObject("deleteme.txt")
suite.Nil(err, "no error deleting deleteme.txt using Azure backend")
}
func (suite *MicrosoftTestSuite) TestListObjects() {
_, err := suite.BrokenAzureBlobBackend.ListObjects("")
suite.NotNil(err, "cannot list objects with bad bucket")
_, err = suite.NoPrefixAzureBlobBackend.ListObjects("")
suite.Nil(err, "can list objects with good bucket, no prefix")
}
func (suite *MicrosoftTestSuite) TestListObjectsWithPaging() {
// create 5001 objects to trigger the need of paging, since
// the default page size for Azure Blobs are 5000.
data := []byte("some object")
for i := 0; i < 5001; i++ {
path := fmt.Sprintf("deleteme-%d.txt", i)
suite.NoPrefixAzureBlobBackend.PutObject(path, data)
}
// check if 5002 (5001 plus deleteme.txt from SetupSuite()) objects
// are returned. Without paging, we would get only 5000.
res, err := suite.NoPrefixAzureBlobBackend.ListObjects("")
suite.Nil(err, "can list objects with good bucket, no prefix")
suite.Equal(5001, len(res))
// clean up
for i := 0; i < 5001; i++ {
path := fmt.Sprintf("deleteme-%d.txt", i)
suite.NoPrefixAzureBlobBackend.DeleteObject(path)
}
}
func (suite *MicrosoftTestSuite) TestGetObject() {
_, err := suite.BrokenAzureBlobBackend.GetObject("this-file-cannot-possibly-exist.tgz")
suite.NotNil(err, "cannot get objects with bad bucket")
}
func (suite *MicrosoftTestSuite) TestPutObject() {
err := suite.BrokenAzureBlobBackend.PutObject("this-file-will-not-upload.txt", []byte{})
suite.NotNil(err, "cannot put objects with bad bucket")
}
func (suite *MicrosoftTestSuite) TestPutObjectGreaterThan4MB() {
data := make([]byte, 2*maxChunkSize)
for i := 0; i < 2*maxChunkSize; i++ {
data[i] = byte(i)
}
err := suite.NoPrefixAzureBlobBackend.PutObject("this-file-created-for-test.txt", data)
suite.Nil(err, "can put objects with good bucket, no prefix")
// clean up
suite.NoPrefixAzureBlobBackend.DeleteObject("this-file-created-for-test.txt")
}
func TestAzureStorageTestSuite(t *testing.T) {
if os.Getenv("TEST_CLOUD_STORAGE") == "1" &&
os.Getenv("TEST_STORAGE_AZURE_CONTAINER") != "" {
suite.Run(t, new(MicrosoftTestSuite))
}
}