forked from Azure/azure-service-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblobcontainer_controller_test.go
109 lines (90 loc) · 3.12 KB
/
blobcontainer_controller_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
109
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
//go:build all || blobcontainer
// +build all blobcontainer
package controllers
import (
"context"
"testing"
s "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-04-01/storage"
"github.com/Azure/go-autorest/autorest/to"
"github.com/Azure/azure-service-operator/api/v1alpha1"
"github.com/Azure/azure-service-operator/api/v1alpha2"
"github.com/Azure/azure-service-operator/pkg/errhelp"
helpers "github.com/Azure/azure-service-operator/pkg/helpers"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestBlobContainerControlleNoResourceGroup(t *testing.T) {
t.Parallel()
defer PanicRecover(t)
ctx := context.Background()
var rgLocation string
var saName string
var containerAccessLevel s.PublicAccess
// Add any setup steps that needs to be executed before each test
rgLocation = tc.resourceGroupLocation
saName = GenerateAlphaNumTestResourceName("blobsa")
containerAccessLevel = s.PublicAccessContainer
blobContainerName := GenerateTestResourceNameWithRandom("bc", 10)
resourceGroupName := GenerateTestResourceNameWithRandom("rg", 10)
// Create Storage account
saInstance := &v1alpha1.StorageAccount{
ObjectMeta: metav1.ObjectMeta{
Name: saName,
Namespace: "default",
},
Spec: v1alpha1.StorageAccountSpec{
Location: tc.resourceGroupLocation,
ResourceGroup: tc.resourceGroupName,
Sku: v1alpha1.StorageAccountSku{
Name: "Standard_RAGRS",
},
Kind: "StorageV2",
AccessTier: "Hot",
EnableHTTPSTrafficOnly: to.BoolPtr(true),
},
}
EnsureInstance(ctx, t, tc, saInstance)
blobContainerInstance := &v1alpha2.BlobContainer{
ObjectMeta: metav1.ObjectMeta{
Name: blobContainerName,
Namespace: "default",
},
Spec: v1alpha2.BlobContainerSpec{
Location: rgLocation,
ResourceGroup: resourceGroupName,
AccountName: saName,
AccessLevel: containerAccessLevel,
},
}
EnsureInstanceWithResult(ctx, t, tc, blobContainerInstance, errhelp.ResourceGroupNotFoundErrorCode, false)
EnsureDelete(ctx, t, tc, blobContainerInstance)
}
func TestTestBlobContainerControllerNoStorageAccount(t *testing.T) {
t.Parallel()
defer PanicRecover(t)
ctx := context.Background()
var rgLocation string
var rgName string
var containerAccessLevel s.PublicAccess
// Add any setup steps that needs to be executed before each test
rgLocation = tc.resourceGroupLocation
rgName = tc.resourceGroupName
containerAccessLevel = s.PublicAccessContainer
blobContainerName := GenerateTestResourceNameWithRandom("bc", 10)
storageAccountName := helpers.FillWithRandom(GenerateAlphaNumTestResourceName("sa"), 24)
blobContainerInstance := &v1alpha2.BlobContainer{
ObjectMeta: metav1.ObjectMeta{
Name: blobContainerName,
Namespace: "default",
},
Spec: v1alpha2.BlobContainerSpec{
Location: rgLocation,
ResourceGroup: rgName,
AccountName: storageAccountName,
AccessLevel: containerAccessLevel,
},
}
EnsureInstanceWithResult(ctx, t, tc, blobContainerInstance, errhelp.ParentNotFoundErrorCode, false)
EnsureDelete(ctx, t, tc, blobContainerInstance)
}