2021-05-23 13:55:15 +00:00
|
|
|
package headscale
|
|
|
|
|
|
|
|
import (
|
2021-10-18 19:26:43 +00:00
|
|
|
"time"
|
|
|
|
|
2021-05-23 13:55:15 +00:00
|
|
|
"gopkg.in/check.v1"
|
2022-01-16 13:16:59 +00:00
|
|
|
"inet.af/netaddr"
|
2021-05-23 13:55:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (s *Suite) TestRegisterMachine(c *check.C) {
|
2021-11-15 16:16:04 +00:00
|
|
|
namespace, err := app.CreateNamespace("test")
|
2021-05-23 13:55:15 +00:00
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
2021-10-18 19:26:43 +00:00
|
|
|
now := time.Now().UTC()
|
|
|
|
|
2021-11-15 16:16:04 +00:00
|
|
|
machine := Machine{
|
2021-11-19 09:02:29 +00:00
|
|
|
ID: 0,
|
|
|
|
MachineKey: "8ce002a935f8c394e55e78fbbb410576575ff8ec5cfa2e627e4b807f1be15b0e",
|
|
|
|
NodeKey: "bar",
|
|
|
|
DiscoKey: "faa",
|
|
|
|
Name: "testmachine",
|
|
|
|
NamespaceID: namespace.ID,
|
2022-01-16 13:16:59 +00:00
|
|
|
IPAddresses: []netaddr.IP{netaddr.MustParseIP("10.0.0.1")},
|
2021-11-19 09:02:29 +00:00
|
|
|
Expiry: &now,
|
2021-05-23 13:55:15 +00:00
|
|
|
}
|
2022-01-16 13:16:59 +00:00
|
|
|
err = app.db.Save(&machine).Error
|
|
|
|
c.Assert(err, check.IsNil)
|
2021-05-23 13:55:15 +00:00
|
|
|
|
2022-01-16 13:16:59 +00:00
|
|
|
_, err = app.GetMachine(namespace.Name, machine.Name)
|
2021-05-23 13:55:15 +00:00
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
2021-11-15 16:16:04 +00:00
|
|
|
machineAfterRegistering, err := app.RegisterMachine(
|
2022-02-28 08:06:39 +00:00
|
|
|
"testmachine",
|
2022-01-16 13:16:59 +00:00
|
|
|
machine.MachineKey,
|
2021-11-15 16:16:04 +00:00
|
|
|
namespace.Name,
|
2022-02-27 17:40:10 +00:00
|
|
|
RegisterMethodCLI,
|
|
|
|
nil, nil, nil, nil,
|
2021-11-13 08:36:45 +00:00
|
|
|
)
|
2021-05-23 13:55:15 +00:00
|
|
|
c.Assert(err, check.IsNil)
|
2021-11-15 16:16:04 +00:00
|
|
|
c.Assert(machineAfterRegistering.Registered, check.Equals, true)
|
2021-05-23 13:55:15 +00:00
|
|
|
|
2021-11-15 16:16:04 +00:00
|
|
|
_, err = machineAfterRegistering.GetHostInfo()
|
2021-05-23 13:55:15 +00:00
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
}
|