forked from Azure/azure-service-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazureloadbalancer_controller_test.go
173 lines (149 loc) · 4.88 KB
/
azureloadbalancer_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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
//go:build all || azureloadbalancer
// +build all azureloadbalancer
package controllers
import (
"context"
"testing"
azurev1alpha1 "github.com/Azure/azure-service-operator/api/v1alpha1"
"github.com/Azure/azure-service-operator/pkg/errhelp"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestLoadBalancerNonExistingSubResources(t *testing.T) {
t.Parallel()
defer PanicRecover(t)
ctx := context.Background()
lbName := GenerateTestResourceNameWithRandom("lb", 10)
pipName := GenerateTestResourceNameWithRandom("pip", 10)
bpName := "test"
natName := "test"
portRangeStart := 100
portRangeEnd := 200
backendPort := 300
// Create an LB instance
lbInstance := &azurev1alpha1.AzureLoadBalancer{
ObjectMeta: metav1.ObjectMeta{
Name: lbName,
Namespace: "default",
},
Spec: azurev1alpha1.AzureLoadBalancerSpec{
Location: tc.resourceGroupLocation,
ResourceGroup: tc.resourceGroupName,
PublicIPAddressName: pipName,
BackendAddressPoolName: bpName,
InboundNatPoolName: natName,
FrontendPortRangeStart: portRangeStart,
FrontendPortRangeEnd: portRangeEnd,
BackendPort: backendPort,
},
}
EnsureInstanceWithResult(ctx, t, tc, lbInstance, errhelp.InvalidResourceReference, false)
EnsureDelete(ctx, t, tc, lbInstance)
}
func TestLaodBalancerHappyPathWithPublicIPAddress(t *testing.T) {
t.Parallel()
defer PanicRecover(t)
ctx := context.Background()
// Create a Public IP Address
pipName := GenerateTestResourceNameWithRandom("lb-pip1", 10)
publicIPAllocationMethod := "Static"
idleTimeoutInMinutes := 10
publicIPAddressVersion := "IPv4"
skuName := "Basic"
pipInstance := &azurev1alpha1.AzurePublicIPAddress{
ObjectMeta: metav1.ObjectMeta{
Name: pipName,
Namespace: "default",
},
Spec: azurev1alpha1.AzurePublicIPAddressSpec{
Location: tc.resourceGroupLocation,
ResourceGroup: tc.resourceGroupName,
PublicIPAllocationMethod: publicIPAllocationMethod,
IdleTimeoutInMinutes: idleTimeoutInMinutes,
PublicIPAddressVersion: publicIPAddressVersion,
SkuName: skuName,
},
}
EnsureInstance(ctx, t, tc, pipInstance)
// Create a Load Balancer
lbName := GenerateTestResourceNameWithRandom("lb1", 10)
bpName := "test"
natName := "test"
portRangeStart := 100
portRangeEnd := 200
backendPort := 300
lbInstance := &azurev1alpha1.AzureLoadBalancer{
ObjectMeta: metav1.ObjectMeta{
Name: lbName,
Namespace: "default",
},
Spec: azurev1alpha1.AzureLoadBalancerSpec{
Location: tc.resourceGroupLocation,
ResourceGroup: tc.resourceGroupName,
PublicIPAddressName: pipName,
BackendAddressPoolName: bpName,
InboundNatPoolName: natName,
FrontendPortRangeStart: portRangeStart,
FrontendPortRangeEnd: portRangeEnd,
BackendPort: backendPort,
},
}
EnsureInstance(ctx, t, tc, lbInstance)
EnsureDelete(ctx, t, tc, lbInstance)
EnsureDelete(ctx, t, tc, pipInstance)
}
func TestLoadBalancerControllerNoResourceGroup(t *testing.T) {
t.Parallel()
defer PanicRecover(t)
ctx := context.Background()
// Add any setup steps that needs to be executed before each test
rgName := GenerateTestResourceNameWithRandom("lb-rand-rg", 10)
// Create a Public IP Address
pipName := GenerateTestResourceNameWithRandom("lb-pip2", 10)
publicIPAllocationMethod := "Static"
idleTimeoutInMinutes := 10
publicIPAddressVersion := "IPv4"
skuName := "Basic"
pipInstance := &azurev1alpha1.AzurePublicIPAddress{
ObjectMeta: metav1.ObjectMeta{
Name: pipName,
Namespace: "default",
},
Spec: azurev1alpha1.AzurePublicIPAddressSpec{
Location: tc.resourceGroupLocation,
ResourceGroup: tc.resourceGroupName,
PublicIPAllocationMethod: publicIPAllocationMethod,
IdleTimeoutInMinutes: idleTimeoutInMinutes,
PublicIPAddressVersion: publicIPAddressVersion,
SkuName: skuName,
},
}
EnsureInstance(ctx, t, tc, pipInstance)
// Create a Load Balancer
lbName := GenerateTestResourceNameWithRandom("lb2", 10)
bpName := "test"
natName := "test"
portRangeStart := 100
portRangeEnd := 200
backendPort := 300
lbInstance := &azurev1alpha1.AzureLoadBalancer{
ObjectMeta: metav1.ObjectMeta{
Name: lbName,
Namespace: "default",
},
Spec: azurev1alpha1.AzureLoadBalancerSpec{
Location: tc.resourceGroupLocation,
ResourceGroup: rgName,
PublicIPAddressName: pipName,
BackendAddressPoolName: bpName,
InboundNatPoolName: natName,
FrontendPortRangeStart: portRangeStart,
FrontendPortRangeEnd: portRangeEnd,
BackendPort: backendPort,
},
}
EnsureInstanceWithResult(ctx, t, tc, lbInstance, errhelp.ResourceGroupNotFoundErrorCode, false)
EnsureDelete(ctx, t, tc, lbInstance)
EnsureDelete(ctx, t, tc, pipInstance)
}