mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-27 12:05:26 +00:00
41f6740ddd
tests for that feature. Other fixes: clean up a few typos in comments. Fix a bug that caused the tests to run four times each. Be more consistent in the use of log rather than fmt to print errors and notices.
54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
package headscale
|
|
|
|
import (
|
|
"gopkg.in/check.v1"
|
|
)
|
|
|
|
func (s *Suite) TestCreateAndDestroyNamespace(c *check.C) {
|
|
n, err := h.CreateNamespace("test")
|
|
c.Assert(err, check.IsNil)
|
|
c.Assert(n.Name, check.Equals, "test")
|
|
|
|
ns, err := h.ListNamespaces()
|
|
c.Assert(err, check.IsNil)
|
|
c.Assert(len(*ns), check.Equals, 1)
|
|
|
|
err = h.DestroyNamespace("test")
|
|
c.Assert(err, check.IsNil)
|
|
|
|
_, err = h.GetNamespace("test")
|
|
c.Assert(err, check.NotNil)
|
|
}
|
|
|
|
func (s *Suite) TestDestroyNamespaceErrors(c *check.C) {
|
|
err := h.DestroyNamespace("test")
|
|
c.Assert(err, check.Equals, errorNamespaceNotFound)
|
|
|
|
n, err := h.CreateNamespace("test")
|
|
c.Assert(err, check.IsNil)
|
|
|
|
pak, err := h.CreatePreAuthKey(n.Name, false, false, nil)
|
|
c.Assert(err, check.IsNil)
|
|
|
|
db, err := h.db()
|
|
if err != nil {
|
|
c.Fatal(err)
|
|
}
|
|
defer db.Close()
|
|
m := Machine{
|
|
ID: 0,
|
|
MachineKey: "foo",
|
|
NodeKey: "bar",
|
|
DiscoKey: "faa",
|
|
Name: "testmachine",
|
|
NamespaceID: n.ID,
|
|
Registered: true,
|
|
RegisterMethod: "authKey",
|
|
AuthKeyID: uint(pak.ID),
|
|
}
|
|
db.Save(&m)
|
|
|
|
err = h.DestroyNamespace("test")
|
|
c.Assert(err, check.Equals, errorNamespaceNotEmpty)
|
|
}
|