From 66ba7c6371ee9590e8c2cb0ade26e434e8a01617 Mon Sep 17 00:00:00 2001 From: Lukasz Wojciechowski Date: Fri, 6 Oct 2017 20:52:00 +0200 Subject: [PATCH] Add WorkersManager interface WorkersManager interface defines API for taking actions triggered by matcher events on workers structures. The mock implementation of interface is provided in matcher package. It is generated using mockgen command: mockgen -package matcher \ -destination=matcher/workersmanager_mock_test.go \ -write_package_comment=false \ git.tizen.org/tools/boruta/matcher WorkersManager Change-Id: I026c661696b19a3443afc430e46d96abf9a272d5 Signed-off-by: Lukasz Wojciechowski --- matcher/workersmanager.go | 54 +++++++++++++++++++++ matcher/workersmanager_mock_test.go | 97 +++++++++++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 matcher/workersmanager.go create mode 100644 matcher/workersmanager_mock_test.go diff --git a/matcher/workersmanager.go b/matcher/workersmanager.go new file mode 100644 index 0000000..5214abc --- /dev/null +++ b/matcher/workersmanager.go @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2017-2018 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 + */ + +// File matcher/workersmanager.go defines WorkersManager interface with API +// for taking actions triggered by matcher events on workers structures. + +package matcher + +import ( + "crypto/rsa" + "net" + + . "git.tizen.org/tools/boruta" + "git.tizen.org/tools/boruta/workers" +) + +// WorkersManager defines API for internal boruta management of workers. +type WorkersManager interface { + // TakeBestMatchingWorker returns best matching worker that meets a criteria. + // An error is returned if no matching worker is found. + TakeBestMatchingWorker(Groups, Capabilities) (WorkerUUID, error) + + // PrepareWorker makes it ready for running a job. + // Caller of this method can decide (with 2nd parameter) if key generation + // is required for preparing worker. + PrepareWorker(worker WorkerUUID, withKeyGeneration bool) error + + // GetWorkerIP returns IP of the worker that can be used for setting up tunnel + // to the worker. If there is no worker with given WorkerUUID an error + // is returned. + GetWorkerIP(WorkerUUID) (net.IP, error) + + // GetWorkerKey returns private RSA key of the worker that can be used for + // accessing the worker. If there is no worker with given WorkerUUID an error + // is returned. + GetWorkerKey(WorkerUUID) (rsa.PrivateKey, error) + + // SetChangeListener stores reference to object, which should be notified + // in case of changes of workers' states. + SetChangeListener(workers.WorkerChange) +} diff --git a/matcher/workersmanager_mock_test.go b/matcher/workersmanager_mock_test.go new file mode 100644 index 0000000..17e5f54 --- /dev/null +++ b/matcher/workersmanager_mock_test.go @@ -0,0 +1,97 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: git.tizen.org/tools/boruta/matcher (interfaces: WorkersManager) + +package matcher + +import ( + rsa "crypto/rsa" + boruta "git.tizen.org/tools/boruta" + workers "git.tizen.org/tools/boruta/workers" + gomock "github.com/golang/mock/gomock" + net "net" + reflect "reflect" +) + +// MockWorkersManager is a mock of WorkersManager interface +type MockWorkersManager struct { + ctrl *gomock.Controller + recorder *MockWorkersManagerMockRecorder +} + +// MockWorkersManagerMockRecorder is the mock recorder for MockWorkersManager +type MockWorkersManagerMockRecorder struct { + mock *MockWorkersManager +} + +// NewMockWorkersManager creates a new mock instance +func NewMockWorkersManager(ctrl *gomock.Controller) *MockWorkersManager { + mock := &MockWorkersManager{ctrl: ctrl} + mock.recorder = &MockWorkersManagerMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockWorkersManager) EXPECT() *MockWorkersManagerMockRecorder { + return m.recorder +} + +// GetWorkerIP mocks base method +func (m *MockWorkersManager) GetWorkerIP(arg0 boruta.WorkerUUID) (net.IP, error) { + ret := m.ctrl.Call(m, "GetWorkerIP", arg0) + ret0, _ := ret[0].(net.IP) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetWorkerIP indicates an expected call of GetWorkerIP +func (mr *MockWorkersManagerMockRecorder) GetWorkerIP(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetWorkerIP", reflect.TypeOf((*MockWorkersManager)(nil).GetWorkerIP), arg0) +} + +// GetWorkerKey mocks base method +func (m *MockWorkersManager) GetWorkerKey(arg0 boruta.WorkerUUID) (rsa.PrivateKey, error) { + ret := m.ctrl.Call(m, "GetWorkerKey", arg0) + ret0, _ := ret[0].(rsa.PrivateKey) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetWorkerKey indicates an expected call of GetWorkerKey +func (mr *MockWorkersManagerMockRecorder) GetWorkerKey(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetWorkerKey", reflect.TypeOf((*MockWorkersManager)(nil).GetWorkerKey), arg0) +} + +// PrepareWorker mocks base method +func (m *MockWorkersManager) PrepareWorker(arg0 boruta.WorkerUUID, arg1 bool) error { + ret := m.ctrl.Call(m, "PrepareWorker", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// PrepareWorker indicates an expected call of PrepareWorker +func (mr *MockWorkersManagerMockRecorder) PrepareWorker(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PrepareWorker", reflect.TypeOf((*MockWorkersManager)(nil).PrepareWorker), arg0, arg1) +} + +// SetChangeListener mocks base method +func (m *MockWorkersManager) SetChangeListener(arg0 workers.WorkerChange) { + m.ctrl.Call(m, "SetChangeListener", arg0) +} + +// SetChangeListener indicates an expected call of SetChangeListener +func (mr *MockWorkersManagerMockRecorder) SetChangeListener(arg0 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetChangeListener", reflect.TypeOf((*MockWorkersManager)(nil).SetChangeListener), arg0) +} + +// TakeBestMatchingWorker mocks base method +func (m *MockWorkersManager) TakeBestMatchingWorker(arg0 boruta.Groups, arg1 boruta.Capabilities) (boruta.WorkerUUID, error) { + ret := m.ctrl.Call(m, "TakeBestMatchingWorker", arg0, arg1) + ret0, _ := ret[0].(boruta.WorkerUUID) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// TakeBestMatchingWorker indicates an expected call of TakeBestMatchingWorker +func (mr *MockWorkersManagerMockRecorder) TakeBestMatchingWorker(arg0, arg1 interface{}) *gomock.Call { + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TakeBestMatchingWorker", reflect.TypeOf((*MockWorkersManager)(nil).TakeBestMatchingWorker), arg0, arg1) +} -- 2.7.4