Implement get information about the Worker
authorAleksander Mistewicz <a.mistewicz@samsung.com>
Thu, 8 Jun 2017 15:28:51 +0000 (17:28 +0200)
committerMaciej Wereski <m.wereski@partner.samsung.com>
Wed, 4 Oct 2017 08:18:44 +0000 (10:18 +0200)
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 <a.mistewicz@samsung.com>
Reviewed-on: https://mcdsrvbld02.digital.local/review/49062
Reviewed-by: Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Tested-by: Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Reviewed-by: Maciej Wereski <m.wereski@partner.samsung.com>
Tested-by: Maciej Wereski <m.wereski@partner.samsung.com>
workers/worker_list_test.go
workers/workers.go
workers/workers_test.go [deleted file]

index d7b2500..f7a3c62 100644 (file)
@@ -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]))
+                       })
+               })
        })
 })
index 1192b28..e3987e0 100644 (file)
@@ -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 (file)
index cf3c5c3..0000000
+++ /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))
-       })
-})