Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove some unused error fields from test cases #1747

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions pkg/controllers/routing/bgp_policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ type PolicyTestCase struct {
customImportRejectDefinedSet *gobgpapi.DefinedSet
exportPolicyStatements []*gobgpapi.Statement
importPolicyStatements []*gobgpapi.Statement
addPolicyErr error
startBGPServerErr error
}

Expand Down Expand Up @@ -171,7 +170,6 @@ func Test_AddPolicies(t *testing.T) {
},
[]*gobgpapi.Statement{},
nil,
nil,
},
{
"has nodes and services with custom import reject annotation",
Expand Down Expand Up @@ -415,7 +413,6 @@ func Test_AddPolicies(t *testing.T) {
},
},
nil,
nil,
},
{
"has nodes, services with external peers",
Expand Down Expand Up @@ -620,7 +617,6 @@ func Test_AddPolicies(t *testing.T) {
},
},
nil,
nil,
},
{
"has nodes, services with external peers and iBGP disabled",
Expand Down Expand Up @@ -808,7 +804,6 @@ func Test_AddPolicies(t *testing.T) {
},
},
nil,
nil,
},
{
"prepends AS with external peers",
Expand Down Expand Up @@ -1019,7 +1014,6 @@ func Test_AddPolicies(t *testing.T) {
},
},
nil,
nil,
},
{
"only prepends AS when both node annotations are present",
Expand Down Expand Up @@ -1228,7 +1222,6 @@ func Test_AddPolicies(t *testing.T) {
},
},
},
nil,
fmt.Errorf("both %s and %s must be set", pathPrependASNAnnotation, pathPrependRepeatNAnnotation),
},
{
Expand Down Expand Up @@ -1444,7 +1437,6 @@ func Test_AddPolicies(t *testing.T) {
},
},
nil,
nil,
},
}

Expand Down Expand Up @@ -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(),
Expand Down
21 changes: 4 additions & 17 deletions pkg/controllers/routing/network_routes_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package routing

import (
"context"
"errors"
"fmt"
"net"
"os"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -1860,7 +1858,6 @@ func Test_nodeHasEndpointsForService(t *testing.T) {
},
},
true,
nil,
},
{
"node has no endpoints for service",
Expand Down Expand Up @@ -1907,7 +1904,6 @@ func Test_nodeHasEndpointsForService(t *testing.T) {
},
},
false,
nil,
},
}

Expand All @@ -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)
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down