From 6ba68d150cdc0233c13486c2952af5808e130b75 Mon Sep 17 00:00:00 2001 From: Igor Perepilitsyn Date: Mon, 2 May 2022 13:47:21 +0400 Subject: [PATCH] correctly update machine namespace --- namespaces.go | 6 ++++-- namespaces_test.go | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/namespaces.go b/namespaces.go index bb32795..321ac45 100644 --- a/namespaces.go +++ b/namespaces.go @@ -177,8 +177,10 @@ func (h *Headscale) SetMachineNamespace(machine *Machine, namespaceName string) if err != nil { return err } - machine.NamespaceID = namespace.ID - h.db.Save(&machine) + machine.Namespace = *namespace + if result := h.db.Save(&machine); result.Error != nil { + return result.Error + } return nil } diff --git a/namespaces_test.go b/namespaces_test.go index 6baf0d9..4e44492 100644 --- a/namespaces_test.go +++ b/namespaces_test.go @@ -399,6 +399,7 @@ func (s *Suite) TestSetMachineNamespace(c *check.C) { err = app.SetMachineNamespace(&machine, newNamespace.Name) c.Assert(err, check.IsNil) c.Assert(machine.NamespaceID, check.Equals, newNamespace.ID) + c.Assert(machine.Namespace.Name, check.Equals, newNamespace.Name) err = app.SetMachineNamespace(&machine, "non-existing-namespace") c.Assert(err, check.Equals, errNamespaceNotFound) @@ -406,4 +407,5 @@ func (s *Suite) TestSetMachineNamespace(c *check.C) { err = app.SetMachineNamespace(&machine, newNamespace.Name) c.Assert(err, check.IsNil) c.Assert(machine.NamespaceID, check.Equals, newNamespace.ID) + c.Assert(machine.Namespace.Name, check.Equals, newNamespace.Name) }