blob: faca16e6b47dc5bf22843455faced3658c2b5446 [file] [log] [blame]
kdarapu891693b2019-09-16 12:33:49 +05301/*
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.
18package mocks
19
20import (
21 "context"
22 "errors"
23 "io"
24
Esin Karamanccb714b2019-11-29 15:02:06 +000025 openolt "github.com/opencord/voltha-protos/v3/go/openolt"
26 tech_profile "github.com/opencord/voltha-protos/v3/go/tech_profile"
kdarapu891693b2019-09-16 12:33:49 +053027 "google.golang.org/grpc"
28 "google.golang.org/grpc/metadata"
29)
30
31// MockOpenoltClient mock struct for OpenoltClient.
32type MockOpenoltClient struct {
33 counter int
34}
35
36// DisableOlt mocks the DisableOlt function of Openoltclient.
37func (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.
47func (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.
56func (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.
64func (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.
69func (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.
74func (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.
82func (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.
87func (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.
92func (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.
97func (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.
102func (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.
107func (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.
112func (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.
117func (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.
137func (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.
146func (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.
151func (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.
156func (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.
161func (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.
166func (ooc *MockOpenoltClient) RemoveTrafficQueues(ctx context.Context, in *tech_profile.TrafficQueues, opts ...grpc.CallOption) (*openolt.Empty, error) {
167 return &openolt.Empty{}, nil
168}
169
Girish Gowdra631ef3d2020-06-15 10:45:52 -0700170// DeleteGroup mocks the DeleteGroup RPC of Openoltclient.
171func (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.
176func (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.
181func (ooc *MockOpenoltClient) GetLogicalOnuDistanceZero(ctx context.Context, in *openolt.Onu, opts ...grpc.CallOption) (*openolt.OnuLogicalDistance, error) {
182 return &openolt.OnuLogicalDistance{}, nil
183}
184
kdarapu891693b2019-09-16 12:33:49 +0530185// EnableIndication mocks the EnableIndication function of Openoltclient.
186func (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
199type mockOpenoltEnableIndicationClient struct {
200 count int
201}
202
203func (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
217func (mock *mockOpenoltEnableIndicationClient) Header() (metadata.MD, error) {
218 return nil, nil
219}
220
221func (mock *mockOpenoltEnableIndicationClient) Trailer() metadata.MD {
222 return nil
223}
224
225func (mock *mockOpenoltEnableIndicationClient) CloseSend() error {
226 return nil
227}
228
229func (mock *mockOpenoltEnableIndicationClient) Context() context.Context {
230 return context.Background()
231}
232
233func (mock *mockOpenoltEnableIndicationClient) SendMsg(m interface{}) error {
234 return nil
235}
236
237func (mock *mockOpenoltEnableIndicationClient) RecvMsg(m interface{}) error {
238 return nil
239}
Esin Karamanccb714b2019-11-29 15:02:06 +0000240
Andrea Campanella9931ad62020-04-28 15:11:06 +0200241// GetExtValue mocks the GetExtValue function of Openoltclient.
242func (ooc *MockOpenoltClient) GetExtValue(ctx context.Context, in *openolt.ValueParam, opts ...grpc.CallOption) (*openolt.ReturnValues, error) {
243 return &openolt.ReturnValues{}, nil
244}
245
Gamze Abaka78a1d2a2020-04-27 10:17:27 +0000246// OnuItuPonAlarmSet mocks the OnuItuPonAlarmSet function of Openoltclient.
247func (ooc *MockOpenoltClient) OnuItuPonAlarmSet(ctx context.Context, in *openolt.OnuItuPonAlarm, opts ...grpc.CallOption) (*openolt.Empty, error) {
248 return &openolt.Empty{}, nil
249}
250
Esin Karamanccb714b2019-11-29 15:02:06 +0000251// PerformGroupOperation mocks the PerformGroupOperation function of Openoltclient.
252func (ooc *MockOpenoltClient) PerformGroupOperation(ctx context.Context, in *openolt.Group, opts ...grpc.CallOption) (*openolt.Empty, error) {
253 return &openolt.Empty{}, nil
254}