diff options
-rw-r--r-- | workers/worker_list_test.go | 24 | ||||
-rw-r--r-- | workers/workers.go | 7 | ||||
-rw-r--r-- | 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)) |