@@ -40,15 +40,23 @@ func TestClusterScope_CreateVCN(t *testing.T) {
40
40
vcnClient := mock_vcn .NewMockClient (mockCtrl )
41
41
42
42
vcnClient .EXPECT ().CreateVcn (gomock .Any (), Eq (func (request interface {}) error {
43
- return vcnMatcher (request , "normal" , common .String ("label" ))
43
+ return vcnMatcher (request , "normal" , common .String ("label" ), [] string { "test-cidr" } )
44
44
})).
45
45
Return (core.CreateVcnResponse {
46
46
Vcn : core.Vcn {
47
47
Id : common .String ("normal_id" ),
48
48
},
49
49
}, nil )
50
50
vcnClient .EXPECT ().CreateVcn (gomock .Any (), Eq (func (request interface {}) error {
51
- return vcnMatcher (request , "error" , nil )
51
+ return vcnMatcher (request , "normal" , common .String ("label" ), []string {"test-cidr1" , "test-cidr2" })
52
+ })).
53
+ Return (core.CreateVcnResponse {
54
+ Vcn : core.Vcn {
55
+ Id : common .String ("normal_id" ),
56
+ },
57
+ }, nil )
58
+ vcnClient .EXPECT ().CreateVcn (gomock .Any (), Eq (func (request interface {}) error {
59
+ return vcnMatcher (request , "error" , nil , []string {VcnDefaultCidr })
52
60
})).
53
61
Return (core.CreateVcnResponse {}, errors .New ("some error" ))
54
62
@@ -65,6 +73,21 @@ func TestClusterScope_CreateVCN(t *testing.T) {
65
73
Vcn : infrastructurev1beta2.VCN {
66
74
Name : "normal" ,
67
75
DnsLabel : common .String ("label" ),
76
+ CIDR : "test-cidr" ,
77
+ },
78
+ },
79
+ },
80
+ want : common .String ("normal_id" ),
81
+ wantErr : false ,
82
+ },
83
+ {
84
+ name : "create vcn is successful, multiple cidrs" ,
85
+ spec : infrastructurev1beta2.OCIClusterSpec {
86
+ NetworkSpec : infrastructurev1beta2.NetworkSpec {
87
+ Vcn : infrastructurev1beta2.VCN {
88
+ Name : "normal" ,
89
+ DnsLabel : common .String ("label" ),
90
+ CIDRS : []string {"test-cidr1" , "test-cidr2" },
68
91
},
69
92
},
70
93
},
@@ -392,11 +415,11 @@ func TestClusterScope_GetVcnCidr(t *testing.T) {
392
415
tests := []struct {
393
416
name string
394
417
spec infrastructurev1beta2.OCIClusterSpec
395
- want string
418
+ want [] string
396
419
}{
397
420
{
398
421
name : "cidr not present" ,
399
- want : VcnDefaultCidr ,
422
+ want : [] string { VcnDefaultCidr } ,
400
423
},
401
424
{
402
425
name : "cidr present" ,
@@ -407,7 +430,7 @@ func TestClusterScope_GetVcnCidr(t *testing.T) {
407
430
},
408
431
},
409
432
},
410
- want : "foo" ,
433
+ want : [] string { "foo" } ,
411
434
},
412
435
}
413
436
l := log .FromContext (context .Background ())
@@ -426,7 +449,7 @@ func TestClusterScope_GetVcnCidr(t *testing.T) {
426
449
OCIClusterAccessor : ociClusterAccessor ,
427
450
Logger : & l ,
428
451
}
429
- if got := s .GetVcnCidr (); got != tt .want {
452
+ if got := s .GetVcnCidrs (); ! reflect . DeepEqual ( got , tt .want ) {
430
453
t .Errorf ("GetVcnCidr() = %v, want %v" , got , tt .want )
431
454
}
432
455
})
@@ -519,7 +542,7 @@ func TestClusterScope_IsVcnEquals(t *testing.T) {
519
542
},
520
543
Logger : & l ,
521
544
}
522
- if got := s .IsVcnEquals (tt .actual , tt . desired ); got != tt .want {
545
+ if got := s .IsVcnEquals (tt .actual ); got != tt .want {
523
546
t .Errorf ("IsVcnEquals() = %v, want %v" , got , tt .want )
524
547
}
525
548
})
@@ -603,7 +626,7 @@ func TestClusterScope_ReconcileVCN(t *testing.T) {
603
626
}}, nil )
604
627
605
628
vcnClient .EXPECT ().CreateVcn (gomock .Any (), Eq (func (request interface {}) error {
606
- return vcnMatcher (request , "not_found" , nil )
629
+ return vcnMatcher (request , "not_found" , common . String ( "label" ), [] string { VcnDefaultCidr } )
607
630
})).
608
631
Return (core.CreateVcnResponse {
609
632
Vcn : core.Vcn {
@@ -664,7 +687,8 @@ func TestClusterScope_ReconcileVCN(t *testing.T) {
664
687
CompartmentId : "bar" ,
665
688
NetworkSpec : infrastructurev1beta2.NetworkSpec {
666
689
Vcn : infrastructurev1beta2.VCN {
667
- Name : "not_found" ,
690
+ Name : "not_found" ,
691
+ DnsLabel : common .String ("label" ),
668
692
},
669
693
},
670
694
},
@@ -706,7 +730,7 @@ func TestClusterScope_ReconcileVCN(t *testing.T) {
706
730
}
707
731
}
708
732
709
- func vcnMatcher (request interface {}, displayName string , dnsLabel * string ) error {
733
+ func vcnMatcher (request interface {}, displayName string , dnsLabel * string , cidrs [] string ) error {
710
734
r , ok := request .(core.CreateVcnRequest )
711
735
if ! ok {
712
736
return errors .New ("expecting CreateVcnRequest type" )
@@ -717,5 +741,8 @@ func vcnMatcher(request interface{}, displayName string, dnsLabel *string) error
717
741
if ! reflect .DeepEqual (r .CreateVcnDetails .DnsLabel , dnsLabel ) {
718
742
return errors .New (fmt .Sprintf ("expecting DnsLabel as %v" , dnsLabel ))
719
743
}
744
+ if ! reflect .DeepEqual (r .CreateVcnDetails .CidrBlocks , cidrs ) {
745
+ return errors .New (fmt .Sprintf ("expecting cidrblocks as %v, actual %v" , cidrs , r .CreateVcnDetails .CidrBlocks ))
746
+ }
720
747
return nil
721
748
}
0 commit comments