VOL-1838 Unit test cases for golang openolt adapter device_handler.go
1.Mocked AdapterproxyIntf and coreproxyIntf Interfaces for unit test cases.
2. Added few unit testcases for the device_handler.go functions
Change-Id: I793d94055d2c0480e614e918c064df51cdf0b0ae
diff --git a/mocks/mockAdapterProxy.go b/mocks/mockAdapterProxy.go
new file mode 100644
index 0000000..a91d361
--- /dev/null
+++ b/mocks/mockAdapterProxy.go
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+
+ * 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 mocks provides the mocks for openolt-adapter.
+package mocks
+
+import (
+ "context"
+ "errors"
+
+ "github.com/golang/protobuf/proto"
+ "github.com/opencord/voltha-protos/go/inter_container"
+)
+
+// MockAdapterProxy mocks the AdapterProxy interface.
+type MockAdapterProxy struct {
+}
+
+// SendInterAdapterMessage mocks SendInterAdapterMessage function.
+func (ma *MockAdapterProxy) SendInterAdapterMessage(ctx context.Context,
+ msg proto.Message,
+ msgType inter_container.InterAdapterMessageType_Types,
+ fromAdapter string,
+ toAdapter string,
+ toDeviceID string,
+ proxyDeviceID string,
+ messageID string) error {
+ //panic("implement me")
+ if ctx == nil || msg == nil || fromAdapter != "" ||
+ toAdapter != "" || toDeviceID != "" || proxyDeviceID != "" || messageID != "" {
+ return errors.New("sendInterAdapterMessage func parameters cannot be nil")
+ }
+ return nil
+}
diff --git a/mocks/mockCoreProxy.go b/mocks/mockCoreProxy.go
new file mode 100644
index 0000000..6abf628
--- /dev/null
+++ b/mocks/mockCoreProxy.go
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+
+ * 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 mocks provides the mocks for openolt-adapter.
+package mocks
+
+import (
+ "context"
+ "errors"
+
+ "github.com/opencord/voltha-go/kafka"
+ "github.com/opencord/voltha-protos/go/voltha"
+)
+
+// MockCoreProxy mocks the CoreProxy interface
+type MockCoreProxy struct {
+ // Values to be used in test can reside inside this structure
+ // TODO store relevant info in this, use this info for negative and positive tests
+}
+
+// UpdateCoreReference mock updatesCoreReference
+func (mp *MockCoreProxy) UpdateCoreReference(deviceID string, coreReference string) {
+ panic("implement me")
+}
+
+// DeleteCoreReference mock DeleteCoreReference function
+func (mp *MockCoreProxy) DeleteCoreReference(deviceID string) {
+ panic("implement me")
+}
+
+// GetCoreTopic implements mock GetCoreTopic
+func (mp *MockCoreProxy) GetCoreTopic(deviceID string) kafka.Topic {
+ panic("implement me")
+}
+
+// GetAdapterTopic implements mock GetAdapterTopic
+func (mp *MockCoreProxy) GetAdapterTopic(args ...string) kafka.Topic {
+ panic("implement me")
+}
+
+// RegisterAdapter implements mock RegisterAdapter
+func (mp *MockCoreProxy) RegisterAdapter(ctx context.Context, adapter *voltha.Adapter,
+ deviceTypes *voltha.DeviceTypes) error {
+ if ctx == nil || adapter == nil || deviceTypes == nil {
+
+ return errors.New("registerAdapter func parameters cannot be nil")
+ }
+ return nil
+
+}
+
+// DeviceUpdate implements mock DeviceUpdate
+func (mp *MockCoreProxy) DeviceUpdate(ctx context.Context, device *voltha.Device) error {
+ panic("implement me")
+}
+
+// PortCreated implements mock PortCreated
+func (mp *MockCoreProxy) PortCreated(ctx context.Context, deviceID string, port *voltha.Port) error {
+ panic("implement me")
+}
+
+// PortsStateUpdate implements mock PortsStateUpdate
+func (mp *MockCoreProxy) PortsStateUpdate(ctx context.Context, deviceID string, operStatus voltha.OperStatus_OperStatus) error {
+ panic("implement me")
+}
+
+// DeleteAllPorts implements mock DeleteAllPorts
+func (mp *MockCoreProxy) DeleteAllPorts(ctx context.Context, deviceID string) error {
+ panic("implement me")
+}
+
+// DeviceStateUpdate implements mock DeviceStateUpdate
+func (mp *MockCoreProxy) DeviceStateUpdate(ctx context.Context, deviceID string,
+ connStatus voltha.ConnectStatus_ConnectStatus, operStatus voltha.OperStatus_OperStatus) error {
+ panic("implement me")
+}
+
+// ChildDeviceDetected implements mock ChildDeviceDetected
+func (mp *MockCoreProxy) ChildDeviceDetected(ctx context.Context, parentDeviceID string, parentPortNo int,
+ childDeviceType string, channelID int, vendorID string, serialNumber string, onuID int64) (*voltha.Device, error) {
+ panic("implement me")
+}
+
+// ChildDevicesLost implements mock ChildDevicesLost
+func (mp *MockCoreProxy) ChildDevicesLost(ctx context.Context, parentDeviceID string) error {
+ panic("implement me")
+}
+
+// ChildDevicesDetected implements mock ChildDevicesDetecte
+func (mp *MockCoreProxy) ChildDevicesDetected(ctx context.Context, parentDeviceID string) error {
+ panic("implement me")
+}
+
+// GetDevice implements mock GetDevice
+func (mp *MockCoreProxy) GetDevice(ctx context.Context, parentDeviceID string, deviceID string) (*voltha.Device, error) {
+ if parentDeviceID != "" {
+ return &voltha.Device{}, nil
+ }
+ return nil, errors.New("device detection failed")
+}
+
+// GetChildDevice implements mock GetChildDevice
+func (mp *MockCoreProxy) GetChildDevice(ctx context.Context, parentDeviceID string, kwargs map[string]interface{}) (*voltha.Device, error) {
+ if parentDeviceID != "" {
+ return &voltha.Device{}, nil
+ }
+ return nil, errors.New("device detection failed")
+}
+
+// GetChildDevices implements mock GetChildDevices
+func (mp *MockCoreProxy) GetChildDevices(ctx context.Context, parentDeviceID string) (*voltha.Devices, error) {
+ if parentDeviceID != "" {
+ return &voltha.Devices{}, nil
+ }
+ return nil, errors.New("device detection failed")
+}
+
+// SendPacketIn implements mock SendPacketIn
+func (mp *MockCoreProxy) SendPacketIn(ctx context.Context, deviceID string, port uint32, pktPayload []byte) error {
+ panic("implement me")
+}