From 256693fe3ea79184d58b36b92865ebd6ed7bc9dd Mon Sep 17 00:00:00 2001 From: Aleksander Mistewicz Date: Thu, 8 Jun 2017 17:28:51 +0200 Subject: [PATCH] Implement get information about the Worker In order to avoid listing workers when information about only one is needed, a convenience function has been added. It is faster and guarantees that a single structure will be returned or an error. workers/workers_test.go has been removed as all functions has been implemented. Change-Id: I0dfaccc4c55bdb30c5875de06db9d3b23b2345b2 Signed-off-by: Aleksander Mistewicz Reviewed-on: https://mcdsrvbld02.digital.local/review/49062 Reviewed-by: Lukasz Wojciechowski Tested-by: Lukasz Wojciechowski Reviewed-by: Maciej Wereski Tested-by: Maciej Wereski --- workers/worker_list_test.go | 14 ++++++++++++++ workers/workers.go | 6 +++++- workers/workers_test.go | 43 ------------------------------------------- 3 files changed, 19 insertions(+), 44 deletions(-) delete mode 100644 workers/workers_test.go diff --git a/workers/worker_list_test.go b/workers/worker_list_test.go index d7b2500..f7a3c62 100644 --- a/workers/worker_list_test.go +++ b/workers/worker_list_test.go @@ -432,5 +432,19 @@ var _ = Describe("WorkerList", func() { refWorkerList[2], refWorkerList[3], refWorkerList[5]}) }) }) + + Describe("GetWorkerInfo", func() { + It("should fail to GetWorkerInfo of nonexistent worker", func() { + uuid := randomUUID() + _, err := wl.GetWorkerInfo(uuid) + Expect(err).To(Equal(ErrWorkerNotFound)) + }) + + It("should work to GetWorkerInfo", func() { + workerInfo, err := wl.GetWorkerInfo(worker) + Expect(err).ToNot(HaveOccurred()) + Expect(workerInfo).To(Equal(*wl.workers[worker])) + }) + }) }) }) diff --git a/workers/workers.go b/workers/workers.go index 1192b28..e3987e0 100644 --- a/workers/workers.go +++ b/workers/workers.go @@ -217,5 +217,9 @@ func (wl *WorkerList) ListWorkers(groups Groups, caps Capabilities) ([]WorkerInf // GetWorkerInfo is an implementation of GetWorkerInfo from Workers interface. func (wl *WorkerList) GetWorkerInfo(uuid WorkerUUID) (WorkerInfo, error) { - return WorkerInfo{}, ErrNotImplemented + worker, ok := wl.workers[uuid] + if !ok { + return WorkerInfo{}, ErrWorkerNotFound + } + return *worker, nil } diff --git a/workers/workers_test.go b/workers/workers_test.go deleted file mode 100644 index cf3c5c3..0000000 --- a/workers/workers_test.go +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package workers_test - -import ( - . "git.tizen.org/tools/boruta" - . "git.tizen.org/tools/boruta/workers" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" -) - -var _ = Describe("WorkerList", func() { - var wl *WorkerList - BeforeEach(func() { - wl = NewWorkerList() - }) - - It("should return ErrNotImplemented", func() { - var ( - err error - uuid WorkerUUID = "" - ) - - By("GetWorkerInfo") - _, err = wl.GetWorkerInfo(uuid) - Expect(err).To(Equal(ErrNotImplemented)) - }) -}) -- 2.7.4