mirror of
https://github.com/juanfont/headscale.git
synced 2024-12-25 01:07:52 +00:00
add unit test
This commit is contained in:
parent
62c780a448
commit
4e686f8b77
@ -372,3 +372,38 @@ func TestCheckForFQDNRules(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Suite) TestSetMachineNamespace(c *check.C) {
|
||||||
|
oldNamespace, err := app.CreateNamespace("old")
|
||||||
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
|
newNamespace, err := app.CreateNamespace("new")
|
||||||
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
|
pak, err := app.CreatePreAuthKey(oldNamespace.Name, false, false, nil)
|
||||||
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
|
machine := Machine{
|
||||||
|
ID: 0,
|
||||||
|
MachineKey: "foo",
|
||||||
|
NodeKey: "bar",
|
||||||
|
DiscoKey: "faa",
|
||||||
|
Name: "testmachine",
|
||||||
|
NamespaceID: oldNamespace.ID,
|
||||||
|
RegisterMethod: RegisterMethodAuthKey,
|
||||||
|
AuthKeyID: uint(pak.ID),
|
||||||
|
}
|
||||||
|
app.db.Save(&machine)
|
||||||
|
c.Assert(machine.NamespaceID, check.Equals, oldNamespace.ID)
|
||||||
|
|
||||||
|
err = app.SetMachineNamespace(&machine, newNamespace.Name)
|
||||||
|
c.Assert(err, check.IsNil)
|
||||||
|
c.Assert(machine.NamespaceID, check.Equals, newNamespace.ID)
|
||||||
|
|
||||||
|
err = app.SetMachineNamespace(&machine, "non-existing-namespace")
|
||||||
|
c.Assert(err, check.Equals, errNamespaceNotFound)
|
||||||
|
|
||||||
|
err = app.SetMachineNamespace(&machine, newNamespace.Name)
|
||||||
|
c.Assert(err, check.IsNil)
|
||||||
|
c.Assert(machine.NamespaceID, check.Equals, newNamespace.ID)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user