Skip to content

Commit bb6f0bf

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request kubernetes#61300 from grayluck/gce-lb-test
Automatic merge from submit-queue (batch tested with PRs 60499, 61715, 61688, 61300, 58787). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Unit tests for external load balancer **What this PR does / why we need it**: Unit test for external load balancer. Increase the code coverage of gce_loadbalancer_external.go from 61.6% to 76.5%. <!-- **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes # **Special notes for your reviewer**: --> **Release note**: ```release-note NONE ```
2 parents 82d6e2c + af5a7e2 commit bb6f0bf

File tree

4 files changed

+540
-7
lines changed

4 files changed

+540
-7
lines changed

pkg/cloudprovider/providers/gce/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ go_test(
115115
"//pkg/cloudprovider/providers/gce/cloud/meta:go_default_library",
116116
"//pkg/cloudprovider/providers/gce/cloud/mock:go_default_library",
117117
"//pkg/kubelet/apis:go_default_library",
118+
"//pkg/util/net/sets:go_default_library",
118119
"//vendor/github.com/stretchr/testify/assert:go_default_library",
119120
"//vendor/github.com/stretchr/testify/require:go_default_library",
120121
"//vendor/golang.org/x/oauth2/google:go_default_library",
@@ -126,6 +127,7 @@ go_test(
126127
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
127128
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
128129
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
130+
"//vendor/k8s.io/client-go/tools/record:go_default_library",
129131
],
130132
)
131133

pkg/cloudprovider/providers/gce/cloud/mock/mock.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,28 @@ func UpdateRegionBackendServiceHook(ctx context.Context, key *meta.Key, obj *ga.
408408
m.Objects[*key] = &cloud.MockRegionBackendServicesObj{Obj: obj}
409409
return nil
410410
}
411+
412+
// InsertFirewallsUnauthorizedErrHook mocks firewall insertion. A forbidden error will be thrown as return.
413+
func InsertFirewallsUnauthorizedErrHook(ctx context.Context, key *meta.Key, obj *ga.Firewall, m *cloud.MockFirewalls) (bool, error) {
414+
return true, &googleapi.Error{Code: http.StatusForbidden}
415+
}
416+
417+
// UpdateFirewallsUnauthorizedErrHook mocks firewall updating. A forbidden error will be thrown as return.
418+
func UpdateFirewallsUnauthorizedErrHook(ctx context.Context, key *meta.Key, obj *ga.Firewall, m *cloud.MockFirewalls) error {
419+
return &googleapi.Error{Code: http.StatusForbidden}
420+
}
421+
422+
// DeleteFirewallsUnauthorizedErrHook mocks firewall deletion. A forbidden error will be thrown as return.
423+
func DeleteFirewallsUnauthorizedErrHook(ctx context.Context, key *meta.Key, m *cloud.MockFirewalls) (bool, error) {
424+
return true, &googleapi.Error{Code: http.StatusForbidden}
425+
}
426+
427+
// GetFirewallsUnauthorizedErrHook mocks firewall information retrival. A forbidden error will be thrown as return.
428+
func GetFirewallsUnauthorizedErrHook(ctx context.Context, key *meta.Key, m *cloud.MockFirewalls) (bool, *ga.Firewall, error) {
429+
return true, nil, &googleapi.Error{Code: http.StatusForbidden}
430+
}
431+
432+
// GetTargetPoolInternalErrHook mocks getting target pool. It returns a internal server error.
433+
func GetTargetPoolInternalErrHook(ctx context.Context, key *meta.Key, m *cloud.MockTargetPools) (bool, *ga.TargetPool, error) {
434+
return true, nil, &googleapi.Error{Code: http.StatusInternalServerError}
435+
}

0 commit comments

Comments
 (0)