2021-05-23 09:55:15 -04:00
|
|
|
package headscale
|
|
|
|
|
|
|
|
import (
|
2021-10-18 15:26:43 -04:00
|
|
|
"time"
|
|
|
|
|
2021-05-23 09:55:15 -04:00
|
|
|
"gopkg.in/check.v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *Suite) TestRegisterMachine(c *check.C) {
|
2021-11-15 11:16:04 -05:00
|
|
|
namespace, err := app.CreateNamespace("test")
|
2021-05-23 09:55:15 -04:00
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
2021-10-18 15:26:43 -04:00
|
|
|
now := time.Now().UTC()
|
|
|
|
|
2021-11-15 11:16:04 -05:00
|
|
|
machine := Machine{
|
2021-11-19 04:02:29 -05:00
|
|
|
ID: 0,
|
|
|
|
MachineKey: "8ce002a935f8c394e55e78fbbb410576575ff8ec5cfa2e627e4b807f1be15b0e",
|
|
|
|
NodeKey: "bar",
|
|
|
|
DiscoKey: "faa",
|
|
|
|
Name: "testmachine",
|
|
|
|
NamespaceID: namespace.ID,
|
|
|
|
IPAddress: "10.0.0.1",
|
|
|
|
Expiry: &now,
|
2021-05-23 09:55:15 -04:00
|
|
|
}
|
2021-11-15 11:16:04 -05:00
|
|
|
app.db.Save(&machine)
|
2021-05-23 09:55:15 -04:00
|
|
|
|
2021-11-15 11:16:04 -05:00
|
|
|
_, err = app.GetMachine("test", "testmachine")
|
2021-05-23 09:55:15 -04:00
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
2021-11-15 11:16:04 -05:00
|
|
|
machineAfterRegistering, err := app.RegisterMachine(
|
2021-11-13 03:36:45 -05:00
|
|
|
"8ce002a935f8c394e55e78fbbb410576575ff8ec5cfa2e627e4b807f1be15b0e",
|
2021-11-15 11:16:04 -05:00
|
|
|
namespace.Name,
|
2021-11-13 03:36:45 -05:00
|
|
|
)
|
2021-05-23 09:55:15 -04:00
|
|
|
c.Assert(err, check.IsNil)
|
2021-11-15 11:16:04 -05:00
|
|
|
c.Assert(machineAfterRegistering.Registered, check.Equals, true)
|
2021-05-23 09:55:15 -04:00
|
|
|
|
2021-11-15 11:16:04 -05:00
|
|
|
_, err = machineAfterRegistering.GetHostInfo()
|
2021-05-23 09:55:15 -04:00
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
}
|