Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
Fixed linting
  • Loading branch information
juanfont committed Jan 29, 2023
1 parent 3ac2e0b commit 0f65918
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ func (s *Suite) TestGetRoutes(c *check.C) {
c.Assert(err, check.IsNil)
c.Assert(len(advertisedRoutes), check.Equals, 1)

err = app.EnableRoutes(&machine, "192.168.0.0/24")
err = app.enableRoutes(&machine, "192.168.0.0/24")
c.Assert(err, check.NotNil)

err = app.EnableRoutes(&machine, "10.0.0.0/24")
err = app.enableRoutes(&machine, "10.0.0.0/24")
c.Assert(err, check.IsNil)
}

Expand Down Expand Up @@ -102,25 +102,25 @@ func (s *Suite) TestGetEnableRoutes(c *check.C) {
c.Assert(err, check.IsNil)
c.Assert(len(noEnabledRoutes), check.Equals, 0)

err = app.EnableRoutes(&machine, "192.168.0.0/24")
err = app.enableRoutes(&machine, "192.168.0.0/24")
c.Assert(err, check.NotNil)

err = app.EnableRoutes(&machine, "10.0.0.0/24")
err = app.enableRoutes(&machine, "10.0.0.0/24")
c.Assert(err, check.IsNil)

enabledRoutes, err := app.GetEnabledRoutes(&machine)
c.Assert(err, check.IsNil)
c.Assert(len(enabledRoutes), check.Equals, 1)

// Adding it twice will just let it pass through
err = app.EnableRoutes(&machine, "10.0.0.0/24")
err = app.enableRoutes(&machine, "10.0.0.0/24")
c.Assert(err, check.IsNil)

enableRoutesAfterDoubleApply, err := app.GetEnabledRoutes(&machine)
c.Assert(err, check.IsNil)
c.Assert(len(enableRoutesAfterDoubleApply), check.Equals, 1)

err = app.EnableRoutes(&machine, "150.0.10.0/25")
err = app.enableRoutes(&machine, "150.0.10.0/25")
c.Assert(err, check.IsNil)

enabledRoutesWithAdditionalRoute, err := app.GetEnabledRoutes(&machine)
Expand Down Expand Up @@ -167,10 +167,10 @@ func (s *Suite) TestIsUniquePrefix(c *check.C) {
err = app.processMachineRoutes(&machine1)
c.Assert(err, check.IsNil)

err = app.EnableRoutes(&machine1, route.String())
err = app.enableRoutes(&machine1, route.String())
c.Assert(err, check.IsNil)

err = app.EnableRoutes(&machine1, route2.String())
err = app.enableRoutes(&machine1, route2.String())
c.Assert(err, check.IsNil)

hostInfo2 := tailcfg.Hostinfo{
Expand All @@ -192,7 +192,7 @@ func (s *Suite) TestIsUniquePrefix(c *check.C) {
err = app.processMachineRoutes(&machine2)
c.Assert(err, check.IsNil)

err = app.EnableRoutes(&machine2, route2.String())
err = app.enableRoutes(&machine2, route2.String())
c.Assert(err, check.IsNil)

enabledRoutes1, err := app.GetEnabledRoutes(&machine1)
Expand Down Expand Up @@ -254,10 +254,10 @@ func (s *Suite) TestSubnetFailover(c *check.C) {
err = app.processMachineRoutes(&machine1)
c.Assert(err, check.IsNil)

err = app.EnableRoutes(&machine1, prefix.String())
err = app.enableRoutes(&machine1, prefix.String())
c.Assert(err, check.IsNil)

err = app.EnableRoutes(&machine1, prefix2.String())
err = app.enableRoutes(&machine1, prefix2.String())
c.Assert(err, check.IsNil)

err = app.handlePrimarySubnetFailover()
Expand Down Expand Up @@ -291,7 +291,7 @@ func (s *Suite) TestSubnetFailover(c *check.C) {
err = app.processMachineRoutes(&machine2)
c.Assert(err, check.IsNil)

err = app.EnableRoutes(&machine2, prefix2.String())
err = app.enableRoutes(&machine2, prefix2.String())
c.Assert(err, check.IsNil)

err = app.handlePrimarySubnetFailover()
Expand Down Expand Up @@ -339,7 +339,7 @@ func (s *Suite) TestSubnetFailover(c *check.C) {
err = app.processMachineRoutes(&machine2)
c.Assert(err, check.IsNil)

err = app.EnableRoutes(&machine2, prefix.String())
err = app.enableRoutes(&machine2, prefix.String())
c.Assert(err, check.IsNil)

err = app.handlePrimarySubnetFailover()
Expand Down Expand Up @@ -413,18 +413,24 @@ func (s *Suite) TestAllowedIPRoutes(c *check.C) {
err = app.processMachineRoutes(&machine1)
c.Assert(err, check.IsNil)

err = app.EnableRoutes(&machine1, prefix.String())
err = app.enableRoutes(&machine1, prefix.String())
c.Assert(err, check.IsNil)

// We do not enable this one on purpose to test that it is not enabled
// err = app.EnableRoutes(&machine1, prefix2.String())
// err = app.enableRoutes(&machine1, prefix2.String())
// c.Assert(err, check.IsNil)

err = app.EnableRoutes(&machine1, prefixExitNodeV4.String())
routes, err := app.GetMachineRoutes(&machine1)
c.Assert(err, check.IsNil)
for _, route := range routes {
if route.isExitRoute() {
err = app.EnableRoute(uint64(route.ID))
c.Assert(err, check.IsNil)

err = app.EnableRoutes(&machine1, prefixExitNodeV6.String())
c.Assert(err, check.IsNil)
// We only enable one exit route, so we can test that both are enabled
break
}
}

err = app.handlePrimarySubnetFailover()
c.Assert(err, check.IsNil)
Expand Down

0 comments on commit 0f65918

Please sign in to comment.