blob: 400176ab7e47ab93635a4d3b47df84b8087de24f [file] [log] [blame]
vinokumaf7605fc2023-06-02 18:08:01 +05301/*
2* Copyright 2022-present Open Networking Foundation
3* Licensed under the Apache License, Version 2.0 (the "License");
4* you may not use this file except in compliance with the License.
5* You may obtain a copy of the License at
6*
7* http://www.apache.org/licenses/LICENSE-2.0
8*
9* Unless required by applicable law or agreed to in writing, software
10* distributed under the License is distributed on an "AS IS" BASIS,
11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12* See the License for the specific language governing permissions and
13* limitations under the License.
14 */
15
16package application
17
18import (
19 "context"
20 "testing"
21 "voltha-go-controller/internal/pkg/intf"
22 "voltha-go-controller/internal/pkg/of"
23 "voltha-go-controller/internal/pkg/util"
24 "voltha-go-controller/internal/test/mocks"
25
26 "github.com/golang/mock/gomock"
27)
28
29var voltPortVnet = &VoltPortVnet{
30 Device: "test_device",
31}
32var voltService = &VoltService{
33 Version: "test_version",
34}
35
36func TestExecuteFlowEvent(t *testing.T) {
37 type args struct {
38 cntx context.Context
39 vd *VoltDevice
40 cookie string
41 flowStatus intf.FlowStatus
42 }
43 tests := []struct {
44 name string
45 args args
46 want bool
47 }{
48 {
49 name: "ExecuteFlowEvent_add",
50 args: args{
51 cntx: context.Background(),
52 vd: &VoltDevice{
53 SouthBoundID: "test_device_id",
54 FlowAddEventMap: util.NewConcurrentMap(),
55 },
56 cookie: "test_cookie",
57 flowStatus: intf.FlowStatus{
58 Device: "test_device",
59 FlowModType: of.CommandAdd,
60 },
61 },
62 },
63 {
64 name: "ExecuteFlowEvent_del",
65 args: args{
66 cntx: context.Background(),
67 vd: &VoltDevice{
68 SouthBoundID: "test_device_id",
69 FlowDelEventMap: util.NewConcurrentMap(),
70 },
71 cookie: "test_cookie",
72 flowStatus: intf.FlowStatus{
73 Device: "test_device",
74 FlowModType: of.CommandDel,
75 },
76 },
77 },
78 }
79 for _, tt := range tests {
80 t.Run(tt.name, func(t *testing.T) {
81 switch tt.name {
82 case "ExecuteFlowEvent_add":
83 if got := ExecuteFlowEvent(tt.args.cntx, tt.args.vd, tt.args.cookie, tt.args.flowStatus); got != tt.want {
84 t.Errorf("ExecuteFlowEvent() = %v, want %v", got, tt.want)
85 }
86 case "ExecuteFlowEvent_del":
87 if got := ExecuteFlowEvent(tt.args.cntx, tt.args.vd, tt.args.cookie, tt.args.flowStatus); got != tt.want {
88 t.Errorf("ExecuteFlowEvent() = %v, want %v", got, tt.want)
89 }
90 }
91 })
92 }
93}
94
95func TestInitEventFuncMapper(t *testing.T) {
96 tests := []struct {
97 name string
98 }{
99 {
100 name: "InitEventFuncMapper",
101 },
102 }
103 for _, tt := range tests {
104 t.Run(tt.name, func(t *testing.T) {
105 InitEventFuncMapper()
106 })
107 }
108}
109
110func TestProcessUsIgmpFlowAddEvent(t *testing.T) {
111 type args struct {
112 cntx context.Context
113 event *FlowEvent
114 flowStatus intf.FlowStatus
115 }
116 tests := []struct {
117 name string
118 args args
119 }{
120 {
121 name: "ProcessUsIgmpFlowAddEvent",
122 args: args{
123 cntx: context.Background(),
124 event: &FlowEvent{
125 device: "test_device",
126 eType: EventTypeControlFlowAdded,
127 eventData: voltPortVnet,
128 },
129 flowStatus: intf.FlowStatus{
130 Device: "test_device",
131 Status: uint32(0),
132 },
133 },
134 },
135 }
136 for _, tt := range tests {
137 t.Run(tt.name, func(t *testing.T) {
138 ProcessUsIgmpFlowAddEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
139 })
140 }
141}
142
143func TestProcessServiceFlowAddEvent(t *testing.T) {
144 type args struct {
145 cntx context.Context
146 event *FlowEvent
147 flowStatus intf.FlowStatus
148 }
149
150 tests := []struct {
151 name string
152 args args
153 }{
154 {
155 name: "ProcessServiceFlowAddEvent",
156 args: args{
157 cntx: context.Background(),
158 event: &FlowEvent{
159 device: "test_device",
160 eventData: voltService,
161 },
162 },
163 },
164 }
165 for _, tt := range tests {
166 t.Run(tt.name, func(t *testing.T) {
167 ProcessServiceFlowAddEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
168 })
169 }
170}
171
172func TestProcessControlFlowAddEvent(t *testing.T) {
173 type args struct {
174 cntx context.Context
175 event *FlowEvent
176 flowStatus intf.FlowStatus
177 }
178 tests := []struct {
179 name string
180 args args
181 }{
182 {
183 name: "ProcessControlFlowAddEvent",
184 args: args{
185 cntx: context.Background(),
186 event: &FlowEvent{
187 eventData: voltPortVnet,
188 },
189 },
190 },
191 }
192 for _, tt := range tests {
193 t.Run(tt.name, func(t *testing.T) {
194 ProcessControlFlowAddEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
195 })
196 }
197}
198
199func TestProcessServiceFlowDelEvent(t *testing.T) {
200 type args struct {
201 cntx context.Context
202 event *FlowEvent
203 flowStatus intf.FlowStatus
204 }
205 tests := []struct {
206 name string
207 args args
208 }{
209 {
210 name: "ProcessServiceFlowDelEvent",
211 args: args{
212 cntx: context.Background(),
213 event: &FlowEvent{
214 eventData: voltService,
215 },
216 },
217 },
218 }
219 for _, tt := range tests {
220 t.Run(tt.name, func(t *testing.T) {
221 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
222 db = dbintf
223 dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
224 ProcessServiceFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
225 })
226 }
227}
228
229func TestProcessControlFlowDelEvent(t *testing.T) {
230 type args struct {
231 cntx context.Context
232 event *FlowEvent
233 flowStatus intf.FlowStatus
234 }
235 tests := []struct {
236 name string
237 args args
238 }{
239 {
240 name: "ProcessControlFlowDelEvent",
241 args: args{
242 cntx: context.Background(),
243 event: &FlowEvent{
244 eventData: voltPortVnet,
245 },
246 },
247 },
248 }
249 for _, tt := range tests {
250 t.Run(tt.name, func(t *testing.T) {
251 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
252 db = dbintf
253 dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
254 ProcessControlFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
255 })
256 }
257}
258
259func TestProcessMcastFlowDelEvent(t *testing.T) {
260 type args struct {
261 cntx context.Context
262 event *FlowEvent
263 flowStatus intf.FlowStatus
264 }
265 mvlanProfile := &MvlanProfile{
266 Version: "test_version",
267 }
268 tests := []struct {
269 name string
270 args args
271 }{
272 {
273 name: "ProcessMcastFlowDelEvent",
274 args: args{
275 cntx: context.Background(),
276 event: &FlowEvent{
277 eventData: mvlanProfile,
278 },
279 },
280 },
281 }
282 for _, tt := range tests {
283 t.Run(tt.name, func(t *testing.T) {
284 dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
285 db = dbintf
286 dbintf.EXPECT().PutMvlan(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
287 ProcessMcastFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
288 })
289 }
290}