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 | |
| 25 | openolt "github.com/opencord/voltha-protos/go/openolt" |
| 26 | tech_profile "github.com/opencord/voltha-protos/go/tech_profile" |
| 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 | |
| 170 | // EnableIndication mocks the EnableIndication function of Openoltclient. |
| 171 | func (ooc *MockOpenoltClient) EnableIndication(ctx context.Context, in *openolt.Empty, opts ...grpc.CallOption) (openolt.Openolt_EnableIndicationClient, error) { |
| 172 | if ooc.counter < 2 { |
| 173 | ooc.counter++ |
| 174 | mockInd := &mockOpenoltEnableIndicationClient{0} |
| 175 | return mockInd, nil |
| 176 | } |
| 177 | if ooc.counter == 2 { |
| 178 | ooc.counter++ |
| 179 | return nil, nil |
| 180 | } |
| 181 | return nil, errors.New("invalid method invocation") |
| 182 | } |
| 183 | |
| 184 | type mockOpenoltEnableIndicationClient struct { |
| 185 | count int |
| 186 | } |
| 187 | |
| 188 | func (mock *mockOpenoltEnableIndicationClient) Recv() (*openolt.Indication, error) { |
| 189 | if mock.count == 0 { |
| 190 | mock.count = mock.count + 1 |
| 191 | indi := &openolt.Indication{Data: &openolt.Indication_OltInd{OltInd: &openolt.OltIndication{OperState: "Down"}}} |
| 192 | return indi, nil |
| 193 | } |
| 194 | if mock.count == 1 { |
| 195 | mock.count = mock.count + 1 |
| 196 | return nil, errors.New("error, while processing indication") |
| 197 | } |
| 198 | |
| 199 | return nil, io.EOF |
| 200 | } |
| 201 | |
| 202 | func (mock *mockOpenoltEnableIndicationClient) Header() (metadata.MD, error) { |
| 203 | return nil, nil |
| 204 | } |
| 205 | |
| 206 | func (mock *mockOpenoltEnableIndicationClient) Trailer() metadata.MD { |
| 207 | return nil |
| 208 | } |
| 209 | |
| 210 | func (mock *mockOpenoltEnableIndicationClient) CloseSend() error { |
| 211 | return nil |
| 212 | } |
| 213 | |
| 214 | func (mock *mockOpenoltEnableIndicationClient) Context() context.Context { |
| 215 | return context.Background() |
| 216 | } |
| 217 | |
| 218 | func (mock *mockOpenoltEnableIndicationClient) SendMsg(m interface{}) error { |
| 219 | return nil |
| 220 | } |
| 221 | |
| 222 | func (mock *mockOpenoltEnableIndicationClient) RecvMsg(m interface{}) error { |
| 223 | return nil |
| 224 | } |