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