kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | //Package mocks provides the mocks for openolt-adapter. |
| 18 | package mocks |
| 19 | |
| 20 | import ( |
| 21 | "context" |
| 22 | "errors" |
| 23 | "io" |
| 24 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 25 | openolt "github.com/opencord/voltha-protos/v3/go/openolt" |
| 26 | tech_profile "github.com/opencord/voltha-protos/v3/go/tech_profile" |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 27 | "google.golang.org/grpc" |
| 28 | "google.golang.org/grpc/metadata" |
| 29 | ) |
| 30 | |
| 31 | // MockOpenoltClient mock struct for OpenoltClient. |
| 32 | type MockOpenoltClient struct { |
| 33 | counter int |
| 34 | } |
| 35 | |
| 36 | // DisableOlt mocks the DisableOlt function of Openoltclient. |
| 37 | func (ooc *MockOpenoltClient) DisableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 38 | //return &openolt.Empty{}, nil |
| 39 | if ooc.counter == 0 { |
| 40 | ooc.counter++ |
| 41 | return &openolt.Empty{}, nil |
| 42 | } |
| 43 | return nil, errors.New("disableOlt failed") |
| 44 | } |
| 45 | |
| 46 | // ReenableOlt mocks the ReenableOlt function of Openoltclient. |
| 47 | func (ooc *MockOpenoltClient) ReenableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 48 | if ooc.counter == 0 { |
| 49 | ooc.counter++ |
| 50 | return &openolt.Empty{}, nil |
| 51 | } |
| 52 | return nil, errors.New("reenable olt failed") |
| 53 | } |
| 54 | |
| 55 | // ActivateOnu mocks the ActivateOnu function of Openoltclient. |
| 56 | func (ooc *MockOpenoltClient) ActivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 57 | if in == nil { |
| 58 | return nil, errors.New("invalid onuId") |
| 59 | } |
| 60 | return &openolt.Empty{}, nil |
| 61 | } |
| 62 | |
| 63 | // DeactivateOnu mocks the DeactivateOnu function of Openoltclient. |
| 64 | func (ooc *MockOpenoltClient) DeactivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 65 | return &openolt.Empty{}, nil |
| 66 | } |
| 67 | |
| 68 | // DeleteOnu mocks the DeleteOnu function of Openoltclient. |
| 69 | func (ooc *MockOpenoltClient) DeleteOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 70 | return &openolt.Empty{}, nil |
| 71 | } |
| 72 | |
| 73 | // OmciMsgOut mocks the OmciMsgOut function of Openoltclient. |
| 74 | func (ooc *MockOpenoltClient) OmciMsgOut(ctx context.Context, in *openolt.OmciMsg, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 75 | if in == nil { |
| 76 | return nil, errors.New("invalid Omci Msg") |
| 77 | } |
| 78 | return &openolt.Empty{}, nil |
| 79 | } |
| 80 | |
| 81 | // OnuPacketOut mocks the OnuPacketOut function of Openoltclient. |
| 82 | func (ooc *MockOpenoltClient) OnuPacketOut(ctx context.Context, in *openolt.OnuPacket, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 83 | return &openolt.Empty{}, nil |
| 84 | } |
| 85 | |
| 86 | // UplinkPacketOut mocks the UplinkPacketOut function of Openoltclient. |
| 87 | func (ooc *MockOpenoltClient) UplinkPacketOut(ctx context.Context, in *openolt.UplinkPacket, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 88 | return &openolt.Empty{}, nil |
| 89 | } |
| 90 | |
| 91 | // FlowAdd mocks the FlowAdd function of Openoltclient. |
| 92 | func (ooc *MockOpenoltClient) FlowAdd(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 93 | return &openolt.Empty{}, nil |
| 94 | } |
| 95 | |
| 96 | // FlowRemove mocks the FlowRemove function of Openoltclient. |
| 97 | func (ooc *MockOpenoltClient) FlowRemove(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 98 | return &openolt.Empty{}, nil |
| 99 | } |
| 100 | |
| 101 | // HeartbeatCheck mocks the HeartbeatCheck function of Openoltclient. |
| 102 | func (ooc *MockOpenoltClient) HeartbeatCheck(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Heartbeat, error) { |
| 103 | return nil, nil |
| 104 | } |
| 105 | |
| 106 | // EnablePonIf mocks the EnablePonIf function of Openoltclient. |
| 107 | func (ooc *MockOpenoltClient) EnablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 108 | return &openolt.Empty{}, nil |
| 109 | } |
| 110 | |
| 111 | // DisablePonIf mocks the DisablePonIf function of Openoltclient. |
| 112 | func (ooc *MockOpenoltClient) DisablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 113 | return &openolt.Empty{}, nil |
| 114 | } |
| 115 | |
| 116 | // GetDeviceInfo mocks the GetDeviceInfo function of Openoltclient. |
| 117 | func (ooc *MockOpenoltClient) GetDeviceInfo(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.DeviceInfo, error) { |
| 118 | if ooc.counter == 0 { |
| 119 | ooc.counter++ |
| 120 | deviceInfo := &openolt.DeviceInfo{Vendor: "Openolt", Model: "1.0", HardwareVersion: "1.0", FirmwareVersion: "1.0", DeviceId: "olt", DeviceSerialNumber: "olt"} |
| 121 | return deviceInfo, nil |
| 122 | } |
| 123 | if ooc.counter == 1 { |
| 124 | ooc.counter++ |
| 125 | deviceInfo := &openolt.DeviceInfo{Vendor: "Openolt", Model: "1.0", HardwareVersion: "1.0", FirmwareVersion: "1.0", DeviceId: "", DeviceSerialNumber: "olt"} |
| 126 | return deviceInfo, nil |
| 127 | } |
| 128 | if ooc.counter == 2 { |
| 129 | ooc.counter++ |
| 130 | return nil, nil |
| 131 | } |
| 132 | |
| 133 | return nil, errors.New("device info not found") |
| 134 | } |
| 135 | |
| 136 | // Reboot mocks the Reboot function of Openoltclient. |
| 137 | func (ooc *MockOpenoltClient) Reboot(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 138 | if ooc.counter == 0 { |
| 139 | ooc.counter++ |
| 140 | return &openolt.Empty{}, nil |
| 141 | } |
| 142 | return nil, errors.New("reboot failed") |
| 143 | } |
| 144 | |
| 145 | // CollectStatistics mocks the CollectStatistics function of Openoltclient. |
| 146 | func (ooc *MockOpenoltClient) CollectStatistics(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 147 | return &openolt.Empty{}, nil |
| 148 | } |
| 149 | |
| 150 | // CreateTrafficSchedulers mocks the CreateTrafficSchedulers function of Openoltclient. |
| 151 | func (ooc *MockOpenoltClient) CreateTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 152 | return &openolt.Empty{}, nil |
| 153 | } |
| 154 | |
| 155 | // RemoveTrafficSchedulers mocks the RemoveTrafficSchedulers function of Openoltclient. |
| 156 | func (ooc *MockOpenoltClient) RemoveTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 157 | return &openolt.Empty{}, nil |
| 158 | } |
| 159 | |
| 160 | // CreateTrafficQueues mocks the CreateTrafficQueues function of Openoltclient. |
| 161 | func (ooc *MockOpenoltClient) CreateTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 162 | return &openolt.Empty{}, nil |
| 163 | } |
| 164 | |
| 165 | // RemoveTrafficQueues mocks the RemoveTrafficQueues function of Openoltclient. |
| 166 | func (ooc *MockOpenoltClient) RemoveTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 167 | return &openolt.Empty{}, nil |
| 168 | } |
| 169 | |
Girish Gowdra | 631ef3d | 2020-06-15 10:45:52 -0700 | [diff] [blame] | 170 | // DeleteGroup mocks the DeleteGroup RPC of Openoltclient. |
| 171 | func (ooc *MockOpenoltClient) DeleteGroup(ctx context.Context, in *openolt.Group, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 172 | return &openolt.Empty{}, nil |
| 173 | } |
| 174 | |
| 175 | // GetLogicalOnuDistance mocks the GetLogicalOnuDistance RPC of Openoltclient. |
| 176 | func (ooc *MockOpenoltClient) GetLogicalOnuDistance(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuLogicalDistance, error) { |
| 177 | return &openolt.OnuLogicalDistance{}, nil |
| 178 | } |
| 179 | |
| 180 | // GetLogicalOnuDistanceZero mocks the GetLogicalOnuDistanceZero RPC of Openoltclient. |
| 181 | func (ooc *MockOpenoltClient) GetLogicalOnuDistanceZero(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuLogicalDistance, error) { |
| 182 | return &openolt.OnuLogicalDistance{}, nil |
| 183 | } |
| 184 | |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 185 | // EnableIndication mocks the EnableIndication function of Openoltclient. |
| 186 | func (ooc *MockOpenoltClient) EnableIndication(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (openolt.Openolt_EnableIndicationClient, error) { |
| 187 | if ooc.counter < 2 { |
| 188 | ooc.counter++ |
| 189 | mockInd := &mockOpenoltEnableIndicationClient{0} |
| 190 | return mockInd, nil |
| 191 | } |
| 192 | if ooc.counter == 2 { |
| 193 | ooc.counter++ |
| 194 | return nil, nil |
| 195 | } |
| 196 | return nil, errors.New("invalid method invocation") |
| 197 | } |
| 198 | |
| 199 | type mockOpenoltEnableIndicationClient struct { |
| 200 | count int |
| 201 | } |
| 202 | |
| 203 | func (mock *mockOpenoltEnableIndicationClient) Recv() (*openolt.Indication, error) { |
| 204 | if mock.count == 0 { |
| 205 | mock.count = mock.count + 1 |
| 206 | indi := &openolt.Indication{Data: &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "Down"}}} |
| 207 | return indi, nil |
| 208 | } |
| 209 | if mock.count == 1 { |
| 210 | mock.count = mock.count + 1 |
| 211 | return nil, errors.New("error, while processing indication") |
| 212 | } |
| 213 | |
| 214 | return nil, io.EOF |
| 215 | } |
| 216 | |
| 217 | func (mock *mockOpenoltEnableIndicationClient) Header() (metadata.MD, error) { |
| 218 | return nil, nil |
| 219 | } |
| 220 | |
| 221 | func (mock *mockOpenoltEnableIndicationClient) Trailer() metadata.MD { |
| 222 | return nil |
| 223 | } |
| 224 | |
| 225 | func (mock *mockOpenoltEnableIndicationClient) CloseSend() error { |
| 226 | return nil |
| 227 | } |
| 228 | |
| 229 | func (mock *mockOpenoltEnableIndicationClient) Context() context.Context { |
| 230 | return context.Background() |
| 231 | } |
| 232 | |
| 233 | func (mock *mockOpenoltEnableIndicationClient) SendMsg(m interface{}) error { |
| 234 | return nil |
| 235 | } |
| 236 | |
| 237 | func (mock *mockOpenoltEnableIndicationClient) RecvMsg(m interface{}) error { |
| 238 | return nil |
| 239 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 240 | |
Andrea Campanella | 9931ad6 | 2020-04-28 15:11:06 +0200 | [diff] [blame] | 241 | // GetExtValue mocks the GetExtValue function of Openoltclient. |
| 242 | func (ooc *MockOpenoltClient) GetExtValue(ctx context.Context, in *openolt.ValueParam, opts ...grpc.CallOption) (*openolt.ReturnValues, error) { |
| 243 | return &openolt.ReturnValues{}, nil |
| 244 | } |
| 245 | |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 246 | // OnuItuPonAlarmSet mocks the OnuItuPonAlarmSet function of Openoltclient. |
| 247 | func (ooc *MockOpenoltClient) OnuItuPonAlarmSet(ctx context.Context, in *openolt.OnuItuPonAlarm, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 248 | return &openolt.Empty{}, nil |
| 249 | } |
| 250 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 251 | // PerformGroupOperation mocks the PerformGroupOperation function of Openoltclient. |
| 252 | func (ooc *MockOpenoltClient) PerformGroupOperation(ctx context.Context, in *openolt.Group, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 253 | return &openolt.Empty{}, nil |
| 254 | } |