Remove some unused error fields from test cases

Signed-off-by: Tom Wieczorek <twieczorek@mirantis.com>
This commit is contained in:
Tom Wieczorek 2024-09-24 12:37:06 +02:00 committed by Aaron U'Ren
parent 63d762f00b
commit ff8a189c29
2 changed files with 7 additions and 34 deletions

View File

@ -31,7 +31,6 @@ type PolicyTestCase struct {
customImportRejectDefinedSet *gobgpapi.DefinedSet
exportPolicyStatements []*gobgpapi.Statement
importPolicyStatements []*gobgpapi.Statement
addPolicyErr error
startBGPServerErr error
}
@ -171,7 +170,6 @@ func Test_AddPolicies(t *testing.T) {
},
[]*gobgpapi.Statement{},
nil,
nil,
},
{
"has nodes and services with custom import reject annotation",
@ -415,7 +413,6 @@ func Test_AddPolicies(t *testing.T) {
},
},
nil,
nil,
},
{
"has nodes, services with external peers",
@ -620,7 +617,6 @@ func Test_AddPolicies(t *testing.T) {
},
},
nil,
nil,
},
{
"has nodes, services with external peers and iBGP disabled",
@ -808,7 +804,6 @@ func Test_AddPolicies(t *testing.T) {
},
},
nil,
nil,
},
{
"prepends AS with external peers",
@ -1019,7 +1014,6 @@ func Test_AddPolicies(t *testing.T) {
},
},
nil,
nil,
},
{
"only prepends AS when both node annotations are present",
@ -1228,7 +1222,6 @@ func Test_AddPolicies(t *testing.T) {
},
},
},
nil,
fmt.Errorf("both %s and %s must be set", pathPrependASNAnnotation, pathPrependRepeatNAnnotation),
},
{
@ -1444,7 +1437,6 @@ func Test_AddPolicies(t *testing.T) {
},
},
nil,
nil,
},
}
@ -1490,15 +1482,9 @@ func Test_AddPolicies(t *testing.T) {
informerFactory := informers.NewSharedInformerFactory(testcase.nrc.clientset, 0)
nodeInformer := informerFactory.Core().V1().Nodes().Informer()
testcase.nrc.nodeLister = nodeInformer.GetIndexer()
err = testcase.nrc.AddPolicies()
if !reflect.DeepEqual(err, testcase.addPolicyErr) {
t.Logf("expected err when invoking AddPolicies(): %v", testcase.addPolicyErr)
t.Logf("actual err from AddPolicies() received: %v", err)
t.Error("unexpected error")
}
// If we expect AddPolicies() to fail we should stop here as there is no point in further evaluating policies
if testcase.addPolicyErr != nil {
return
if err := testcase.nrc.AddPolicies(); err != nil {
// If AddPolicies() failed we should stop here as there is no point in further evaluating policies
t.Fatalf("unexpected error when invoking AddPolicies(): %v", err)
}
err = testcase.nrc.bgpServer.ListDefinedSet(context.Background(),

View File

@ -2,7 +2,6 @@ package routing
import (
"context"
"errors"
"fmt"
"net"
"os"
@ -1813,7 +1812,6 @@ func Test_nodeHasEndpointsForService(t *testing.T) {
existingService *v1core.Service
existingEndpoint *v1core.Endpoints
nodeHasEndpoints bool
err error
}{
{
"node has endpoints for service",
@ -1860,7 +1858,6 @@ func Test_nodeHasEndpointsForService(t *testing.T) {
},
},
true,
nil,
},
{
"node has no endpoints for service",
@ -1907,7 +1904,6 @@ func Test_nodeHasEndpointsForService(t *testing.T) {
},
},
false,
nil,
},
}
@ -1930,10 +1926,8 @@ func Test_nodeHasEndpointsForService(t *testing.T) {
waitForListerWithTimeout(testcase.nrc.epLister, time.Second*10, t)
nodeHasEndpoints, err := testcase.nrc.nodeHasEndpointsForService(testcase.existingService)
if !errors.Is(err, testcase.err) {
t.Logf("actual err: %v", err)
t.Logf("expected err: %v", testcase.err)
t.Error("unexpected error")
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if nodeHasEndpoints != testcase.nodeHasEndpoints {
t.Logf("expected nodeHasEndpoints: %v", testcase.nodeHasEndpoints)
@ -1953,7 +1947,6 @@ func Test_advertisePodRoute(t *testing.T) {
node *v1core.Node
// the key is the subnet from the watch event
watchEvents map[string]bool
err error
}{
{
"add bgp path for pod cidr using NODE_NAME",
@ -1984,7 +1977,6 @@ func Test_advertisePodRoute(t *testing.T) {
map[string]bool{
"172.20.0.0/24": true,
},
nil,
},
{
"add bgp path for pod cidr using hostname override",
@ -2016,7 +2008,6 @@ func Test_advertisePodRoute(t *testing.T) {
map[string]bool{
"172.20.0.0/24": true,
},
nil,
},
{
"advertise IPv6 Address when enabled",
@ -2051,7 +2042,6 @@ func Test_advertisePodRoute(t *testing.T) {
map[string]bool{
"2001:db8:42:2::/64": true,
},
nil,
},
/* disabling tests for now, as node POD cidr is read just once at the starting of the program
Tests needs to be adopted to catch the errors when NetworkRoutingController starts
@ -2148,11 +2138,8 @@ func Test_advertisePodRoute(t *testing.T) {
_ = os.Setenv("NODE_NAME", testcase.envNodeName)
defer func() { _ = os.Unsetenv("NODE_NAME") }()
err = testcase.nrc.advertisePodRoute()
if !reflect.DeepEqual(err, testcase.err) {
t.Logf("actual error: %v", err)
t.Logf("expected error: %v", testcase.err)
t.Error("did not get expected error")
if err := testcase.nrc.advertisePodRoute(); err != nil {
t.Errorf("unexpected error: %v", err)
}
timeoutCh := time.After(time.Second * 10)