Skip to content

Commit

Permalink
Add test to ensure we can deal with empty ips from database
Browse files Browse the repository at this point in the history
  • Loading branch information
kradalby committed Aug 3, 2021
1 parent 73207de commit d3349aa
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,39 @@ func (s *Suite) TestGetMultiIp(c *check.C) {

c.Assert(nextIP2.String(), check.Equals, expectedNextIP.String())
}

func (s *Suite) TestGetAvailableIpMachineWithoutIP(c *check.C) {
ip, err := h.getAvailableIP()
c.Assert(err, check.IsNil)

expected := netaddr.MustParseIP("10.27.0.0")

c.Assert(ip.String(), check.Equals, expected.String())

n, err := h.CreateNamespace("test_ip")
c.Assert(err, check.IsNil)

pak, err := h.CreatePreAuthKey(n.Name, false, false, nil)
c.Assert(err, check.IsNil)

_, err = h.GetMachine("test", "testmachine")
c.Assert(err, check.NotNil)

m := Machine{
ID: 0,
MachineKey: "foo",
NodeKey: "bar",
DiscoKey: "faa",
Name: "testmachine",
NamespaceID: n.ID,
Registered: true,
RegisterMethod: "authKey",
AuthKeyID: uint(pak.ID),
}
h.db.Save(&m)

ip2, err := h.getAvailableIP()
c.Assert(err, check.IsNil)

c.Assert(ip2.String(), check.Equals, expected.String())
}

0 comments on commit d3349aa

Please sign in to comment.