Skip to content

Commit

Permalink
add more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Shawn Warren committed Jul 1, 2024
1 parent b48bd34 commit 1ebb54b
Showing 1 changed file with 83 additions and 3 deletions.
86 changes: 83 additions & 3 deletions cloud/services/compute/loadbalancers/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ func TestService_createOrGetRegionalHealthCheck(t *testing.T) {
mockHealthChecks *cloud.MockRegionHealthChecks
want *compute.HealthCheck
wantErr bool
sharedVPC bool
}{
{
name: "regional health check does not exist for internal load balancer (should create healthcheck)",
Expand All @@ -279,11 +280,43 @@ func TestService_createOrGetRegionalHealthCheck(t *testing.T) {
UnhealthyThreshold: 3,
},
},
{
name: "regional health check does not exist for internal load balancer in shared VPC (should create healthcheck)",
scope: func(s *scope.ClusterScope) Scope {
s.GCPCluster.Spec.LoadBalancer = infrav1.LoadBalancerSpec{
LoadBalancerType: &lbTypeInternal,
}
return s
},
lbName: infrav1.InternalRoleTagValue,
mockHealthChecks: &cloud.MockRegionHealthChecks{
ProjectRouter: &cloud.SingleProjectRouter{ID: "proj-id"},
Objects: map[meta.Key]*cloud.MockRegionHealthChecksObj{},
},
want: &compute.HealthCheck{
CheckIntervalSec: 10,
HealthyThreshold: 5,
HttpsHealthCheck: &compute.HTTPSHealthCheck{Port: 6443, PortSpecification: "USE_FIXED_PORT", RequestPath: "/readyz"},
Name: "my-cluster-api-internal",
Region: "us-central1",
SelfLink: "https://www.googleapis.com/compute/v1/projects/proj-id/regions/us-central1/healthChecks/my-cluster-api-internal",
TimeoutSec: 5,
Type: "HTTPS",
UnhealthyThreshold: 3,
},
sharedVPC: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx := context.TODO()
clusterScope, err := getBaseClusterScope()
var err error
var clusterScope *scope.ClusterScope
if tt.sharedVPC {
clusterScope, err = getBaseClusterScopeWithSharedVPC()
} else {
clusterScope, err = getBaseClusterScope()
}
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -461,6 +494,7 @@ func TestService_createOrGetAddress(t *testing.T) {
mockAddress *cloud.MockGlobalAddresses
want *compute.Address
wantErr bool
sharedVPC bool
}{
{
name: "address does not exist for external load balancer (should create address)",
Expand All @@ -477,11 +511,33 @@ func TestService_createOrGetAddress(t *testing.T) {
AddressType: "EXTERNAL",
},
},
{
name: "address does not exist for external load balancer in shared VPC (should create address)",
scope: func(s *scope.ClusterScope) Scope { return s },
lbName: infrav1.APIServerRoleTagValue,
mockAddress: &cloud.MockGlobalAddresses{
ProjectRouter: &cloud.SingleProjectRouter{ID: "proj-id"},
Objects: map[meta.Key]*cloud.MockGlobalAddressesObj{},
},
want: &compute.Address{
IpVersion: "IPV4",
Name: "my-cluster-apiserver",
SelfLink: "https://www.googleapis.com/compute/v1/projects/proj-id/global/addresses/my-cluster-apiserver",
AddressType: "EXTERNAL",
},
sharedVPC: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx := context.TODO()
clusterScope, err := getBaseClusterScope()
var err error
var clusterScope *scope.ClusterScope
if tt.sharedVPC {
clusterScope, err = getBaseClusterScopeWithSharedVPC()
} else {
clusterScope, err = getBaseClusterScope()
}
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -604,6 +660,7 @@ func TestService_createOrGetTargetTCPProxy(t *testing.T) {
mockTargetTCPProxy *cloud.MockTargetTcpProxies
want *compute.TargetTcpProxy
wantErr bool
sharedVPC bool
}{
{
name: "target tcp proxy does not exist for external load balancer (should create target tp proxy)",
Expand All @@ -621,11 +678,34 @@ func TestService_createOrGetTargetTCPProxy(t *testing.T) {
SelfLink: "https://www.googleapis.com/compute/v1/projects/proj-id/global/targetTcpProxies/my-cluster-apiserver",
},
},
{
name: "target tcp proxy does not exist for external load balancer in shared VPC (should create target tp proxy)",
scope: func(s *scope.ClusterScope) Scope { return s },
backendService: &compute.BackendService{
Name: "my-cluster-api-internal",
},
mockTargetTCPProxy: &cloud.MockTargetTcpProxies{
ProjectRouter: &cloud.SingleProjectRouter{ID: "proj-id"},
Objects: map[meta.Key]*cloud.MockTargetTcpProxiesObj{},
},
want: &compute.TargetTcpProxy{
Name: "my-cluster-apiserver",
ProxyHeader: "NONE",
SelfLink: "https://www.googleapis.com/compute/v1/projects/proj-id/global/targetTcpProxies/my-cluster-apiserver",
},
sharedVPC: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx := context.TODO()
clusterScope, err := getBaseClusterScope()
var err error
var clusterScope *scope.ClusterScope
if tt.sharedVPC {
clusterScope, err = getBaseClusterScopeWithSharedVPC()
} else {
clusterScope, err = getBaseClusterScope()
}
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 1ebb54b

Please sign in to comment.