Add workers package
authorAleksander Mistewicz <a.mistewicz@samsung.com>
Thu, 8 Jun 2017 10:50:20 +0000 (12:50 +0200)
committerMaciej Wereski <m.wereski@partner.samsung.com>
Wed, 20 Sep 2017 08:39:22 +0000 (10:39 +0200)
Package workers is responsible for Workers list management. Moreover
it implements Superviser and Workers interfaces. It can be used either
directly from API handlers or indirectly through a decorator which can
add authentication layer. It can also be aggregated with implementation
of Requests interface to construct a implementation of Server.
Tests are added in order to achieve 100% coverage.

Change-Id: I268f9e61f7551993e279326a7bd33637248c453c
Signed-off-by: Aleksander Mistewicz <a.mistewicz@samsung.com>
Reviewed-on: https://mcdsrvbld02.digital.local/review/49055
Reviewed-by: Maciej Wereski <m.wereski@partner.samsung.com>
Tested-by: Maciej Wereski <m.wereski@partner.samsung.com>
workers/error.go [new file with mode: 0644]
workers/workers.go [new file with mode: 0644]
workers/workers_suite_test.go [new file with mode: 0644]
workers/workers_test.go [new file with mode: 0644]

diff --git a/workers/error.go b/workers/error.go
new file mode 100644 (file)
index 0000000..9141f5c
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ *  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
+
+import (
+       "errors"
+)
+
+var (
+       // ErrNotImplemented is returned when function is not implemented yet.
+       ErrNotImplemented = errors.New("function not implemented")
+)
diff --git a/workers/workers.go b/workers/workers.go
new file mode 100644 (file)
index 0000000..1fc6c54
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ *  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 is responsible for worker list management.
+package workers
+
+import (
+       . "git.tizen.org/tools/boruta"
+)
+
+// WorkerList implements Superviser and Workers interfaces.
+// It manages a list of Workers.
+type WorkerList struct {
+       Superviser
+       Workers
+       workers map[WorkerUUID]*WorkerInfo
+}
+
+// NewWorkerList returns a new WorkerList with all fields set.
+func NewWorkerList() *WorkerList {
+       return &WorkerList{
+               workers: make(map[WorkerUUID]*WorkerInfo),
+       }
+}
+
+// Register is an implementation of Register from Superviser interface.
+func (wl *WorkerList) Register(caps Capabilities) error {
+       return ErrNotImplemented
+}
+
+// SetFail is an implementation of SetFail from Superviser interface.
+func (wl *WorkerList) SetFail(uuid WorkerUUID, reason string) error {
+       return ErrNotImplemented
+}
+
+// SetState is an implementation of SetState from Workers interface.
+func (wl *WorkerList) SetState(uuid WorkerUUID, state WorkerState) error {
+       return ErrNotImplemented
+}
+
+// SetGroups is an implementation of SetGroups from Workers interface.
+func (wl *WorkerList) SetGroups(uuid WorkerUUID, groups Groups) error {
+       return ErrNotImplemented
+}
+
+// Deregister is an implementation of Deregister from Workers interface.
+func (wl *WorkerList) Deregister(uuid WorkerUUID) error {
+       return ErrNotImplemented
+}
+
+// ListWorkers is an implementation of ListWorkers from Workers interface.
+func (wl *WorkerList) ListWorkers(groups Groups, caps Capabilities) ([]WorkerInfo, error) {
+       return nil, ErrNotImplemented
+}
+
+// GetWorkerInfo is an implementation of GetWorkerInfo from Workers interface.
+func (wl *WorkerList) GetWorkerInfo(uuid WorkerUUID) (WorkerInfo, error) {
+       return WorkerInfo{}, ErrNotImplemented
+}
diff --git a/workers/workers_suite_test.go b/workers/workers_suite_test.go
new file mode 100644 (file)
index 0000000..39afe98
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ *  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 (
+       . "github.com/onsi/ginkgo"
+       . "github.com/onsi/gomega"
+
+       "testing"
+)
+
+func TestWorkerList(t *testing.T) {
+       RegisterFailHandler(Fail)
+       RunSpecs(t, "Workers Suite")
+}
diff --git a/workers/workers_test.go b/workers/workers_test.go
new file mode 100644 (file)
index 0000000..d3e7688
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ *  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   = ""
+                       caps   Capabilities = nil
+                       groups Groups       = nil
+               )
+
+               By("Register")
+               err = wl.Register(caps)
+               Expect(err).To(Equal(ErrNotImplemented))
+
+               By("SetFail")
+               err = wl.SetFail(uuid, "")
+               Expect(err).To(Equal(ErrNotImplemented))
+
+               By("SetState")
+               err = wl.SetState(uuid, MAINTENANCE)
+               Expect(err).To(Equal(ErrNotImplemented))
+
+               By("SetGroups")
+               err = wl.SetGroups(uuid, groups)
+               Expect(err).To(Equal(ErrNotImplemented))
+
+               By("Deregister")
+               err = wl.Deregister(uuid)
+               Expect(err).To(Equal(ErrNotImplemented))
+
+               By("ListWorkers")
+               _, err = wl.ListWorkers(groups, caps)
+               Expect(err).To(Equal(ErrNotImplemented))
+
+               By("GetWorkerInfo")
+               _, err = wl.GetWorkerInfo(uuid)
+               Expect(err).To(Equal(ErrNotImplemented))
+       })
+})