mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-30 02:43:05 +00:00
Port routes tests to new model
This commit is contained in:
parent
cf35ae94d0
commit
52ab2a8ffd
2 changed files with 27 additions and 30 deletions
|
@ -1153,9 +1153,14 @@ func (s *Suite) TestAutoApproveRoutes(c *check.C) {
|
||||||
|
|
||||||
app.db.Save(&machine)
|
app.db.Save(&machine)
|
||||||
|
|
||||||
|
err = app.processMachineRoutes(&machine)
|
||||||
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
machine0ByID, err := app.GetMachineByID(0)
|
machine0ByID, err := app.GetMachineByID(0)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
app.EnableAutoApprovedRoutes(machine0ByID)
|
app.EnableAutoApprovedRoutes(machine0ByID)
|
||||||
c.Assert(machine0ByID.GetEnabledRoutes(), check.HasLen, 3)
|
enabledRoutes, err := app.GetEnabledRoutes(machine0ByID)
|
||||||
|
c.Assert(err, check.IsNil)
|
||||||
|
c.Assert(enabledRoutes, check.HasLen, 3)
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,17 +37,17 @@ func (s *Suite) TestGetRoutes(c *check.C) {
|
||||||
}
|
}
|
||||||
app.db.Save(&machine)
|
app.db.Save(&machine)
|
||||||
|
|
||||||
advertisedRoutes, err := app.GetAdvertisedNodeRoutes(
|
err = app.processMachineRoutes(&machine)
|
||||||
"test",
|
|
||||||
"test_get_route_machine",
|
|
||||||
)
|
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
c.Assert(len(*advertisedRoutes), check.Equals, 1)
|
|
||||||
|
|
||||||
err = app.EnableNodeRoute("test", "test_get_route_machine", "192.168.0.0/24")
|
advertisedRoutes, err := app.GetAdvertisedRoutes(&machine)
|
||||||
|
c.Assert(err, check.IsNil)
|
||||||
|
c.Assert(len(advertisedRoutes), check.Equals, 1)
|
||||||
|
|
||||||
|
err = app.EnableRoutes(&machine, "192.168.0.0/24")
|
||||||
c.Assert(err, check.NotNil)
|
c.Assert(err, check.NotNil)
|
||||||
|
|
||||||
err = app.EnableNodeRoute("test", "test_get_route_machine", "10.0.0.0/24")
|
err = app.EnableRoutes(&machine, "10.0.0.0/24")
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,48 +88,40 @@ func (s *Suite) TestGetEnableRoutes(c *check.C) {
|
||||||
}
|
}
|
||||||
app.db.Save(&machine)
|
app.db.Save(&machine)
|
||||||
|
|
||||||
availableRoutes, err := app.GetAdvertisedNodeRoutes(
|
err = app.processMachineRoutes(&machine)
|
||||||
"test",
|
|
||||||
"test_enable_route_machine",
|
|
||||||
)
|
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
c.Assert(len(*availableRoutes), check.Equals, 2)
|
|
||||||
|
|
||||||
noEnabledRoutes, err := app.GetEnabledNodeRoutes(
|
availableRoutes, err := app.GetAdvertisedRoutes(&machine)
|
||||||
"test",
|
c.Assert(err, check.IsNil)
|
||||||
"test_enable_route_machine",
|
c.Assert(err, check.IsNil)
|
||||||
)
|
c.Assert(len(availableRoutes), check.Equals, 2)
|
||||||
|
|
||||||
|
noEnabledRoutes, err := app.GetEnabledRoutes(&machine)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
c.Assert(len(noEnabledRoutes), check.Equals, 0)
|
c.Assert(len(noEnabledRoutes), check.Equals, 0)
|
||||||
|
|
||||||
err = app.EnableNodeRoute("test", "test_enable_route_machine", "192.168.0.0/24")
|
err = app.EnableRoutes(&machine, "192.168.0.0/24")
|
||||||
c.Assert(err, check.NotNil)
|
c.Assert(err, check.NotNil)
|
||||||
|
|
||||||
err = app.EnableNodeRoute("test", "test_enable_route_machine", "10.0.0.0/24")
|
err = app.EnableRoutes(&machine, "10.0.0.0/24")
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
enabledRoutes, err := app.GetEnabledNodeRoutes("test", "test_enable_route_machine")
|
enabledRoutes, err := app.GetEnabledRoutes(&machine)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
c.Assert(len(enabledRoutes), check.Equals, 1)
|
c.Assert(len(enabledRoutes), check.Equals, 1)
|
||||||
|
|
||||||
// Adding it twice will just let it pass through
|
// Adding it twice will just let it pass through
|
||||||
err = app.EnableNodeRoute("test", "test_enable_route_machine", "10.0.0.0/24")
|
err = app.EnableRoutes(&machine, "10.0.0.0/24")
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
enableRoutesAfterDoubleApply, err := app.GetEnabledNodeRoutes(
|
enableRoutesAfterDoubleApply, err := app.GetEnabledRoutes(&machine)
|
||||||
"test",
|
|
||||||
"test_enable_route_machine",
|
|
||||||
)
|
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
c.Assert(len(enableRoutesAfterDoubleApply), check.Equals, 1)
|
c.Assert(len(enableRoutesAfterDoubleApply), check.Equals, 1)
|
||||||
|
|
||||||
err = app.EnableNodeRoute("test", "test_enable_route_machine", "150.0.10.0/25")
|
err = app.EnableRoutes(&machine, "150.0.10.0/25")
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
enabledRoutesWithAdditionalRoute, err := app.GetEnabledNodeRoutes(
|
enabledRoutesWithAdditionalRoute, err := app.GetEnabledRoutes(&machine)
|
||||||
"test",
|
|
||||||
"test_enable_route_machine",
|
|
||||||
)
|
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
c.Assert(len(enabledRoutesWithAdditionalRoute), check.Equals, 2)
|
c.Assert(len(enabledRoutesWithAdditionalRoute), check.Equals, 2)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue