Skip to content

Commit ca8a02f

Browse files
author
Carlos Flores
committed
update tests
1 parent b0ec7ee commit ca8a02f

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

pkg/targetgroupbinding/networking_manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,10 +540,10 @@ func (m *defaultNetworkingManager) resolveEndpointSGForENI(ctx context.Context,
540540
// user may provide incorrect `--cluster-name` at bootstrap or modify the tag key unexpectedly, it is hard to find out if no clusterName included in error message.
541541
// having `clusterName` included in error message might be helpful for shorten the troubleshooting time spent.
542542
if len(m.serviceTargetENISGTags) == 0 {
543-
return "", errors.Errorf("expect exactly one securityGroup tagged with %v for eni %v, got: %v (clusterName: %v)",
543+
return "", errors.Errorf("expected exactly one securityGroup tagged with %v for eni %v, got: %v (clusterName: %v)",
544544
clusterResourceTagKey, eniInfo.NetworkInterfaceID, sgIDsWithMatchingEndpointSGTags.List(), m.clusterName)
545545
}
546-
return "", errors.Errorf("expect exactly one securityGroup tagged with %v and %v for eni %v, got: %v (clusterName: %v)",
546+
return "", errors.Errorf("expected exactly one securityGroup tagged with %v and %v for eni %v, got: %v (clusterName: %v)",
547547
clusterResourceTagKey, m.serviceTargetENISGTags, eniInfo.NetworkInterfaceID, sgIDsWithMatchingEndpointSGTags.List(), m.clusterName)
548548
}
549549
sgID, _ := sgIDsWithMatchingEndpointSGTags.PopAny()

pkg/targetgroupbinding/networking_manager_test.go

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,7 @@ func Test_defaultNetworkingManager_resolveEndpointSGForENI(t *testing.T) {
14351435
fields fields
14361436
args args
14371437
want string
1438-
wantErr bool
1438+
wantErr error
14391439
}{
14401440
{
14411441
name: "Only one security group in eniInfo returns early",
@@ -1449,8 +1449,7 @@ func Test_defaultNetworkingManager_resolveEndpointSGForENI(t *testing.T) {
14491449
SecurityGroups: []string{"sg-a"},
14501450
},
14511451
},
1452-
want: "sg-a",
1453-
wantErr: false,
1452+
want: "sg-a",
14541453
},
14551454
{
14561455
name: "No security group in eniInfo returns error",
@@ -1471,7 +1470,7 @@ func Test_defaultNetworkingManager_resolveEndpointSGForENI(t *testing.T) {
14711470
},
14721471
},
14731472
want: "",
1474-
wantErr: true,
1473+
wantErr: errors.New("expected exactly one securityGroup tagged with kubernetes.io/cluster/cluster-a for eni eni-a, got: [] (clusterName: cluster-a)"),
14751474
},
14761475
{
14771476
name: "A single security group with cluster name tag and no service target tags set",
@@ -1507,8 +1506,7 @@ func Test_defaultNetworkingManager_resolveEndpointSGForENI(t *testing.T) {
15071506
SecurityGroups: []string{"sg-a", "sg-b"},
15081507
},
15091508
},
1510-
want: "sg-a",
1511-
wantErr: false,
1509+
want: "sg-a",
15121510
},
15131511
{
15141512
name: "A single security group with cluster name tag and one service target tag set",
@@ -1547,8 +1545,7 @@ func Test_defaultNetworkingManager_resolveEndpointSGForENI(t *testing.T) {
15471545
SecurityGroups: []string{"sg-a", "sg-b"},
15481546
},
15491547
},
1550-
want: "sg-b",
1551-
wantErr: false,
1548+
want: "sg-b",
15521549
},
15531550
{
15541551
name: "A single security group with cluster name tag and one service target tag set with no matches",
@@ -1588,7 +1585,7 @@ func Test_defaultNetworkingManager_resolveEndpointSGForENI(t *testing.T) {
15881585
},
15891586
},
15901587
want: "",
1591-
wantErr: true,
1588+
wantErr: errors.New("expected exactly one securityGroup tagged with kubernetes.io/cluster/cluster-a and map[keyA:valueNotA] for eni eni-a, got: [] (clusterName: cluster-a)"),
15921589
},
15931590
{
15941591
name: "A single security group with cluster name tag and multiple service target tags set",
@@ -1628,8 +1625,7 @@ func Test_defaultNetworkingManager_resolveEndpointSGForENI(t *testing.T) {
16281625
SecurityGroups: []string{"sg-a", "sg-b"},
16291626
},
16301627
},
1631-
want: "sg-b",
1632-
wantErr: false,
1628+
want: "sg-b",
16331629
},
16341630
{
16351631
name: "A single security group with cluster name tag and multiple service target tags set with no matches",
@@ -1670,7 +1666,7 @@ func Test_defaultNetworkingManager_resolveEndpointSGForENI(t *testing.T) {
16701666
},
16711667
},
16721668
want: "",
1673-
wantErr: true,
1669+
wantErr: errors.New("expected exactly one securityGroup tagged with kubernetes.io/cluster/cluster-a and map[keyA:valueA keyB:valueNotB2] for eni eni-a, got: [] (clusterName: cluster-a)"),
16741670
},
16751671
{
16761672
name: "A single security group with cluster name tag and a service target tags with an empty value",
@@ -1709,11 +1705,10 @@ func Test_defaultNetworkingManager_resolveEndpointSGForENI(t *testing.T) {
17091705
SecurityGroups: []string{"sg-a", "sg-b"},
17101706
},
17111707
},
1712-
want: "sg-b",
1713-
wantErr: false,
1708+
want: "sg-b",
17141709
},
17151710
{
1716-
name: "A single security group with cluster name tag and a service target tags with an empty value with no matches",
1711+
name: "A single security group with cluster name tag and a service target tag with an empty value with no matches",
17171712
fields: fields{
17181713
serviceTargetENISGTags: map[string]string{
17191714
"keyE": "",
@@ -1750,7 +1745,7 @@ func Test_defaultNetworkingManager_resolveEndpointSGForENI(t *testing.T) {
17501745
},
17511746
},
17521747
want: "",
1753-
wantErr: true,
1748+
wantErr: errors.New("expected exactly one securityGroup tagged with kubernetes.io/cluster/cluster-a and map[keyE:] for eni eni-a, got: [] (clusterName: cluster-a)"),
17541749
},
17551750
}
17561751
for _, tt := range tests {
@@ -1769,12 +1764,11 @@ func Test_defaultNetworkingManager_resolveEndpointSGForENI(t *testing.T) {
17691764
serviceTargetENISGTags: tt.fields.serviceTargetENISGTags,
17701765
}
17711766
got, err := m.resolveEndpointSGForENI(tt.args.ctx, tt.args.eniInfo)
1772-
if (err != nil) != tt.wantErr {
1773-
t.Errorf("defaultNetworkingManager.resolveEndpointSGForENI() error = %v, wantErr %v", err, tt.wantErr)
1774-
return
1775-
}
1776-
if got != tt.want {
1777-
t.Errorf("defaultNetworkingManager.resolveEndpointSGForENI() = %v, want %v", got, tt.want)
1767+
if tt.wantErr != nil {
1768+
assert.EqualError(t, err, tt.wantErr.Error())
1769+
} else {
1770+
assert.NoError(t, err)
1771+
assert.Equal(t, tt.want, got)
17781772
}
17791773
})
17801774
}

0 commit comments

Comments
 (0)