From 1249262bb79526bdc47fca79d0a344a4d8b7a64e Mon Sep 17 00:00:00 2001 From: Aleksander Mistewicz Date: Thu, 8 Jun 2017 15:29:10 +0200 Subject: [PATCH] Implement setting groups for worker One of the assumptions of Boruta system is that every user will have access to the limited amount of resources. It is done by groups. Initially Worker is not assigned to any. In order to add or remove group from the list a new list should be created and SetGroups used to replace it. Change-Id: Id17eb5feab091dbaa90404d8a09bf4e52537fc61 Signed-off-by: Aleksander Mistewicz Reviewed-on: https://mcdsrvbld02.digital.local/review/49060 Reviewed-by: Maciej Wereski Tested-by: Maciej Wereski --- workers/worker_list_test.go | 24 ++++++++++++++++++++++++ workers/workers.go | 7 ++++++- workers/workers_test.go | 4 ---- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/workers/worker_list_test.go b/workers/worker_list_test.go index 92ce1fa..96b85cb 100644 --- a/workers/worker_list_test.go +++ b/workers/worker_list_test.go @@ -261,5 +261,29 @@ var _ = Describe("WorkerList", func() { } }) }) + + Describe("SetGroups", func() { + It("should fail to SetGroup of nonexistent worker", func() { + uuid := randomUUID() + err := wl.SetGroups(uuid, nil) + Expect(err).To(Equal(ErrWorkerNotFound)) + }) + + It("should work to SetGroup", func() { + var group Groups = []Group{ + Group("group1"), + } + + By("setting it") + err := wl.SetGroups(worker, group) + Expect(err).ToNot(HaveOccurred()) + Expect(wl.workers[worker].Groups).To(Equal(group)) + + By("setting it to nil") + err = wl.SetGroups(worker, nil) + Expect(err).ToNot(HaveOccurred()) + Expect(wl.workers[worker].Groups).To(BeNil()) + }) + }) }) }) diff --git a/workers/workers.go b/workers/workers.go index b265f73..220950b 100644 --- a/workers/workers.go +++ b/workers/workers.go @@ -96,7 +96,12 @@ func (wl *WorkerList) SetState(uuid WorkerUUID, state WorkerState) error { // SetGroups is an implementation of SetGroups from Workers interface. func (wl *WorkerList) SetGroups(uuid WorkerUUID, groups Groups) error { - return ErrNotImplemented + worker, ok := wl.workers[uuid] + if !ok { + return ErrWorkerNotFound + } + worker.Groups = groups + return nil } // Deregister is an implementation of Deregister from Workers interface. diff --git a/workers/workers_test.go b/workers/workers_test.go index 8247544..f9674ee 100644 --- a/workers/workers_test.go +++ b/workers/workers_test.go @@ -38,10 +38,6 @@ var _ = Describe("WorkerList", func() { groups Groups = nil ) - By("SetGroups") - err = wl.SetGroups(uuid, groups) - Expect(err).To(Equal(ErrNotImplemented)) - By("ListWorkers") _, err = wl.ListWorkers(groups, caps) Expect(err).To(Equal(ErrNotImplemented)) -- 2.7.4