|
9 | 9 | . "github.com/onsi/gomega"
|
10 | 10 | "github.com/oracle/oci-go-sdk/v65/common"
|
11 | 11 | ociloadbalancer "github.com/oracle/oci-go-sdk/v65/loadbalancer"
|
| 12 | + "github.com/oracle/oci-native-ingress-controller/pkg/exception" |
12 | 13 |
|
13 | 14 | "github.com/oracle/oci-go-sdk/v65/waf"
|
14 | 15 | "github.com/oracle/oci-native-ingress-controller/pkg/client"
|
@@ -38,6 +39,42 @@ func TestEnsureLoadBalancer(t *testing.T) {
|
38 | 39 | Expect(err).Should(BeNil())
|
39 | 40 | }
|
40 | 41 |
|
| 42 | +func TestEnsureLoadBalancerWithLbIdSet(t *testing.T) { |
| 43 | + RegisterTestingT(t) |
| 44 | + ctx := context.TODO() |
| 45 | + |
| 46 | + ingressClassList := util.GetIngressClassListWithLBSet("id") |
| 47 | + c := inits(ctx, ingressClassList) |
| 48 | + |
| 49 | + err := c.ensureLoadBalancer(&ingressClassList.Items[0]) |
| 50 | + Expect(err).Should(BeNil()) |
| 51 | +} |
| 52 | + |
| 53 | +func TestEnsureLoadBalancerWithNotFound(t *testing.T) { |
| 54 | + RegisterTestingT(t) |
| 55 | + ctx := context.TODO() |
| 56 | + |
| 57 | + ingressClassList := util.GetIngressClassListWithLBSet("notfound") |
| 58 | + c := inits(ctx, ingressClassList) |
| 59 | + |
| 60 | + ic := &ingressClassList.Items[0] |
| 61 | + err := c.ensureLoadBalancer(ic) |
| 62 | + Expect(err).Should(BeNil()) |
| 63 | + |
| 64 | +} |
| 65 | + |
| 66 | +func TestEnsureLoadBalancerWithNetworkError(t *testing.T) { |
| 67 | + RegisterTestingT(t) |
| 68 | + ctx := context.TODO() |
| 69 | + |
| 70 | + ingressClassList := util.GetIngressClassListWithLBSet("networkerror") |
| 71 | + c := inits(ctx, ingressClassList) |
| 72 | + |
| 73 | + err := c.ensureLoadBalancer(&ingressClassList.Items[0]) |
| 74 | + Expect(err).Should(Not(BeNil())) |
| 75 | + Expect(err.Error()).Should(Equal("Failure due to network error")) |
| 76 | +} |
| 77 | + |
41 | 78 | func TestIngressClassAdd(t *testing.T) {
|
42 | 79 | RegisterTestingT(t)
|
43 | 80 | ctx, cancel := context.WithCancel(context.Background())
|
@@ -245,10 +282,24 @@ type MockLoadBalancerClient struct {
|
245 | 282 | }
|
246 | 283 |
|
247 | 284 | func (m MockLoadBalancerClient) GetLoadBalancer(ctx context.Context, request ociloadbalancer.GetLoadBalancerRequest) (ociloadbalancer.GetLoadBalancerResponse, error) {
|
| 285 | + if *request.LoadBalancerId == "networkerror" { |
| 286 | + return ociloadbalancer.GetLoadBalancerResponse{}, NetworkError{} |
| 287 | + } |
| 288 | + if *request.LoadBalancerId == "notfound" { |
| 289 | + return ociloadbalancer.GetLoadBalancerResponse{}, &exception.NotFoundServiceError{} |
| 290 | + } |
| 291 | + |
248 | 292 | res := util.SampleLoadBalancerResponse()
|
249 | 293 | return res, nil
|
250 | 294 | }
|
251 | 295 |
|
| 296 | +type NetworkError struct { |
| 297 | +} |
| 298 | + |
| 299 | +func (n NetworkError) Error() string { |
| 300 | + return "Failure due to network error" |
| 301 | +} |
| 302 | + |
252 | 303 | func (m MockLoadBalancerClient) UpdateLoadBalancer(ctx context.Context, request ociloadbalancer.UpdateLoadBalancerRequest) (response ociloadbalancer.UpdateLoadBalancerResponse, err error) {
|
253 | 304 | return ociloadbalancer.UpdateLoadBalancerResponse{
|
254 | 305 | RawResponse: nil,
|
|
0 commit comments