kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 1 | /* |
Joey Armstrong | f9bffdf | 2022-12-27 07:05:28 -0500 | [diff] [blame] | 2 | * Copyright 2018-2023 Open Networking Foundation (ONF) and the ONF Contributors |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 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 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 25 | config "github.com/opencord/voltha-protos/v5/go/ext/config" |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 26 | "github.com/opencord/voltha-protos/v5/go/extension" |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 27 | openolt "github.com/opencord/voltha-protos/v5/go/openolt" |
| 28 | tech_profile "github.com/opencord/voltha-protos/v5/go/tech_profile" |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 29 | "google.golang.org/grpc" |
| 30 | "google.golang.org/grpc/metadata" |
| 31 | ) |
| 32 | |
| 33 | // MockOpenoltClient mock struct for OpenoltClient. |
| 34 | type MockOpenoltClient struct { |
Gamze Abaka | c2c32a6 | 2021-03-11 11:44:18 +0000 | [diff] [blame] | 35 | counter int |
| 36 | IsRestarted bool |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | // DisableOlt mocks the DisableOlt function of Openoltclient. |
| 40 | func (ooc *MockOpenoltClient) DisableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 41 | //return &openolt.Empty{}, nil |
| 42 | if ooc.counter == 0 { |
| 43 | ooc.counter++ |
| 44 | return &openolt.Empty{}, nil |
| 45 | } |
| 46 | return nil, errors.New("disableOlt failed") |
| 47 | } |
| 48 | |
| 49 | // ReenableOlt mocks the ReenableOlt function of Openoltclient. |
| 50 | func (ooc *MockOpenoltClient) ReenableOlt(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 51 | if ooc.counter == 0 { |
| 52 | ooc.counter++ |
| 53 | return &openolt.Empty{}, nil |
| 54 | } |
| 55 | return nil, errors.New("reenable olt failed") |
| 56 | } |
| 57 | |
| 58 | // ActivateOnu mocks the ActivateOnu function of Openoltclient. |
| 59 | func (ooc *MockOpenoltClient) ActivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 60 | if in == nil { |
| 61 | return nil, errors.New("invalid onuId") |
| 62 | } |
| 63 | return &openolt.Empty{}, nil |
| 64 | } |
| 65 | |
| 66 | // DeactivateOnu mocks the DeactivateOnu function of Openoltclient. |
| 67 | func (ooc *MockOpenoltClient) DeactivateOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 68 | return &openolt.Empty{}, nil |
| 69 | } |
| 70 | |
| 71 | // DeleteOnu mocks the DeleteOnu function of Openoltclient. |
| 72 | func (ooc *MockOpenoltClient) DeleteOnu(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 73 | return &openolt.Empty{}, nil |
| 74 | } |
| 75 | |
| 76 | // OmciMsgOut mocks the OmciMsgOut function of Openoltclient. |
| 77 | func (ooc *MockOpenoltClient) OmciMsgOut(ctx context.Context, in *openolt.OmciMsg, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 78 | if in == nil { |
| 79 | return nil, errors.New("invalid Omci Msg") |
| 80 | } |
| 81 | return &openolt.Empty{}, nil |
| 82 | } |
| 83 | |
| 84 | // OnuPacketOut mocks the OnuPacketOut function of Openoltclient. |
| 85 | func (ooc *MockOpenoltClient) OnuPacketOut(ctx context.Context, in *openolt.OnuPacket, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 86 | return &openolt.Empty{}, nil |
| 87 | } |
| 88 | |
| 89 | // UplinkPacketOut mocks the UplinkPacketOut function of Openoltclient. |
| 90 | func (ooc *MockOpenoltClient) UplinkPacketOut(ctx context.Context, in *openolt.UplinkPacket, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 91 | return &openolt.Empty{}, nil |
| 92 | } |
| 93 | |
| 94 | // FlowAdd mocks the FlowAdd function of Openoltclient. |
| 95 | func (ooc *MockOpenoltClient) FlowAdd(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 96 | return &openolt.Empty{}, nil |
| 97 | } |
| 98 | |
| 99 | // FlowRemove mocks the FlowRemove function of Openoltclient. |
| 100 | func (ooc *MockOpenoltClient) FlowRemove(ctx context.Context, in *openolt.Flow, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 101 | return &openolt.Empty{}, nil |
| 102 | } |
| 103 | |
| 104 | // HeartbeatCheck mocks the HeartbeatCheck function of Openoltclient. |
| 105 | func (ooc *MockOpenoltClient) HeartbeatCheck(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Heartbeat, error) { |
| 106 | return nil, nil |
| 107 | } |
| 108 | |
| 109 | // EnablePonIf mocks the EnablePonIf function of Openoltclient. |
| 110 | func (ooc *MockOpenoltClient) EnablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 111 | return &openolt.Empty{}, nil |
| 112 | } |
| 113 | |
| 114 | // DisablePonIf mocks the DisablePonIf function of Openoltclient. |
| 115 | func (ooc *MockOpenoltClient) DisablePonIf(ctx context.Context, in *openolt.Interface, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 116 | return &openolt.Empty{}, nil |
| 117 | } |
| 118 | |
| 119 | // GetDeviceInfo mocks the GetDeviceInfo function of Openoltclient. |
| 120 | func (ooc *MockOpenoltClient) GetDeviceInfo(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.DeviceInfo, error) { |
| 121 | if ooc.counter == 0 { |
| 122 | ooc.counter++ |
| 123 | deviceInfo := &openolt.DeviceInfo{Vendor: "Openolt", Model: "1.0", HardwareVersion: "1.0", FirmwareVersion: "1.0", DeviceId: "olt", DeviceSerialNumber: "olt"} |
| 124 | return deviceInfo, nil |
| 125 | } |
| 126 | if ooc.counter == 1 { |
| 127 | ooc.counter++ |
| 128 | deviceInfo := &openolt.DeviceInfo{Vendor: "Openolt", Model: "1.0", HardwareVersion: "1.0", FirmwareVersion: "1.0", DeviceId: "", DeviceSerialNumber: "olt"} |
| 129 | return deviceInfo, nil |
| 130 | } |
| 131 | if ooc.counter == 2 { |
| 132 | ooc.counter++ |
| 133 | return nil, nil |
| 134 | } |
| 135 | |
| 136 | return nil, errors.New("device info not found") |
| 137 | } |
| 138 | |
| 139 | // Reboot mocks the Reboot function of Openoltclient. |
| 140 | func (ooc *MockOpenoltClient) Reboot(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 141 | if ooc.counter == 0 { |
| 142 | ooc.counter++ |
Gamze Abaka | c2c32a6 | 2021-03-11 11:44:18 +0000 | [diff] [blame] | 143 | ooc.IsRestarted = true |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 144 | return &openolt.Empty{}, nil |
| 145 | } |
| 146 | return nil, errors.New("reboot failed") |
| 147 | } |
| 148 | |
| 149 | // CollectStatistics mocks the CollectStatistics function of Openoltclient. |
| 150 | func (ooc *MockOpenoltClient) CollectStatistics(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 151 | return &openolt.Empty{}, nil |
| 152 | } |
| 153 | |
| 154 | // CreateTrafficSchedulers mocks the CreateTrafficSchedulers function of Openoltclient. |
| 155 | func (ooc *MockOpenoltClient) CreateTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 156 | return &openolt.Empty{}, nil |
| 157 | } |
| 158 | |
| 159 | // RemoveTrafficSchedulers mocks the RemoveTrafficSchedulers function of Openoltclient. |
| 160 | func (ooc *MockOpenoltClient) RemoveTrafficSchedulers(ctx context.Context, in *tech_profile.TrafficSchedulers, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 161 | return &openolt.Empty{}, nil |
| 162 | } |
| 163 | |
| 164 | // CreateTrafficQueues mocks the CreateTrafficQueues function of Openoltclient. |
| 165 | func (ooc *MockOpenoltClient) CreateTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 166 | return &openolt.Empty{}, nil |
| 167 | } |
| 168 | |
| 169 | // RemoveTrafficQueues mocks the RemoveTrafficQueues function of Openoltclient. |
| 170 | func (ooc *MockOpenoltClient) RemoveTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 171 | return &openolt.Empty{}, nil |
| 172 | } |
| 173 | |
Girish Gowdra | 631ef3d | 2020-06-15 10:45:52 -0700 | [diff] [blame] | 174 | // DeleteGroup mocks the DeleteGroup RPC of Openoltclient. |
| 175 | func (ooc *MockOpenoltClient) DeleteGroup(ctx context.Context, in *openolt.Group, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 176 | return &openolt.Empty{}, nil |
| 177 | } |
| 178 | |
| 179 | // GetLogicalOnuDistance mocks the GetLogicalOnuDistance RPC of Openoltclient. |
| 180 | func (ooc *MockOpenoltClient) GetLogicalOnuDistance(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuLogicalDistance, error) { |
| 181 | return &openolt.OnuLogicalDistance{}, nil |
| 182 | } |
| 183 | |
| 184 | // GetLogicalOnuDistanceZero mocks the GetLogicalOnuDistanceZero RPC of Openoltclient. |
| 185 | func (ooc *MockOpenoltClient) GetLogicalOnuDistanceZero(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuLogicalDistance, error) { |
| 186 | return &openolt.OnuLogicalDistance{}, nil |
| 187 | } |
| 188 | |
kdarapu | 891693b | 2019-09-16 12:33:49 +0530 | [diff] [blame] | 189 | // EnableIndication mocks the EnableIndication function of Openoltclient. |
| 190 | func (ooc *MockOpenoltClient) EnableIndication(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (openolt.Openolt_EnableIndicationClient, error) { |
| 191 | if ooc.counter < 2 { |
| 192 | ooc.counter++ |
| 193 | mockInd := &mockOpenoltEnableIndicationClient{0} |
| 194 | return mockInd, nil |
| 195 | } |
| 196 | if ooc.counter == 2 { |
| 197 | ooc.counter++ |
| 198 | return nil, nil |
| 199 | } |
| 200 | return nil, errors.New("invalid method invocation") |
| 201 | } |
| 202 | |
| 203 | type mockOpenoltEnableIndicationClient struct { |
| 204 | count int |
| 205 | } |
| 206 | |
| 207 | func (mock *mockOpenoltEnableIndicationClient) Recv() (*openolt.Indication, error) { |
| 208 | if mock.count == 0 { |
| 209 | mock.count = mock.count + 1 |
| 210 | indi := &openolt.Indication{Data: &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "Down"}}} |
| 211 | return indi, nil |
| 212 | } |
| 213 | if mock.count == 1 { |
| 214 | mock.count = mock.count + 1 |
| 215 | return nil, errors.New("error, while processing indication") |
| 216 | } |
| 217 | |
| 218 | return nil, io.EOF |
| 219 | } |
| 220 | |
| 221 | func (mock *mockOpenoltEnableIndicationClient) Header() (metadata.MD, error) { |
| 222 | return nil, nil |
| 223 | } |
| 224 | |
| 225 | func (mock *mockOpenoltEnableIndicationClient) Trailer() metadata.MD { |
| 226 | return nil |
| 227 | } |
| 228 | |
| 229 | func (mock *mockOpenoltEnableIndicationClient) CloseSend() error { |
| 230 | return nil |
| 231 | } |
| 232 | |
| 233 | func (mock *mockOpenoltEnableIndicationClient) Context() context.Context { |
| 234 | return context.Background() |
| 235 | } |
| 236 | |
| 237 | func (mock *mockOpenoltEnableIndicationClient) SendMsg(m interface{}) error { |
| 238 | return nil |
| 239 | } |
| 240 | |
| 241 | func (mock *mockOpenoltEnableIndicationClient) RecvMsg(m interface{}) error { |
| 242 | return nil |
| 243 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 244 | |
Andrea Campanella | 9931ad6 | 2020-04-28 15:11:06 +0200 | [diff] [blame] | 245 | // GetExtValue mocks the GetExtValue function of Openoltclient. |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 246 | func (ooc *MockOpenoltClient) GetExtValue(ctx context.Context, in *openolt.ValueParam, opts ...grpc.CallOption) (*extension.ReturnValues, error) { |
| 247 | return &extension.ReturnValues{}, nil |
Andrea Campanella | 9931ad6 | 2020-04-28 15:11:06 +0200 | [diff] [blame] | 248 | } |
| 249 | |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 250 | // OnuItuPonAlarmSet mocks the OnuItuPonAlarmSet function of Openoltclient. |
kesavand | 494c208 | 2020-08-31 11:16:12 +0530 | [diff] [blame] | 251 | func (ooc *MockOpenoltClient) OnuItuPonAlarmSet(ctx context.Context, in *config.OnuItuPonAlarm, opts ...grpc.CallOption) (*openolt.Empty, error) { |
Gamze Abaka | 78a1d2a | 2020-04-27 10:17:27 +0000 | [diff] [blame] | 252 | return &openolt.Empty{}, nil |
| 253 | } |
| 254 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 255 | // PerformGroupOperation mocks the PerformGroupOperation function of Openoltclient. |
| 256 | func (ooc *MockOpenoltClient) PerformGroupOperation(ctx context.Context, in *openolt.Group, opts ...grpc.CallOption) (*openolt.Empty, error) { |
| 257 | return &openolt.Empty{}, nil |
| 258 | } |
Gamze Abaka | fcbd6e7 | 2020-12-17 13:25:16 +0000 | [diff] [blame] | 259 | |
| 260 | //GetOnuStatistics mocks the GetOnuStatistics function of Openoltclient. |
| 261 | func (ooc *MockOpenoltClient) GetOnuStatistics(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuStatistics, error) { |
| 262 | return &openolt.OnuStatistics{}, nil |
| 263 | } |
| 264 | |
| 265 | //GetGemPortStatistics mocks the GetGemPortStatistics function of Openoltclient. |
| 266 | func (ooc *MockOpenoltClient) GetGemPortStatistics(ctx context.Context, in *openolt.OnuPacket, opts ...grpc.CallOption) (*openolt.GemPortStatistics, error) { |
| 267 | return &openolt.GemPortStatistics{}, nil |
| 268 | } |
Himani Chawla | 2c8ae0f | 2021-05-18 23:27:00 +0530 | [diff] [blame] | 269 | |
| 270 | //GetPonRxPower mocks the GetPonRxPower function of Openoltclient. |
| 271 | func (ooc *MockOpenoltClient) GetPonRxPower(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.PonRxPowerData, error) { |
| 272 | return &openolt.PonRxPowerData{}, nil |
| 273 | } |