mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-23 18:15:26 +00:00
b5841c8a8b
This commit reworks getAvailableIp with a "simpler" version that will look for the first available IP address in our IP Prefix. There is a couple of ideas behind this: * Make the host IPs reasonably predictable and in within similar subnets, which should simplify ACLs for subnets * The code is not random, but deterministic so we can have tests * The code is a bit more understandable (no bit shift magic)
32 lines
737 B
Go
32 lines
737 B
Go
package headscale
|
|
|
|
import (
|
|
"gopkg.in/check.v1"
|
|
)
|
|
|
|
func (s *Suite) TestRegisterMachine(c *check.C) {
|
|
n, err := h.CreateNamespace("test")
|
|
c.Assert(err, check.IsNil)
|
|
|
|
m := Machine{
|
|
ID: 0,
|
|
MachineKey: "8ce002a935f8c394e55e78fbbb410576575ff8ec5cfa2e627e4b807f1be15b0e",
|
|
NodeKey: "bar",
|
|
DiscoKey: "faa",
|
|
Name: "testmachine",
|
|
NamespaceID: n.ID,
|
|
IPAddress: "10.0.0.1",
|
|
}
|
|
h.db.Save(&m)
|
|
|
|
_, err = h.GetMachine("test", "testmachine")
|
|
c.Assert(err, check.IsNil)
|
|
|
|
m2, err := h.RegisterMachine("8ce002a935f8c394e55e78fbbb410576575ff8ec5cfa2e627e4b807f1be15b0e", n.Name)
|
|
c.Assert(err, check.IsNil)
|
|
c.Assert(m2.Registered, check.Equals, true)
|
|
|
|
_, err = m2.GetHostInfo()
|
|
c.Assert(err, check.IsNil)
|
|
}
|