blob: f8fabbc040d8e425424dcd5f4ec5d826c74b6b57 [file] [log] [blame]
cbabuabf02352019-10-15 13:14:56 +02001/*
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
cbabubef89432019-10-18 11:47:27 +020017/*
18This file contains unit test cases for functions in the file resourcemanager.go.
19This file also implements the Client interface to mock the kv-client, fields struct to mock OpenOltResourceMgr
20and few utility functions.
21*/
22
23//Package adaptercore provides the utility for olt devices, flows and statistics
cbabuabf02352019-10-15 13:14:56 +020024package resourcemanager
25
26import (
npujarec5762e2020-01-01 14:08:48 +053027 "context"
cbabuabf02352019-10-15 13:14:56 +020028 "encoding/json"
29 "errors"
serkant.uluderya7b8211e2021-02-24 16:39:18 +030030 "reflect"
31 "strconv"
32 "strings"
serkant.uluderya7b8211e2021-02-24 16:39:18 +030033 "testing"
34 "time"
35
Girish Gowdra4c3d4602021-07-22 16:33:37 -070036 "github.com/opencord/voltha-lib-go/v6/pkg/db"
37 "github.com/opencord/voltha-lib-go/v6/pkg/db/kvstore"
38 fu "github.com/opencord/voltha-lib-go/v6/pkg/flows"
39 "github.com/opencord/voltha-lib-go/v6/pkg/log"
40 ponrmgr "github.com/opencord/voltha-lib-go/v6/pkg/ponresourcemanager"
Girish Gowdraa09aeab2020-09-14 16:30:52 -070041 ofp "github.com/opencord/voltha-protos/v4/go/openflow_13"
42 "github.com/opencord/voltha-protos/v4/go/openolt"
cbabuabf02352019-10-15 13:14:56 +020043)
44
45func init() {
Kent Hagermane6ff1012020-07-14 15:07:53 -040046 _, _ = log.SetDefaultLogger(log.JSON, log.DebugLevel, nil)
cbabuabf02352019-10-15 13:14:56 +020047}
48
49const (
50 // MeterConfig meter to extract meter
51 MeterConfig = "meter_id"
52 // TpIDSuffixPath to extract Techprofile
Kent Hagermane6ff1012020-07-14 15:07:53 -040053 // TpIDSuffixPath = "tp_id"
cbabuabf02352019-10-15 13:14:56 +020054 // FlowIDInfo to extract flows
55 FlowIDInfo = "flow_id_info"
56 // FlowIds to extract flows
57 FlowIDs = "flow_ids"
58 // GemportIDs to gemport_ids
59 GemportIDs = "gemport_ids"
60 // AllocIDs to extract alloc_ids
61 AllocIDs = "alloc_ids"
62 // GemportIDPool to extract gemport
63 GemportIDPool = "gemport_id_pool"
64 // AllocIDPool to extract allocid
65 AllocIDPool = "alloc_id_pool"
66 // FlowIDpool to extract Flow ids
67 FlowIDpool = "flow_id_pool"
68)
69
cbabubef89432019-10-18 11:47:27 +020070// fields mocks OpenOltResourceMgr struct.
cbabuabf02352019-10-15 13:14:56 +020071type fields struct {
Girish Gowdra38d533d2020-03-30 20:38:51 -070072 DeviceID string
Neha Sharma3f221ae2020-04-29 19:02:12 +000073 Address string
Girish Gowdra38d533d2020-03-30 20:38:51 -070074 Args string
75 KVStore *db.Backend
76 DeviceType string
Girish Gowdra38d533d2020-03-30 20:38:51 -070077 DevInfo *openolt.DeviceInfo
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070078 PonRsrMgr *ponrmgr.PONResourceManager
Girish Gowdra38d533d2020-03-30 20:38:51 -070079 NumOfPonPorts uint32
cbabuabf02352019-10-15 13:14:56 +020080}
cbabubef89432019-10-18 11:47:27 +020081
82// MockKVClient mocks the AdapterProxy interface.
cbabuabf02352019-10-15 13:14:56 +020083type MockResKVClient struct {
84}
85
cbabubef89432019-10-18 11:47:27 +020086// getResMgr mocks OpenOltResourceMgr struct.
cbabuabf02352019-10-15 13:14:56 +020087func getResMgr() *fields {
88 var resMgr fields
sbarbaria8910ba2019-11-05 10:12:23 -050089 resMgr.KVStore = &db.Backend{
cbabuabf02352019-10-15 13:14:56 +020090 Client: &MockResKVClient{},
91 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070092 resMgr.PonRsrMgr = &ponrmgr.PONResourceManager{}
cbabuabf02352019-10-15 13:14:56 +020093 ranges := make(map[string]interface{})
94 sharedIdxByType := make(map[string]string)
95 sharedIdxByType["ALLOC_ID"] = "ALLOC_ID"
96 sharedIdxByType["ONU_ID"] = "ONU_ID"
97 sharedIdxByType["GEMPORT_ID"] = "GEMPORT_ID"
98 sharedIdxByType["FLOW_ID"] = "FLOW_ID"
99 ranges["ONU_ID"] = uint32(0)
100 ranges["GEMPORT_ID"] = uint32(0)
101 ranges["ALLOC_ID"] = uint32(0)
102 ranges["FLOW_ID"] = uint32(0)
103 ranges["onu_id_shared"] = uint32(0)
104 ranges["alloc_id_shared"] = uint32(0)
105 ranges["gemport_id_shared"] = uint32(0)
106 ranges["flow_id_shared"] = uint32(0)
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700107 resMgr.NumOfPonPorts = 16
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700108 resMgr.PonRsrMgr.DeviceID = "onu-1"
109 resMgr.PonRsrMgr.IntfIDs = []uint32{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
110 resMgr.PonRsrMgr.KVStore = &db.Backend{
Matteo Scandolo84585372021-03-18 14:21:22 -0700111 Client: &MockResKVClient{},
112 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700113 resMgr.PonRsrMgr.Technology = "XGS-PON"
114 resMgr.PonRsrMgr.PonResourceRanges = ranges
115 resMgr.PonRsrMgr.SharedIdxByType = sharedIdxByType
116 /*
117 tpMgr, err := tp.NewTechProfile(ctx, resMgr.PonRsrMgr, "etcd", "127.0.0.1", "/")
118 if err != nil {
119 logger.Fatal(ctx, err.Error())
120 }
121 */
Matteo Scandolo84585372021-03-18 14:21:22 -0700122
cbabuabf02352019-10-15 13:14:56 +0200123 return &resMgr
124}
cbabubef89432019-10-18 11:47:27 +0200125
126// List function implemented for KVClient.
npujarec5762e2020-01-01 14:08:48 +0530127func (kvclient *MockResKVClient) List(ctx context.Context, key string) (map[string]*kvstore.KVPair, error) {
cbabuabf02352019-10-15 13:14:56 +0200128 return nil, errors.New("key didn't find")
129}
130
131// Get mock function implementation for KVClient
npujarec5762e2020-01-01 14:08:48 +0530132func (kvclient *MockResKVClient) Get(ctx context.Context, key string) (*kvstore.KVPair, error) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000133 logger.Debugw(ctx, "Warning Warning Warning: Get of MockKVClient called", log.Fields{"key": key})
cbabuabf02352019-10-15 13:14:56 +0200134 if key != "" {
135 if strings.Contains(key, MeterConfig) {
136 var bands []*ofp.OfpMeterBandHeader
137 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DSCP_REMARK,
138 Rate: 1024, Data: &ofp.OfpMeterBandHeader_DscpRemark{DscpRemark: &ofp.OfpMeterBandDscpRemark{PrecLevel: 2}}})
139
140 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DSCP_REMARK,
141 Rate: 1024, Data: &ofp.OfpMeterBandHeader_DscpRemark{DscpRemark: &ofp.OfpMeterBandDscpRemark{PrecLevel: 3}}})
142
Gamze Abakafee36392019-10-03 11:17:24 +0000143 sep := strings.Split(key, "/")[1]
cbabuabf02352019-10-15 13:14:56 +0200144 val, _ := strconv.ParseInt(strings.Split(sep, ",")[1], 10, 32)
145 if uint32(val) > 1 {
146 meterConfig := &ofp.OfpMeterConfig{MeterId: uint32(val), Bands: bands}
147 str, _ := json.Marshal(meterConfig)
148
149 return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
150 }
151 return nil, errors.New("invalid meter")
152 }
153 if strings.Contains(key, FlowIDpool) || strings.Contains(key, GemportIDPool) || strings.Contains(key, AllocIDPool) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000154 logger.Debug(ctx, "Error Error Error Key:", FlowIDpool, GemportIDPool, AllocIDPool)
cbabuabf02352019-10-15 13:14:56 +0200155 data := make(map[string]interface{})
156 data["pool"] = "1024"
157 data["start_idx"] = 1
158 data["end_idx"] = 1024
159 str, _ := json.Marshal(data)
160 return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
161 }
162 if strings.Contains(key, FlowIDInfo) || strings.Contains(key, FlowIDs) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000163 logger.Debug(ctx, "Error Error Error Key:", FlowIDs, FlowIDInfo)
cbabuabf02352019-10-15 13:14:56 +0200164 str, _ := json.Marshal([]uint32{1, 2})
165 return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
166 }
167 if strings.Contains(key, AllocIDs) || strings.Contains(key, GemportIDs) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000168 logger.Debug(ctx, "Error Error Error Key:", AllocIDs, GemportIDs)
cbabuabf02352019-10-15 13:14:56 +0200169 str, _ := json.Marshal(1)
170 return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
171 }
Esin Karamanccb714b2019-11-29 15:02:06 +0000172 if strings.Contains(key, McastQueuesForIntf) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000173 logger.Debug(ctx, "Error Error Error Key:", McastQueuesForIntf)
Esin Karamanccb714b2019-11-29 15:02:06 +0000174 mcastQueues := make(map[uint32][]uint32)
175 mcastQueues[10] = []uint32{4000, 0}
176 str, _ := json.Marshal(mcastQueues)
177 return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
178 }
179 if strings.Contains(key, "flow_groups") && !strings.Contains(key, "1000") {
180 groupInfo := GroupInfo{GroupID: 2, OutPorts: []uint32{2}}
181 str, _ := json.Marshal(groupInfo)
182 return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
183 }
184
cbabuabf02352019-10-15 13:14:56 +0200185 maps := make(map[string]*kvstore.KVPair)
186 maps[key] = &kvstore.KVPair{Key: key}
187 return maps[key], nil
188 }
189 return nil, errors.New("key didn't find")
190}
191
192// Put mock function implementation for KVClient
npujarec5762e2020-01-01 14:08:48 +0530193func (kvclient *MockResKVClient) Put(ctx context.Context, key string, value interface{}) error {
cbabuabf02352019-10-15 13:14:56 +0200194 if key != "" {
195 return nil
196 }
197 return errors.New("key didn't find")
198}
199
200// Delete mock function implementation for KVClient
npujarec5762e2020-01-01 14:08:48 +0530201func (kvclient *MockResKVClient) Delete(ctx context.Context, key string) error {
cbabuabf02352019-10-15 13:14:56 +0200202 return nil
203}
204
serkant.uluderya7b8211e2021-02-24 16:39:18 +0300205// DeleteWithPrefix mock function implementation for KVClient
206func (kvclient *MockResKVClient) DeleteWithPrefix(ctx context.Context, prefix string) error {
207 return nil
208}
209
cbabuabf02352019-10-15 13:14:56 +0200210// Reserve mock function implementation for KVClient
Neha Sharmacc656962020-04-14 14:26:11 +0000211func (kvclient *MockResKVClient) Reserve(ctx context.Context, key string, value interface{}, ttl time.Duration) (interface{}, error) {
cbabuabf02352019-10-15 13:14:56 +0200212 return nil, errors.New("key didn't find")
213}
214
215// ReleaseReservation mock function implementation for KVClient
npujarec5762e2020-01-01 14:08:48 +0530216func (kvclient *MockResKVClient) ReleaseReservation(ctx context.Context, key string) error {
cbabuabf02352019-10-15 13:14:56 +0200217 return nil
218}
219
220// ReleaseAllReservations mock function implementation for KVClient
npujarec5762e2020-01-01 14:08:48 +0530221func (kvclient *MockResKVClient) ReleaseAllReservations(ctx context.Context) error {
cbabuabf02352019-10-15 13:14:56 +0200222 return nil
223}
224
225// RenewReservation mock function implementation for KVClient
npujarec5762e2020-01-01 14:08:48 +0530226func (kvclient *MockResKVClient) RenewReservation(ctx context.Context, key string) error {
cbabuabf02352019-10-15 13:14:56 +0200227 return nil
228}
229
230// Watch mock function implementation for KVClient
Scott Bakere701b862020-02-20 16:19:16 -0800231func (kvclient *MockResKVClient) Watch(ctx context.Context, key string, withPrefix bool) chan *kvstore.Event {
cbabuabf02352019-10-15 13:14:56 +0200232 return nil
233}
234
235// AcquireLock mock function implementation for KVClient
Neha Sharmacc656962020-04-14 14:26:11 +0000236func (kvclient *MockResKVClient) AcquireLock(ctx context.Context, lockName string, timeout time.Duration) error {
cbabuabf02352019-10-15 13:14:56 +0200237 return nil
238}
239
240// ReleaseLock mock function implementation for KVClient
241func (kvclient *MockResKVClient) ReleaseLock(lockName string) error {
242 return nil
243}
244
245// IsConnectionUp mock function implementation for KVClient
npujarec5762e2020-01-01 14:08:48 +0530246func (kvclient *MockResKVClient) IsConnectionUp(ctx context.Context) bool { // timeout in second
cbabuabf02352019-10-15 13:14:56 +0200247 return true
248}
249
250// CloseWatch mock function implementation for KVClient
Neha Sharma96b7bf22020-06-15 10:37:32 +0000251func (kvclient *MockResKVClient) CloseWatch(ctx context.Context, key string, ch chan *kvstore.Event) {
cbabuabf02352019-10-15 13:14:56 +0200252}
253
254// Close mock function implementation for KVClient
Neha Sharma96b7bf22020-06-15 10:37:32 +0000255func (kvclient *MockResKVClient) Close(ctx context.Context) {
cbabuabf02352019-10-15 13:14:56 +0200256}
257
cbabubef89432019-10-18 11:47:27 +0200258// testResMgrObject maps fields type to OpenOltResourceMgr type.
cbabuabf02352019-10-15 13:14:56 +0200259func testResMgrObject(testResMgr *fields) *OpenOltResourceMgr {
Girish Gowdra38d533d2020-03-30 20:38:51 -0700260 var rsrMgr = OpenOltResourceMgr{
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700261 DeviceID: testResMgr.DeviceID,
262 Args: testResMgr.Args,
263 KVStore: testResMgr.KVStore,
264 DeviceType: testResMgr.DeviceType,
265 Address: testResMgr.Address,
266 DevInfo: testResMgr.DevInfo,
267 PonRsrMgr: testResMgr.PonRsrMgr,
cbabuabf02352019-10-15 13:14:56 +0200268 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700269 rsrMgr.InitLocalCache()
Girish Gowdra38d533d2020-03-30 20:38:51 -0700270
271 return &rsrMgr
cbabuabf02352019-10-15 13:14:56 +0200272}
273
274func TestNewResourceMgr(t *testing.T) {
275 type args struct {
Neha Sharma3f221ae2020-04-29 19:02:12 +0000276 deviceID string
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700277 intfID uint32
Neha Sharma3f221ae2020-04-29 19:02:12 +0000278 KVStoreAddress string
279 kvStoreType string
280 deviceType string
281 devInfo *openolt.DeviceInfo
Matteo Scandolodfa7a972020-11-06 13:03:40 -0800282 kvStorePrefix string
cbabuabf02352019-10-15 13:14:56 +0200283 }
284 tests := []struct {
285 name string
286 args args
287 want *OpenOltResourceMgr
288 }{
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700289 {"NewResourceMgr-2", args{"olt1", 0, "1:2", "etcd",
Matteo Scandolodfa7a972020-11-06 13:03:40 -0800290 "onu", &openolt.DeviceInfo{OnuIdStart: 1, OnuIdEnd: 1}, "service/voltha"}, &OpenOltResourceMgr{}},
cbabuabf02352019-10-15 13:14:56 +0200291 }
292 for _, tt := range tests {
293 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530294 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
295 defer cancel()
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700296 if got := NewResourceMgr(ctx, tt.args.intfID, tt.args.deviceID, tt.args.KVStoreAddress, tt.args.kvStoreType, tt.args.deviceType, tt.args.devInfo, tt.args.kvStorePrefix); reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
cbabuabf02352019-10-15 13:14:56 +0200297 t.Errorf("NewResourceMgr() = %v, want %v", got, tt.want)
298 }
299 })
300 }
301}
302
303func TestOpenOltResourceMgr_Delete(t *testing.T) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700304 type args struct {
305 intfID uint32
306 }
cbabuabf02352019-10-15 13:14:56 +0200307 tests := []struct {
308 name string
309 fields *fields
310 wantErr error
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700311 args args
cbabuabf02352019-10-15 13:14:56 +0200312 }{
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700313 {"Delete-1", getResMgr(), errors.New("failed to clear device resource pool"), args{intfID: 0}},
cbabuabf02352019-10-15 13:14:56 +0200314 }
315 for _, tt := range tests {
316 t.Run(tt.name, func(t *testing.T) {
317 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530318 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
319 defer cancel()
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700320 if err := RsrcMgr.Delete(ctx, tt.args.intfID); (err != nil) && reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr) {
cbabuabf02352019-10-15 13:14:56 +0200321 t.Errorf("Delete() error = %v, wantErr %v", err, tt.wantErr)
322 }
323 })
324 }
325}
326
cbabuabf02352019-10-15 13:14:56 +0200327func TestOpenOltResourceMgr_FreePONResourcesForONU(t *testing.T) {
328 type args struct {
329 intfID uint32
330 onuID uint32
331 uniID uint32
332 }
333 tests := []struct {
334 name string
335 fields *fields
336 args args
337 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700338 {"FreePONResourcesForONU-1", getResMgr(), args{1, 0, 2}},
cbabuabf02352019-10-15 13:14:56 +0200339 }
340 for _, tt := range tests {
341 t.Run(tt.name, func(t *testing.T) {
342 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530343 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
344 defer cancel()
345 RsrcMgr.FreePONResourcesForONU(ctx, tt.args.intfID, tt.args.onuID, tt.args.uniID)
cbabuabf02352019-10-15 13:14:56 +0200346 })
347 }
348}
349
350func TestOpenOltResourceMgr_FreeonuID(t *testing.T) {
351 type args struct {
352 intfID uint32
353 onuID []uint32
354 }
355 tests := []struct {
356 name string
357 fields *fields
358 args args
359 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700360 {"FreeOnuID-1", getResMgr(), args{1, []uint32{1, 2}}},
cbabuabf02352019-10-15 13:14:56 +0200361 }
362 for _, tt := range tests {
363 t.Run(tt.name, func(t *testing.T) {
364 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530365 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
366 defer cancel()
367 RsrcMgr.FreeonuID(ctx, tt.args.intfID, tt.args.onuID)
cbabuabf02352019-10-15 13:14:56 +0200368 })
369 }
370}
371
cbabuabf02352019-10-15 13:14:56 +0200372func TestOpenOltResourceMgr_GetCurrentAllocIDForOnu(t *testing.T) {
373 type args struct {
374 intfID uint32
375 onuID uint32
376 uniID uint32
377 }
378 tests := []struct {
379 name string
380 fields *fields
381 args args
Gamze Abakafee36392019-10-03 11:17:24 +0000382 want []uint32
cbabuabf02352019-10-15 13:14:56 +0200383 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700384 {"GetCurrentAllocIDForOnu-1", getResMgr(), args{1, 2, 2}, []uint32{}},
cbabuabf02352019-10-15 13:14:56 +0200385 }
386 for _, tt := range tests {
387 t.Run(tt.name, func(t *testing.T) {
388 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530389 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
390 defer cancel()
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700391 got := RsrcMgr.GetCurrentAllocIDsForOnu(ctx, tt.args.intfID, tt.args.onuID, tt.args.uniID)
392 if len(got) != len(tt.want) {
Gamze Abakafee36392019-10-03 11:17:24 +0000393 t.Errorf("GetCurrentAllocIDsForOnu() = %v, want %v", got, tt.want)
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700394 } else {
395 for i := range tt.want {
396 if got[i] != tt.want[i] {
397 t.Errorf("GetCurrentAllocIDsForOnu() = %v, want %v", got, tt.want)
398 break
399 }
400 }
cbabuabf02352019-10-15 13:14:56 +0200401 }
402 })
403 }
404}
405
406func TestOpenOltResourceMgr_GetCurrentFlowIDsForOnu(t *testing.T) {
407
408 type args struct {
409 PONIntfID uint32
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530410 ONUID int32
411 UNIID int32
cbabuabf02352019-10-15 13:14:56 +0200412 }
413 tests := []struct {
414 name string
415 fields *fields
416 args args
Girish Gowdraa09aeab2020-09-14 16:30:52 -0700417 want []uint64
cbabuabf02352019-10-15 13:14:56 +0200418 }{
Girish Gowdraa09aeab2020-09-14 16:30:52 -0700419 {"GetCurrentFlowIDsForOnu-1", getResMgr(), args{1, 2, 2}, []uint64{1, 2}},
cbabuabf02352019-10-15 13:14:56 +0200420 }
421 for _, tt := range tests {
422 t.Run(tt.name, func(t *testing.T) {
423 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530424 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
425 defer cancel()
Girish Gowdraa09aeab2020-09-14 16:30:52 -0700426 got, err := RsrcMgr.GetCurrentFlowIDsForOnu(ctx, tt.args.PONIntfID, tt.args.ONUID, tt.args.UNIID)
427 if err != nil {
428 t.Errorf("GetCurrentFlowIDsForOnu() returned error")
429 }
430 if reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
cbabuabf02352019-10-15 13:14:56 +0200431 t.Errorf("GetCurrentFlowIDsForOnu() = %v, want %v", got, tt.want)
432 }
433 })
434 }
435}
436
437func TestOpenOltResourceMgr_GetCurrentGEMPortIDsForOnu(t *testing.T) {
438 type args struct {
439 intfID uint32
440 onuID uint32
441 uniID uint32
442 }
443 tests := []struct {
444 name string
445 fields *fields
446 args args
447 want []uint32
448 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700449 {"GetCurrentGEMPortIDsForOnu-1", getResMgr(), args{1, 2, 2}, []uint32{}},
cbabuabf02352019-10-15 13:14:56 +0200450 }
451 for _, tt := range tests {
452 t.Run(tt.name, func(t *testing.T) {
453 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530454 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
455 defer cancel()
456 if got := RsrcMgr.GetCurrentGEMPortIDsForOnu(ctx, tt.args.intfID, tt.args.onuID, tt.args.uniID); reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
cbabuabf02352019-10-15 13:14:56 +0200457 t.Errorf("GetCurrentGEMPortIDsForOnu() = %v, want %v", got, tt.want)
458 }
459 })
460 }
461}
462
Girish Gowdraa482f272021-03-24 23:04:19 -0700463func TestOpenOltResourceMgr_GetMeterInfoForOnu(t *testing.T) {
cbabuabf02352019-10-15 13:14:56 +0200464 type args struct {
465 Direction string
466 IntfID uint32
467 OnuID uint32
468 UniID uint32
Gamze Abakafee36392019-10-03 11:17:24 +0000469 tpID uint32
cbabuabf02352019-10-15 13:14:56 +0200470 }
471 tests := []struct {
472 name string
473 fields *fields
474 args args
Girish Gowdraa482f272021-03-24 23:04:19 -0700475 want *MeterInfo
cbabuabf02352019-10-15 13:14:56 +0200476 wantErr error
477 }{
Girish Gowdraa482f272021-03-24 23:04:19 -0700478 {"GetMeterInfoForOnu", getResMgr(), args{"DOWNSTREAM", 0, 1, 1, 64},
479 &MeterInfo{}, errors.New("failed to get Meter config from kvstore for path")},
480 {"GetMeterInfoForOnu", getResMgr(), args{"DOWNSTREAM", 1, 2, 2, 65},
481 &MeterInfo{}, errors.New("failed to get Meter config from kvstore for path")},
cbabuabf02352019-10-15 13:14:56 +0200482 }
483 for _, tt := range tests {
484 t.Run(tt.name, func(t *testing.T) {
485 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530486 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
487 defer cancel()
Girish Gowdraa482f272021-03-24 23:04:19 -0700488 got, err := RsrcMgr.GetMeterInfoForOnu(ctx, tt.args.Direction, tt.args.IntfID, tt.args.OnuID, tt.args.UniID, tt.args.tpID)
cbabuabf02352019-10-15 13:14:56 +0200489 if reflect.TypeOf(got) != reflect.TypeOf(tt.want) && err != nil {
Girish Gowdraa482f272021-03-24 23:04:19 -0700490 t.Errorf("GetMeterInfoForOnu() got = %v, want %v", got, tt.want)
cbabuabf02352019-10-15 13:14:56 +0200491 }
492 })
493 }
494}
495
496func TestOpenOltResourceMgr_GetONUID(t *testing.T) {
497 type args struct {
498 ponIntfID uint32
499 }
500 tests := []struct {
501 name string
502 fields *fields
503 args args
504 want uint32
505 wantErr error
506 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700507 {"GetONUID-1", getResMgr(), args{1}, uint32(0), errors.New("json errors")},
cbabuabf02352019-10-15 13:14:56 +0200508 }
509 for _, tt := range tests {
510 t.Run(tt.name, func(t *testing.T) {
511 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530512 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
513 defer cancel()
514 got, err := RsrcMgr.GetONUID(ctx, tt.args.ponIntfID)
cbabuabf02352019-10-15 13:14:56 +0200515 if got != tt.want && err != nil {
516 t.Errorf("GetONUID() got = %v, want %v", got, tt.want)
517 }
518 })
519 }
520}
521
522func TestOpenOltResourceMgr_GetTechProfileIDForOnu(t *testing.T) {
523
524 type args struct {
525 IntfID uint32
526 OnuID uint32
527 UniID uint32
528 }
529 tests := []struct {
530 name string
531 fields *fields
532 args args
Gamze Abakafee36392019-10-03 11:17:24 +0000533 want []uint32
cbabuabf02352019-10-15 13:14:56 +0200534 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700535 {"GetTechProfileIDForOnu-1", getResMgr(), args{1, 2, 2},
Gamze Abakafee36392019-10-03 11:17:24 +0000536 []uint32{1}},
cbabuabf02352019-10-15 13:14:56 +0200537 }
538 for _, tt := range tests {
539 t.Run(tt.name, func(t *testing.T) {
540 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530541 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
542 defer cancel()
543 if got := RsrcMgr.GetTechProfileIDForOnu(ctx, tt.args.IntfID, tt.args.OnuID, tt.args.UniID); reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
cbabuabf02352019-10-15 13:14:56 +0200544 t.Errorf("GetTechProfileIDForOnu() = %v, want %v", got, tt.want)
545 }
546 })
547 }
548}
549
cbabuabf02352019-10-15 13:14:56 +0200550func TestOpenOltResourceMgr_RemoveMeterIDForOnu(t *testing.T) {
551
552 type args struct {
553 Direction string
554 IntfID uint32
555 OnuID uint32
556 UniID uint32
Gamze Abakafee36392019-10-03 11:17:24 +0000557 tpID uint32
cbabuabf02352019-10-15 13:14:56 +0200558 }
559 tests := []struct {
560 name string
561 fields *fields
562 args args
563 wantErr error
564 }{
Gamze Abakafee36392019-10-03 11:17:24 +0000565 {"RemoveMeterIdForOnu-1", getResMgr(), args{"DOWNSTREAM", 1, 1, 1, 64},
cbabuabf02352019-10-15 13:14:56 +0200566 errors.New("failed to delete meter id %s from kvstore")},
567 }
568 for _, tt := range tests {
569 t.Run(tt.name, func(t *testing.T) {
570 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530571 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
572 defer cancel()
Girish Gowdraa482f272021-03-24 23:04:19 -0700573 if err := RsrcMgr.RemoveMeterInfoForOnu(ctx, tt.args.Direction, tt.args.IntfID, tt.args.OnuID, tt.args.UniID,
Gamze Abakafee36392019-10-03 11:17:24 +0000574 tt.args.tpID); reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr) && err != nil {
cbabuabf02352019-10-15 13:14:56 +0200575 t.Errorf("RemoveMeterIDForOnu() error = %v, wantErr %v", err, tt.wantErr)
576 }
577 })
578 }
579}
580
581func TestOpenOltResourceMgr_RemoveTechProfileIDForOnu(t *testing.T) {
582 type args struct {
583 IntfID uint32
584 OnuID uint32
585 UniID uint32
Gamze Abakafee36392019-10-03 11:17:24 +0000586 tpID uint32
cbabuabf02352019-10-15 13:14:56 +0200587 }
588 tests := []struct {
589 name string
590 fields *fields
591 args args
592 wantErr error
593 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700594 {"RemoveTechProfileIDForOnu-1", getResMgr(), args{1, 2, 2, 64},
cbabuabf02352019-10-15 13:14:56 +0200595 errors.New("failed to delete techprofile id resource %s in KV store")},
596 }
597 for _, tt := range tests {
598 t.Run(tt.name, func(t *testing.T) {
599 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530600 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
601 defer cancel()
602 if err := RsrcMgr.RemoveTechProfileIDForOnu(ctx, tt.args.IntfID, tt.args.OnuID, tt.args.UniID,
Gamze Abakafee36392019-10-03 11:17:24 +0000603 tt.args.tpID); reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr) && err != nil {
cbabuabf02352019-10-15 13:14:56 +0200604 t.Errorf("RemoveTechProfileIDForOnu() error = %v, wantErr %v", err, tt.wantErr)
605 }
606 })
607 }
608}
609
610func TestOpenOltResourceMgr_UpdateAllocIdsForOnu(t *testing.T) {
611 type args struct {
612 ponPort uint32
613 onuID uint32
614 uniID uint32
615 allocID []uint32
616 }
617 tests := []struct {
618 name string
619 fields *fields
620 args args
621 wantErr error
622 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700623 {"UpdateAllocIdsForOnu-1", getResMgr(), args{1, 2, 2, []uint32{1, 2}},
cbabuabf02352019-10-15 13:14:56 +0200624 errors.New("")},
625 }
626 for _, tt := range tests {
627 t.Run(tt.name, func(t *testing.T) {
628 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530629 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
630 defer cancel()
631 if err := RsrcMgr.UpdateAllocIdsForOnu(ctx, tt.args.ponPort, tt.args.onuID, tt.args.uniID, tt.args.allocID); err != nil && reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr) {
cbabuabf02352019-10-15 13:14:56 +0200632 t.Errorf("UpdateAllocIdsForOnu() error = %v, wantErr %v", err, tt.wantErr)
633 }
634 })
635 }
636}
637
cbabuabf02352019-10-15 13:14:56 +0200638func TestOpenOltResourceMgr_UpdateGEMPortIDsForOnu(t *testing.T) {
639
640 type args struct {
641 ponPort uint32
642 onuID uint32
643 uniID uint32
644 GEMPortList []uint32
645 }
646 tests := []struct {
647 name string
648 fields *fields
649 args args
650 wantErr error
651 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700652 {"UpdateGEMPortIDsForOnu-1", getResMgr(), args{1, 2, 2,
cbabuabf02352019-10-15 13:14:56 +0200653 []uint32{1, 2}}, errors.New("failed to update resource")},
654 }
655 for _, tt := range tests {
656 t.Run(tt.name, func(t *testing.T) {
657 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530658 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
659 defer cancel()
660 if err := RsrcMgr.UpdateGEMPortIDsForOnu(ctx, tt.args.ponPort, tt.args.onuID, tt.args.uniID, tt.args.GEMPortList); err != nil && reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr) {
cbabuabf02352019-10-15 13:14:56 +0200661 t.Errorf("UpdateGEMPortIDsForOnu() error = %v, wantErr %v", err, tt.wantErr)
662 }
663 })
664 }
665}
666
cbabuabf02352019-10-15 13:14:56 +0200667func TestOpenOltResourceMgr_UpdateMeterIDForOnu(t *testing.T) {
668 type args struct {
Girish Gowdraa482f272021-03-24 23:04:19 -0700669 Direction string
670 IntfID uint32
671 OnuID uint32
672 UniID uint32
673 tpID uint32
674 MeterInfo *MeterInfo
cbabuabf02352019-10-15 13:14:56 +0200675 }
676 tests := []struct {
677 name string
678 fields *fields
679 args args
680 wantErr error
681 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700682 {"UpdateMeterIDForOnu-1", getResMgr(), args{"DOWNSTREAM", 1, 2,
Girish Gowdraa482f272021-03-24 23:04:19 -0700683 2, 64, &MeterInfo{}}, errors.New("failed to get Meter config from kvstore for path")},
cbabuabf02352019-10-15 13:14:56 +0200684 }
685 for _, tt := range tests {
686 t.Run(tt.name, func(t *testing.T) {
687 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530688 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
689 defer cancel()
Girish Gowdraa482f272021-03-24 23:04:19 -0700690 if err := RsrcMgr.StoreMeterInfoForOnu(ctx, tt.args.Direction, tt.args.IntfID, tt.args.OnuID, tt.args.UniID,
691 tt.args.tpID, tt.args.MeterInfo); reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr) && err != nil {
cbabuabf02352019-10-15 13:14:56 +0200692 t.Errorf("UpdateMeterIDForOnu() got = %v, want %v", err, tt.wantErr)
693 }
694 })
695 }
696}
697
698func TestOpenOltResourceMgr_UpdateTechProfileIDForOnu(t *testing.T) {
699 type args struct {
700 IntfID uint32
701 OnuID uint32
702 UniID uint32
703 TpID uint32
704 }
705 tests := []struct {
706 name string
707 fields *fields
708 args args
709 wantErr error
710 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700711 {"UpdateTechProfileIDForOnu-1", getResMgr(), args{1, 2, 2,
cbabuabf02352019-10-15 13:14:56 +0200712 2}, errors.New("failed to update resource")},
713 }
714 for _, tt := range tests {
715 t.Run(tt.name, func(t *testing.T) {
716 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530717 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
718 defer cancel()
719 if err := RsrcMgr.UpdateTechProfileIDForOnu(ctx, tt.args.IntfID, tt.args.OnuID, tt.args.UniID, tt.args.TpID); reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr) && err != nil {
cbabuabf02352019-10-15 13:14:56 +0200720 t.Errorf("UpdateTechProfileIDForOnu() got = %v, want %v", err, tt.wantErr)
721 }
722 })
723 }
724}
725
726func TestSetKVClient(t *testing.T) {
727 type args struct {
Matteo Scandolodfa7a972020-11-06 13:03:40 -0800728 backend string
729 address string
730 DeviceID string
731 kvStorePrefix string
cbabuabf02352019-10-15 13:14:56 +0200732 }
733 tests := []struct {
734 name string
735 args args
sbarbaria8910ba2019-11-05 10:12:23 -0500736 want *db.Backend
cbabuabf02352019-10-15 13:14:56 +0200737 }{
serkant.uluderya7b8211e2021-02-24 16:39:18 +0300738 {"setKVClient-1", args{"etcd", "1.1.1.1:1", "olt1", "service/voltha"}, &db.Backend{}},
cbabuabf02352019-10-15 13:14:56 +0200739 }
740 for _, tt := range tests {
741 t.Run(tt.name, func(t *testing.T) {
Matteo Scandolodfa7a972020-11-06 13:03:40 -0800742 if got := SetKVClient(context.Background(), tt.args.backend, tt.args.address, tt.args.DeviceID, tt.args.kvStorePrefix); reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
cbabuabf02352019-10-15 13:14:56 +0200743 t.Errorf("SetKVClient() = %v, want %v", got, tt.want)
744 }
745 })
746 }
747}
748
cbabuabf02352019-10-15 13:14:56 +0200749func Test_newKVClient(t *testing.T) {
750 type args struct {
751 storeType string
752 address string
Neha Sharmacc656962020-04-14 14:26:11 +0000753 timeout time.Duration
cbabuabf02352019-10-15 13:14:56 +0200754 }
755 var kvClient kvstore.Client
756 tests := []struct {
757 name string
758 args args
759 want kvstore.Client
760 wantErr error
761 }{
762 {"newKVClient-1", args{"", "3.3.3.3", 1}, kvClient, errors.New("unsupported-kv-store")},
763 }
764 for _, tt := range tests {
765 t.Run(tt.name, func(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000766 got, err := newKVClient(context.Background(), tt.args.storeType, tt.args.address, tt.args.timeout)
cbabuabf02352019-10-15 13:14:56 +0200767 if got != nil && reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
768 t.Errorf("newKVClient() got = %v, want %v", got, tt.want)
769 }
770 if (err != nil) && reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr) {
771 t.Errorf("newKVClient() error = %v, wantErr %v", err, tt.wantErr)
772 return
773 }
774
775 })
776 }
777}
Esin Karamanccb714b2019-11-29 15:02:06 +0000778
779func TestOpenOltResourceMgr_AddMcastQueueForIntf(t *testing.T) {
780 type args struct {
781 intf uint32
782 gem uint32
783 servicePriority uint32
784 }
785 tests := []struct {
786 name string
787 args args
788 fields *fields
789 }{
790 {"AddMcastQueueForIntf-1", args{0, 4000, 0}, getResMgr()},
791 {"AddMcastQueueForIntf-2", args{1, 4000, 1}, getResMgr()},
792 {"AddMcastQueueForIntf-3", args{2, 4000, 2}, getResMgr()},
793 }
794 for _, tt := range tests {
795 t.Run(tt.name, func(t *testing.T) {
796 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530797 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
798 defer cancel()
799 err := RsrcMgr.AddMcastQueueForIntf(ctx, tt.args.intf, tt.args.gem, tt.args.servicePriority)
Esin Karamanccb714b2019-11-29 15:02:06 +0000800 if err != nil {
801 t.Errorf("%s got err= %s wants nil", tt.name, err)
802 return
803 }
804 })
805 }
806}
807
808func newGroup(groupID uint32, outPorts []uint32) *ofp.OfpGroupEntry {
809 groupDesc := ofp.OfpGroupDesc{
810 Type: ofp.OfpGroupType_OFPGT_ALL,
811 GroupId: groupID,
812 }
813 groupEntry := ofp.OfpGroupEntry{
814 Desc: &groupDesc,
815 }
Esin Karamanccb714b2019-11-29 15:02:06 +0000816 for i := 0; i < len(outPorts); i++ {
Esin Karaman0ebd2a32020-02-09 18:45:36 +0000817 var acts []*ofp.OfpAction
Esin Karamanccb714b2019-11-29 15:02:06 +0000818 acts = append(acts, fu.Output(outPorts[i]))
Esin Karaman0ebd2a32020-02-09 18:45:36 +0000819 bucket := ofp.OfpBucket{
820 Actions: acts,
821 }
822 groupDesc.Buckets = append(groupDesc.Buckets, &bucket)
Esin Karamanccb714b2019-11-29 15:02:06 +0000823 }
Esin Karamanccb714b2019-11-29 15:02:06 +0000824 return &groupEntry
825}
826
827func TestOpenOltResourceMgr_AddFlowGroupToKVStore(t *testing.T) {
828 type args struct {
829 group *ofp.OfpGroupEntry
830 cached bool
831 }
832 //create group 1
833 group1 := newGroup(1, []uint32{1})
834 //create group 2
835 group2 := newGroup(2, []uint32{2})
836 //define test set
837 tests := []struct {
838 name string
839 args args
840 fields *fields
841 }{
842 {"AddFlowGroupToKVStore-1", args{group1, true}, getResMgr()},
843 {"AddFlowGroupToKVStore-2", args{group2, false}, getResMgr()},
844 }
845 //execute tests
846 for _, tt := range tests {
847 t.Run(tt.name, func(t *testing.T) {
848 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530849 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
850 defer cancel()
851 err := RsrcMgr.AddFlowGroupToKVStore(ctx, tt.args.group, tt.args.cached)
Esin Karamanccb714b2019-11-29 15:02:06 +0000852 if err != nil {
853 t.Errorf("%s got err= %s wants nil", tt.name, err)
854 return
855 }
856 })
857 }
858}
859
860func TestOpenOltResourceMgr_RemoveFlowGroupFromKVStore(t *testing.T) {
861 type args struct {
862 groupID uint32
863 cached bool
864 }
865 //define test set
866 tests := []struct {
867 name string
868 args args
869 fields *fields
870 }{
871 {"RemoveFlowGroupFromKVStore-1", args{1, true}, getResMgr()},
872 {"RemoveFlowGroupFromKVStore-2", args{2, false}, getResMgr()},
873 }
874 //execute tests
875 for _, tt := range tests {
876 t.Run(tt.name, func(t *testing.T) {
877 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530878 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
879 defer cancel()
Esin Karamand519bbf2020-07-01 11:16:03 +0000880 err := RsrcMgr.RemoveFlowGroupFromKVStore(ctx, tt.args.groupID, tt.args.cached)
881 if err != nil {
Esin Karamanccb714b2019-11-29 15:02:06 +0000882 t.Errorf("%s got false but wants true", tt.name)
883 return
884 }
885 })
886 }
887}
888
889func TestOpenOltResourceMgr_GetFlowGroupFromKVStore(t *testing.T) {
890 type args struct {
891 groupID uint32
892 cached bool
893 }
894 //define test set
895 tests := []struct {
896 name string
897 args args
898 fields *fields
899 }{
900 {"GetFlowGroupFromKVStore-1", args{1, true}, getResMgr()},
901 {"GetFlowGroupFromKVStore-2", args{2, false}, getResMgr()},
902 {"GetFlowGroupFromKVStore-3", args{1000, false}, getResMgr()},
903 }
904 //execute tests
905 for _, tt := range tests {
906 t.Run(tt.name, func(t *testing.T) {
907 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530908 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
909 defer cancel()
910 exists, groupInfo, err := RsrcMgr.GetFlowGroupFromKVStore(ctx, tt.args.groupID, tt.args.cached)
Esin Karamanccb714b2019-11-29 15:02:06 +0000911 if err != nil {
912 t.Errorf("%s got error but wants nil error", tt.name)
913 return
914 } else if exists && (groupInfo.GroupID == 0) {
915 t.Errorf("%s got true and nil group info but expected not nil group info", tt.name)
916 return
917 } else if tt.args.groupID == 3 && exists {
918 t.Errorf("%s got true but wants false", tt.name)
919 return
920 }
921 })
922 }
923}