1
0
mirror of https://github.com/juanfont/headscale.git synced 2024-12-20 19:09:07 +01:00

Add test to ensure we can read back ips

This commit is contained in:
Kristoffer Dalby 2021-08-02 22:39:18 +01:00
parent 9f85efffd5
commit 95de823b72
No known key found for this signature in database
GPG Key ID: 09F62DC067465735

View File

@ -49,6 +49,11 @@ func (s *Suite) TestGetUsedIps(c *check.C) {
expected := netaddr.MustParseIP("10.27.0.0") expected := netaddr.MustParseIP("10.27.0.0")
c.Assert(ips[0], check.Equals, expected) c.Assert(ips[0], check.Equals, expected)
m1, err := h.GetMachineByID(0)
c.Assert(err, check.IsNil)
c.Assert(m1.IPAddress, check.Equals, expected.String())
} }
func (s *Suite) TestGetMultiIp(c *check.C) { func (s *Suite) TestGetMultiIp(c *check.C) {
@ -66,7 +71,7 @@ func (s *Suite) TestGetMultiIp(c *check.C) {
c.Assert(err, check.NotNil) c.Assert(err, check.NotNil)
m := Machine{ m := Machine{
ID: 0, ID: uint64(i),
MachineKey: "foo", MachineKey: "foo",
NodeKey: "bar", NodeKey: "bar",
DiscoKey: "faa", DiscoKey: "faa",
@ -90,6 +95,15 @@ func (s *Suite) TestGetMultiIp(c *check.C) {
c.Assert(ips[9], check.Equals, netaddr.MustParseIP("10.27.0.9")) c.Assert(ips[9], check.Equals, netaddr.MustParseIP("10.27.0.9"))
c.Assert(ips[300], check.Equals, netaddr.MustParseIP("10.27.1.44")) c.Assert(ips[300], check.Equals, netaddr.MustParseIP("10.27.1.44"))
// Check that we can read back the IPs
m1, err := h.GetMachineByID(1)
c.Assert(err, check.IsNil)
c.Assert(m1.IPAddress, check.Equals, netaddr.MustParseIP("10.27.0.0").String())
m50, err := h.GetMachineByID(50)
c.Assert(err, check.IsNil)
c.Assert(m50.IPAddress, check.Equals, netaddr.MustParseIP("10.27.0.49").String())
expectedNextIP := netaddr.MustParseIP("10.27.1.94") expectedNextIP := netaddr.MustParseIP("10.27.1.94")
nextIP, err := h.getAvailableIP() nextIP, err := h.getAvailableIP()
c.Assert(err, check.IsNil) c.Assert(err, check.IsNil)