From 95de823b7241eec5ae8d763414d86cab7b1dfcf0 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Mon, 2 Aug 2021 22:39:18 +0100 Subject: [PATCH] Add test to ensure we can read back ips --- utils_test.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/utils_test.go b/utils_test.go index 471b8220..439fdc19 100644 --- a/utils_test.go +++ b/utils_test.go @@ -49,6 +49,11 @@ func (s *Suite) TestGetUsedIps(c *check.C) { expected := netaddr.MustParseIP("10.27.0.0") 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) { @@ -66,7 +71,7 @@ func (s *Suite) TestGetMultiIp(c *check.C) { c.Assert(err, check.NotNil) m := Machine{ - ID: 0, + ID: uint64(i), MachineKey: "foo", NodeKey: "bar", 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[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") nextIP, err := h.getAvailableIP() c.Assert(err, check.IsNil)