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