blob: 424497792357c8a0d187680a98c7b6b645b7e6a9 [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
khenaidoo106c61a2021-08-11 18:05:46 -040036 "github.com/opencord/voltha-lib-go/v7/pkg/techprofile"
37 "github.com/opencord/voltha-openolt-adapter/pkg/mocks"
38
39 "github.com/opencord/voltha-lib-go/v7/pkg/db"
40 "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore"
41 fu "github.com/opencord/voltha-lib-go/v7/pkg/flows"
42 "github.com/opencord/voltha-lib-go/v7/pkg/log"
43 ponrmgr "github.com/opencord/voltha-lib-go/v7/pkg/ponresourcemanager"
44 ofp "github.com/opencord/voltha-protos/v5/go/openflow_13"
45 "github.com/opencord/voltha-protos/v5/go/openolt"
cbabuabf02352019-10-15 13:14:56 +020046)
47
48func init() {
Kent Hagermane6ff1012020-07-14 15:07:53 -040049 _, _ = log.SetDefaultLogger(log.JSON, log.DebugLevel, nil)
cbabuabf02352019-10-15 13:14:56 +020050}
51
52const (
53 // MeterConfig meter to extract meter
54 MeterConfig = "meter_id"
55 // TpIDSuffixPath to extract Techprofile
Kent Hagermane6ff1012020-07-14 15:07:53 -040056 // TpIDSuffixPath = "tp_id"
cbabuabf02352019-10-15 13:14:56 +020057 // FlowIDInfo to extract flows
58 FlowIDInfo = "flow_id_info"
59 // FlowIds to extract flows
60 FlowIDs = "flow_ids"
61 // GemportIDs to gemport_ids
62 GemportIDs = "gemport_ids"
63 // AllocIDs to extract alloc_ids
64 AllocIDs = "alloc_ids"
65 // GemportIDPool to extract gemport
66 GemportIDPool = "gemport_id_pool"
67 // AllocIDPool to extract allocid
68 AllocIDPool = "alloc_id_pool"
69 // FlowIDpool to extract Flow ids
70 FlowIDpool = "flow_id_pool"
71)
72
cbabubef89432019-10-18 11:47:27 +020073// fields mocks OpenOltResourceMgr struct.
cbabuabf02352019-10-15 13:14:56 +020074type fields struct {
Girish Gowdra76a1b092021-07-28 10:07:04 -070075 DeviceID string
76 Address string
77 Args string
78 KVStore *db.Backend
79 DeviceType string
80 DevInfo *openolt.DeviceInfo
81 PonRsrMgr *ponrmgr.PONResourceManager
82 NumOfPonPorts uint32
83 TechProfileRef techprofile.TechProfileIf
cbabuabf02352019-10-15 13:14:56 +020084}
cbabubef89432019-10-18 11:47:27 +020085
86// MockKVClient mocks the AdapterProxy interface.
cbabuabf02352019-10-15 13:14:56 +020087type MockResKVClient struct {
88}
89
cbabubef89432019-10-18 11:47:27 +020090// getResMgr mocks OpenOltResourceMgr struct.
cbabuabf02352019-10-15 13:14:56 +020091func getResMgr() *fields {
92 var resMgr fields
sbarbaria8910ba2019-11-05 10:12:23 -050093 resMgr.KVStore = &db.Backend{
cbabuabf02352019-10-15 13:14:56 +020094 Client: &MockResKVClient{},
95 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070096 resMgr.PonRsrMgr = &ponrmgr.PONResourceManager{}
cbabuabf02352019-10-15 13:14:56 +020097 ranges := make(map[string]interface{})
98 sharedIdxByType := make(map[string]string)
99 sharedIdxByType["ALLOC_ID"] = "ALLOC_ID"
100 sharedIdxByType["ONU_ID"] = "ONU_ID"
101 sharedIdxByType["GEMPORT_ID"] = "GEMPORT_ID"
102 sharedIdxByType["FLOW_ID"] = "FLOW_ID"
103 ranges["ONU_ID"] = uint32(0)
104 ranges["GEMPORT_ID"] = uint32(0)
105 ranges["ALLOC_ID"] = uint32(0)
106 ranges["FLOW_ID"] = uint32(0)
107 ranges["onu_id_shared"] = uint32(0)
108 ranges["alloc_id_shared"] = uint32(0)
109 ranges["gemport_id_shared"] = uint32(0)
110 ranges["flow_id_shared"] = uint32(0)
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700111 resMgr.NumOfPonPorts = 16
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700112 resMgr.PonRsrMgr.DeviceID = "onu-1"
113 resMgr.PonRsrMgr.IntfIDs = []uint32{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
114 resMgr.PonRsrMgr.KVStore = &db.Backend{
Matteo Scandolo84585372021-03-18 14:21:22 -0700115 Client: &MockResKVClient{},
116 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700117 resMgr.PonRsrMgr.Technology = "XGS-PON"
118 resMgr.PonRsrMgr.PonResourceRanges = ranges
119 resMgr.PonRsrMgr.SharedIdxByType = sharedIdxByType
Girish Gowdra76a1b092021-07-28 10:07:04 -0700120 resMgr.TechProfileRef = mocks.MockTechProfile{}
121
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700122 /*
123 tpMgr, err := tp.NewTechProfile(ctx, resMgr.PonRsrMgr, "etcd", "127.0.0.1", "/")
124 if err != nil {
125 logger.Fatal(ctx, err.Error())
126 }
127 */
Matteo Scandolo84585372021-03-18 14:21:22 -0700128
cbabuabf02352019-10-15 13:14:56 +0200129 return &resMgr
130}
cbabubef89432019-10-18 11:47:27 +0200131
132// List function implemented for KVClient.
npujarec5762e2020-01-01 14:08:48 +0530133func (kvclient *MockResKVClient) List(ctx context.Context, key string) (map[string]*kvstore.KVPair, error) {
cbabuabf02352019-10-15 13:14:56 +0200134 return nil, errors.New("key didn't find")
135}
136
137// Get mock function implementation for KVClient
npujarec5762e2020-01-01 14:08:48 +0530138func (kvclient *MockResKVClient) Get(ctx context.Context, key string) (*kvstore.KVPair, error) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000139 logger.Debugw(ctx, "Warning Warning Warning: Get of MockKVClient called", log.Fields{"key": key})
cbabuabf02352019-10-15 13:14:56 +0200140 if key != "" {
141 if strings.Contains(key, MeterConfig) {
142 var bands []*ofp.OfpMeterBandHeader
143 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DSCP_REMARK,
144 Rate: 1024, Data: &ofp.OfpMeterBandHeader_DscpRemark{DscpRemark: &ofp.OfpMeterBandDscpRemark{PrecLevel: 2}}})
145
146 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DSCP_REMARK,
147 Rate: 1024, Data: &ofp.OfpMeterBandHeader_DscpRemark{DscpRemark: &ofp.OfpMeterBandDscpRemark{PrecLevel: 3}}})
148
Gamze Abakafee36392019-10-03 11:17:24 +0000149 sep := strings.Split(key, "/")[1]
cbabuabf02352019-10-15 13:14:56 +0200150 val, _ := strconv.ParseInt(strings.Split(sep, ",")[1], 10, 32)
151 if uint32(val) > 1 {
152 meterConfig := &ofp.OfpMeterConfig{MeterId: uint32(val), Bands: bands}
153 str, _ := json.Marshal(meterConfig)
154
155 return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
156 }
157 return nil, errors.New("invalid meter")
158 }
159 if strings.Contains(key, FlowIDpool) || strings.Contains(key, GemportIDPool) || strings.Contains(key, AllocIDPool) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000160 logger.Debug(ctx, "Error Error Error Key:", FlowIDpool, GemportIDPool, AllocIDPool)
cbabuabf02352019-10-15 13:14:56 +0200161 data := make(map[string]interface{})
162 data["pool"] = "1024"
163 data["start_idx"] = 1
164 data["end_idx"] = 1024
165 str, _ := json.Marshal(data)
166 return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
167 }
168 if strings.Contains(key, FlowIDInfo) || strings.Contains(key, FlowIDs) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000169 logger.Debug(ctx, "Error Error Error Key:", FlowIDs, FlowIDInfo)
cbabuabf02352019-10-15 13:14:56 +0200170 str, _ := json.Marshal([]uint32{1, 2})
171 return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
172 }
173 if strings.Contains(key, AllocIDs) || strings.Contains(key, GemportIDs) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000174 logger.Debug(ctx, "Error Error Error Key:", AllocIDs, GemportIDs)
cbabuabf02352019-10-15 13:14:56 +0200175 str, _ := json.Marshal(1)
176 return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
177 }
Esin Karamanccb714b2019-11-29 15:02:06 +0000178 if strings.Contains(key, McastQueuesForIntf) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000179 logger.Debug(ctx, "Error Error Error Key:", McastQueuesForIntf)
Esin Karamanccb714b2019-11-29 15:02:06 +0000180 mcastQueues := make(map[uint32][]uint32)
181 mcastQueues[10] = []uint32{4000, 0}
182 str, _ := json.Marshal(mcastQueues)
183 return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
184 }
185 if strings.Contains(key, "flow_groups") && !strings.Contains(key, "1000") {
186 groupInfo := GroupInfo{GroupID: 2, OutPorts: []uint32{2}}
187 str, _ := json.Marshal(groupInfo)
188 return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
189 }
190
cbabuabf02352019-10-15 13:14:56 +0200191 maps := make(map[string]*kvstore.KVPair)
192 maps[key] = &kvstore.KVPair{Key: key}
193 return maps[key], nil
194 }
195 return nil, errors.New("key didn't find")
196}
197
198// Put mock function implementation for KVClient
npujarec5762e2020-01-01 14:08:48 +0530199func (kvclient *MockResKVClient) Put(ctx context.Context, key string, value interface{}) error {
cbabuabf02352019-10-15 13:14:56 +0200200 if key != "" {
201 return nil
202 }
203 return errors.New("key didn't find")
204}
205
206// Delete mock function implementation for KVClient
npujarec5762e2020-01-01 14:08:48 +0530207func (kvclient *MockResKVClient) Delete(ctx context.Context, key string) error {
cbabuabf02352019-10-15 13:14:56 +0200208 return nil
209}
210
serkant.uluderya7b8211e2021-02-24 16:39:18 +0300211// DeleteWithPrefix mock function implementation for KVClient
212func (kvclient *MockResKVClient) DeleteWithPrefix(ctx context.Context, prefix string) error {
213 return nil
214}
215
cbabuabf02352019-10-15 13:14:56 +0200216// Reserve mock function implementation for KVClient
Neha Sharmacc656962020-04-14 14:26:11 +0000217func (kvclient *MockResKVClient) Reserve(ctx context.Context, key string, value interface{}, ttl time.Duration) (interface{}, error) {
cbabuabf02352019-10-15 13:14:56 +0200218 return nil, errors.New("key didn't find")
219}
220
221// ReleaseReservation mock function implementation for KVClient
npujarec5762e2020-01-01 14:08:48 +0530222func (kvclient *MockResKVClient) ReleaseReservation(ctx context.Context, key string) error {
cbabuabf02352019-10-15 13:14:56 +0200223 return nil
224}
225
226// ReleaseAllReservations mock function implementation for KVClient
npujarec5762e2020-01-01 14:08:48 +0530227func (kvclient *MockResKVClient) ReleaseAllReservations(ctx context.Context) error {
cbabuabf02352019-10-15 13:14:56 +0200228 return nil
229}
230
231// RenewReservation mock function implementation for KVClient
npujarec5762e2020-01-01 14:08:48 +0530232func (kvclient *MockResKVClient) RenewReservation(ctx context.Context, key string) error {
cbabuabf02352019-10-15 13:14:56 +0200233 return nil
234}
235
236// Watch mock function implementation for KVClient
Scott Bakere701b862020-02-20 16:19:16 -0800237func (kvclient *MockResKVClient) Watch(ctx context.Context, key string, withPrefix bool) chan *kvstore.Event {
cbabuabf02352019-10-15 13:14:56 +0200238 return nil
239}
240
241// AcquireLock mock function implementation for KVClient
Neha Sharmacc656962020-04-14 14:26:11 +0000242func (kvclient *MockResKVClient) AcquireLock(ctx context.Context, lockName string, timeout time.Duration) error {
cbabuabf02352019-10-15 13:14:56 +0200243 return nil
244}
245
246// ReleaseLock mock function implementation for KVClient
247func (kvclient *MockResKVClient) ReleaseLock(lockName string) error {
248 return nil
249}
250
251// IsConnectionUp mock function implementation for KVClient
npujarec5762e2020-01-01 14:08:48 +0530252func (kvclient *MockResKVClient) IsConnectionUp(ctx context.Context) bool { // timeout in second
cbabuabf02352019-10-15 13:14:56 +0200253 return true
254}
255
256// CloseWatch mock function implementation for KVClient
Neha Sharma96b7bf22020-06-15 10:37:32 +0000257func (kvclient *MockResKVClient) CloseWatch(ctx context.Context, key string, ch chan *kvstore.Event) {
cbabuabf02352019-10-15 13:14:56 +0200258}
259
260// Close mock function implementation for KVClient
Neha Sharma96b7bf22020-06-15 10:37:32 +0000261func (kvclient *MockResKVClient) Close(ctx context.Context) {
cbabuabf02352019-10-15 13:14:56 +0200262}
263
cbabubef89432019-10-18 11:47:27 +0200264// testResMgrObject maps fields type to OpenOltResourceMgr type.
cbabuabf02352019-10-15 13:14:56 +0200265func testResMgrObject(testResMgr *fields) *OpenOltResourceMgr {
Girish Gowdra38d533d2020-03-30 20:38:51 -0700266 var rsrMgr = OpenOltResourceMgr{
Girish Gowdra76a1b092021-07-28 10:07:04 -0700267 DeviceID: testResMgr.DeviceID,
268 Args: testResMgr.Args,
269 KVStore: testResMgr.KVStore,
270 DeviceType: testResMgr.DeviceType,
271 Address: testResMgr.Address,
272 DevInfo: testResMgr.DevInfo,
273 PonRsrMgr: testResMgr.PonRsrMgr,
274 TechprofileRef: testResMgr.TechProfileRef,
cbabuabf02352019-10-15 13:14:56 +0200275 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700276 rsrMgr.InitLocalCache()
Girish Gowdra38d533d2020-03-30 20:38:51 -0700277
278 return &rsrMgr
cbabuabf02352019-10-15 13:14:56 +0200279}
280
281func TestNewResourceMgr(t *testing.T) {
282 type args struct {
Neha Sharma3f221ae2020-04-29 19:02:12 +0000283 deviceID string
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700284 intfID uint32
Neha Sharma3f221ae2020-04-29 19:02:12 +0000285 KVStoreAddress string
286 kvStoreType string
287 deviceType string
288 devInfo *openolt.DeviceInfo
Matteo Scandolodfa7a972020-11-06 13:03:40 -0800289 kvStorePrefix string
cbabuabf02352019-10-15 13:14:56 +0200290 }
291 tests := []struct {
292 name string
293 args args
294 want *OpenOltResourceMgr
295 }{
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700296 {"NewResourceMgr-2", args{"olt1", 0, "1:2", "etcd",
Matteo Scandolodfa7a972020-11-06 13:03:40 -0800297 "onu", &openolt.DeviceInfo{OnuIdStart: 1, OnuIdEnd: 1}, "service/voltha"}, &OpenOltResourceMgr{}},
cbabuabf02352019-10-15 13:14:56 +0200298 }
299 for _, tt := range tests {
300 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530301 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
302 defer cancel()
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700303 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 +0200304 t.Errorf("NewResourceMgr() = %v, want %v", got, tt.want)
305 }
306 })
307 }
308}
309
310func TestOpenOltResourceMgr_Delete(t *testing.T) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700311 type args struct {
312 intfID uint32
313 }
cbabuabf02352019-10-15 13:14:56 +0200314 tests := []struct {
315 name string
316 fields *fields
317 wantErr error
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700318 args args
cbabuabf02352019-10-15 13:14:56 +0200319 }{
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700320 {"Delete-1", getResMgr(), errors.New("failed to clear device resource pool"), args{intfID: 0}},
cbabuabf02352019-10-15 13:14:56 +0200321 }
322 for _, tt := range tests {
323 t.Run(tt.name, func(t *testing.T) {
324 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530325 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
326 defer cancel()
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700327 if err := RsrcMgr.Delete(ctx, tt.args.intfID); (err != nil) && reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr) {
cbabuabf02352019-10-15 13:14:56 +0200328 t.Errorf("Delete() error = %v, wantErr %v", err, tt.wantErr)
329 }
330 })
331 }
332}
333
cbabuabf02352019-10-15 13:14:56 +0200334func TestOpenOltResourceMgr_FreePONResourcesForONU(t *testing.T) {
335 type args struct {
336 intfID uint32
337 onuID uint32
338 uniID uint32
339 }
340 tests := []struct {
341 name string
342 fields *fields
343 args args
344 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700345 {"FreePONResourcesForONU-1", getResMgr(), args{1, 0, 2}},
cbabuabf02352019-10-15 13:14:56 +0200346 }
347 for _, tt := range tests {
348 t.Run(tt.name, func(t *testing.T) {
349 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530350 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
351 defer cancel()
352 RsrcMgr.FreePONResourcesForONU(ctx, tt.args.intfID, tt.args.onuID, tt.args.uniID)
cbabuabf02352019-10-15 13:14:56 +0200353 })
354 }
355}
356
357func TestOpenOltResourceMgr_FreeonuID(t *testing.T) {
358 type args struct {
359 intfID uint32
360 onuID []uint32
361 }
362 tests := []struct {
363 name string
364 fields *fields
365 args args
366 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700367 {"FreeOnuID-1", getResMgr(), args{1, []uint32{1, 2}}},
cbabuabf02352019-10-15 13:14:56 +0200368 }
369 for _, tt := range tests {
370 t.Run(tt.name, func(t *testing.T) {
371 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530372 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
373 defer cancel()
374 RsrcMgr.FreeonuID(ctx, tt.args.intfID, tt.args.onuID)
cbabuabf02352019-10-15 13:14:56 +0200375 })
376 }
377}
378
cbabuabf02352019-10-15 13:14:56 +0200379func TestOpenOltResourceMgr_GetCurrentAllocIDForOnu(t *testing.T) {
380 type args struct {
381 intfID uint32
382 onuID uint32
383 uniID uint32
384 }
385 tests := []struct {
386 name string
387 fields *fields
388 args args
Gamze Abakafee36392019-10-03 11:17:24 +0000389 want []uint32
cbabuabf02352019-10-15 13:14:56 +0200390 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700391 {"GetCurrentAllocIDForOnu-1", getResMgr(), args{1, 2, 2}, []uint32{}},
cbabuabf02352019-10-15 13:14:56 +0200392 }
393 for _, tt := range tests {
394 t.Run(tt.name, func(t *testing.T) {
395 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530396 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
397 defer cancel()
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700398 got := RsrcMgr.GetCurrentAllocIDsForOnu(ctx, tt.args.intfID, tt.args.onuID, tt.args.uniID)
399 if len(got) != len(tt.want) {
Gamze Abakafee36392019-10-03 11:17:24 +0000400 t.Errorf("GetCurrentAllocIDsForOnu() = %v, want %v", got, tt.want)
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700401 } else {
402 for i := range tt.want {
403 if got[i] != tt.want[i] {
404 t.Errorf("GetCurrentAllocIDsForOnu() = %v, want %v", got, tt.want)
405 break
406 }
407 }
cbabuabf02352019-10-15 13:14:56 +0200408 }
409 })
410 }
411}
412
413func TestOpenOltResourceMgr_GetCurrentFlowIDsForOnu(t *testing.T) {
414
415 type args struct {
416 PONIntfID uint32
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530417 ONUID int32
418 UNIID int32
cbabuabf02352019-10-15 13:14:56 +0200419 }
420 tests := []struct {
421 name string
422 fields *fields
423 args args
Girish Gowdraa09aeab2020-09-14 16:30:52 -0700424 want []uint64
cbabuabf02352019-10-15 13:14:56 +0200425 }{
Girish Gowdraa09aeab2020-09-14 16:30:52 -0700426 {"GetCurrentFlowIDsForOnu-1", getResMgr(), args{1, 2, 2}, []uint64{1, 2}},
cbabuabf02352019-10-15 13:14:56 +0200427 }
428 for _, tt := range tests {
429 t.Run(tt.name, func(t *testing.T) {
430 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530431 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
432 defer cancel()
Girish Gowdraa09aeab2020-09-14 16:30:52 -0700433 got, err := RsrcMgr.GetCurrentFlowIDsForOnu(ctx, tt.args.PONIntfID, tt.args.ONUID, tt.args.UNIID)
434 if err != nil {
435 t.Errorf("GetCurrentFlowIDsForOnu() returned error")
436 }
437 if reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
cbabuabf02352019-10-15 13:14:56 +0200438 t.Errorf("GetCurrentFlowIDsForOnu() = %v, want %v", got, tt.want)
439 }
440 })
441 }
442}
443
444func TestOpenOltResourceMgr_GetCurrentGEMPortIDsForOnu(t *testing.T) {
445 type args struct {
446 intfID uint32
447 onuID uint32
448 uniID uint32
449 }
450 tests := []struct {
451 name string
452 fields *fields
453 args args
454 want []uint32
455 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700456 {"GetCurrentGEMPortIDsForOnu-1", getResMgr(), args{1, 2, 2}, []uint32{}},
cbabuabf02352019-10-15 13:14:56 +0200457 }
458 for _, tt := range tests {
459 t.Run(tt.name, func(t *testing.T) {
460 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530461 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
462 defer cancel()
463 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 +0200464 t.Errorf("GetCurrentGEMPortIDsForOnu() = %v, want %v", got, tt.want)
465 }
466 })
467 }
468}
469
Girish Gowdraa482f272021-03-24 23:04:19 -0700470func TestOpenOltResourceMgr_GetMeterInfoForOnu(t *testing.T) {
cbabuabf02352019-10-15 13:14:56 +0200471 type args struct {
472 Direction string
473 IntfID uint32
474 OnuID uint32
475 UniID uint32
Gamze Abakafee36392019-10-03 11:17:24 +0000476 tpID uint32
cbabuabf02352019-10-15 13:14:56 +0200477 }
478 tests := []struct {
479 name string
480 fields *fields
481 args args
Girish Gowdraa482f272021-03-24 23:04:19 -0700482 want *MeterInfo
cbabuabf02352019-10-15 13:14:56 +0200483 wantErr error
484 }{
Girish Gowdraa482f272021-03-24 23:04:19 -0700485 {"GetMeterInfoForOnu", getResMgr(), args{"DOWNSTREAM", 0, 1, 1, 64},
486 &MeterInfo{}, errors.New("failed to get Meter config from kvstore for path")},
487 {"GetMeterInfoForOnu", getResMgr(), args{"DOWNSTREAM", 1, 2, 2, 65},
488 &MeterInfo{}, errors.New("failed to get Meter config from kvstore for path")},
cbabuabf02352019-10-15 13:14:56 +0200489 }
490 for _, tt := range tests {
491 t.Run(tt.name, func(t *testing.T) {
492 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530493 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
494 defer cancel()
Girish Gowdraa482f272021-03-24 23:04:19 -0700495 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 +0200496 if reflect.TypeOf(got) != reflect.TypeOf(tt.want) && err != nil {
Girish Gowdraa482f272021-03-24 23:04:19 -0700497 t.Errorf("GetMeterInfoForOnu() got = %v, want %v", got, tt.want)
cbabuabf02352019-10-15 13:14:56 +0200498 }
499 })
500 }
501}
502
503func TestOpenOltResourceMgr_GetONUID(t *testing.T) {
504 type args struct {
505 ponIntfID uint32
506 }
507 tests := []struct {
508 name string
509 fields *fields
510 args args
511 want uint32
512 wantErr error
513 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700514 {"GetONUID-1", getResMgr(), args{1}, uint32(0), errors.New("json errors")},
cbabuabf02352019-10-15 13:14:56 +0200515 }
516 for _, tt := range tests {
517 t.Run(tt.name, func(t *testing.T) {
518 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530519 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
520 defer cancel()
521 got, err := RsrcMgr.GetONUID(ctx, tt.args.ponIntfID)
cbabuabf02352019-10-15 13:14:56 +0200522 if got != tt.want && err != nil {
523 t.Errorf("GetONUID() got = %v, want %v", got, tt.want)
524 }
525 })
526 }
527}
528
529func TestOpenOltResourceMgr_GetTechProfileIDForOnu(t *testing.T) {
530
531 type args struct {
532 IntfID uint32
533 OnuID uint32
534 UniID uint32
535 }
536 tests := []struct {
537 name string
538 fields *fields
539 args args
Gamze Abakafee36392019-10-03 11:17:24 +0000540 want []uint32
cbabuabf02352019-10-15 13:14:56 +0200541 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700542 {"GetTechProfileIDForOnu-1", getResMgr(), args{1, 2, 2},
Gamze Abakafee36392019-10-03 11:17:24 +0000543 []uint32{1}},
cbabuabf02352019-10-15 13:14:56 +0200544 }
545 for _, tt := range tests {
546 t.Run(tt.name, func(t *testing.T) {
547 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530548 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
549 defer cancel()
550 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 +0200551 t.Errorf("GetTechProfileIDForOnu() = %v, want %v", got, tt.want)
552 }
553 })
554 }
555}
556
cbabuabf02352019-10-15 13:14:56 +0200557func TestOpenOltResourceMgr_RemoveMeterIDForOnu(t *testing.T) {
558
559 type args struct {
560 Direction string
561 IntfID uint32
562 OnuID uint32
563 UniID uint32
Gamze Abakafee36392019-10-03 11:17:24 +0000564 tpID uint32
cbabuabf02352019-10-15 13:14:56 +0200565 }
566 tests := []struct {
567 name string
568 fields *fields
569 args args
570 wantErr error
571 }{
Gamze Abakafee36392019-10-03 11:17:24 +0000572 {"RemoveMeterIdForOnu-1", getResMgr(), args{"DOWNSTREAM", 1, 1, 1, 64},
cbabuabf02352019-10-15 13:14:56 +0200573 errors.New("failed to delete meter id %s from kvstore")},
574 }
575 for _, tt := range tests {
576 t.Run(tt.name, func(t *testing.T) {
577 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530578 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
579 defer cancel()
Girish Gowdraa482f272021-03-24 23:04:19 -0700580 if err := RsrcMgr.RemoveMeterInfoForOnu(ctx, tt.args.Direction, tt.args.IntfID, tt.args.OnuID, tt.args.UniID,
Gamze Abakafee36392019-10-03 11:17:24 +0000581 tt.args.tpID); reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr) && err != nil {
cbabuabf02352019-10-15 13:14:56 +0200582 t.Errorf("RemoveMeterIDForOnu() error = %v, wantErr %v", err, tt.wantErr)
583 }
584 })
585 }
586}
587
588func TestOpenOltResourceMgr_RemoveTechProfileIDForOnu(t *testing.T) {
589 type args struct {
590 IntfID uint32
591 OnuID uint32
592 UniID uint32
Gamze Abakafee36392019-10-03 11:17:24 +0000593 tpID uint32
cbabuabf02352019-10-15 13:14:56 +0200594 }
595 tests := []struct {
596 name string
597 fields *fields
598 args args
599 wantErr error
600 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700601 {"RemoveTechProfileIDForOnu-1", getResMgr(), args{1, 2, 2, 64},
cbabuabf02352019-10-15 13:14:56 +0200602 errors.New("failed to delete techprofile id resource %s in KV store")},
603 }
604 for _, tt := range tests {
605 t.Run(tt.name, func(t *testing.T) {
606 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530607 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
608 defer cancel()
609 if err := RsrcMgr.RemoveTechProfileIDForOnu(ctx, tt.args.IntfID, tt.args.OnuID, tt.args.UniID,
Gamze Abakafee36392019-10-03 11:17:24 +0000610 tt.args.tpID); reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr) && err != nil {
cbabuabf02352019-10-15 13:14:56 +0200611 t.Errorf("RemoveTechProfileIDForOnu() error = %v, wantErr %v", err, tt.wantErr)
612 }
613 })
614 }
615}
616
617func TestOpenOltResourceMgr_UpdateAllocIdsForOnu(t *testing.T) {
618 type args struct {
619 ponPort uint32
620 onuID uint32
621 uniID uint32
622 allocID []uint32
623 }
624 tests := []struct {
625 name string
626 fields *fields
627 args args
628 wantErr error
629 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700630 {"UpdateAllocIdsForOnu-1", getResMgr(), args{1, 2, 2, []uint32{1, 2}},
cbabuabf02352019-10-15 13:14:56 +0200631 errors.New("")},
632 }
633 for _, tt := range tests {
634 t.Run(tt.name, func(t *testing.T) {
635 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530636 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
637 defer cancel()
638 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 +0200639 t.Errorf("UpdateAllocIdsForOnu() error = %v, wantErr %v", err, tt.wantErr)
640 }
641 })
642 }
643}
644
cbabuabf02352019-10-15 13:14:56 +0200645func TestOpenOltResourceMgr_UpdateGEMPortIDsForOnu(t *testing.T) {
646
647 type args struct {
648 ponPort uint32
649 onuID uint32
650 uniID uint32
651 GEMPortList []uint32
652 }
653 tests := []struct {
654 name string
655 fields *fields
656 args args
657 wantErr error
658 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700659 {"UpdateGEMPortIDsForOnu-1", getResMgr(), args{1, 2, 2,
cbabuabf02352019-10-15 13:14:56 +0200660 []uint32{1, 2}}, errors.New("failed to update resource")},
661 }
662 for _, tt := range tests {
663 t.Run(tt.name, func(t *testing.T) {
664 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530665 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
666 defer cancel()
667 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 +0200668 t.Errorf("UpdateGEMPortIDsForOnu() error = %v, wantErr %v", err, tt.wantErr)
669 }
670 })
671 }
672}
673
cbabuabf02352019-10-15 13:14:56 +0200674func TestOpenOltResourceMgr_UpdateMeterIDForOnu(t *testing.T) {
675 type args struct {
Girish Gowdraa482f272021-03-24 23:04:19 -0700676 Direction string
677 IntfID uint32
678 OnuID uint32
679 UniID uint32
680 tpID uint32
681 MeterInfo *MeterInfo
cbabuabf02352019-10-15 13:14:56 +0200682 }
683 tests := []struct {
684 name string
685 fields *fields
686 args args
687 wantErr error
688 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700689 {"UpdateMeterIDForOnu-1", getResMgr(), args{"DOWNSTREAM", 1, 2,
Girish Gowdraa482f272021-03-24 23:04:19 -0700690 2, 64, &MeterInfo{}}, errors.New("failed to get Meter config from kvstore for path")},
cbabuabf02352019-10-15 13:14:56 +0200691 }
692 for _, tt := range tests {
693 t.Run(tt.name, func(t *testing.T) {
694 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530695 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
696 defer cancel()
Girish Gowdraa482f272021-03-24 23:04:19 -0700697 if err := RsrcMgr.StoreMeterInfoForOnu(ctx, tt.args.Direction, tt.args.IntfID, tt.args.OnuID, tt.args.UniID,
698 tt.args.tpID, tt.args.MeterInfo); reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr) && err != nil {
cbabuabf02352019-10-15 13:14:56 +0200699 t.Errorf("UpdateMeterIDForOnu() got = %v, want %v", err, tt.wantErr)
700 }
701 })
702 }
703}
704
705func TestOpenOltResourceMgr_UpdateTechProfileIDForOnu(t *testing.T) {
706 type args struct {
707 IntfID uint32
708 OnuID uint32
709 UniID uint32
710 TpID uint32
711 }
712 tests := []struct {
713 name string
714 fields *fields
715 args args
716 wantErr error
717 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700718 {"UpdateTechProfileIDForOnu-1", getResMgr(), args{1, 2, 2,
cbabuabf02352019-10-15 13:14:56 +0200719 2}, errors.New("failed to update resource")},
720 }
721 for _, tt := range tests {
722 t.Run(tt.name, func(t *testing.T) {
723 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530724 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
725 defer cancel()
726 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 +0200727 t.Errorf("UpdateTechProfileIDForOnu() got = %v, want %v", err, tt.wantErr)
728 }
729 })
730 }
731}
732
733func TestSetKVClient(t *testing.T) {
734 type args struct {
Matteo Scandolodfa7a972020-11-06 13:03:40 -0800735 backend string
736 address string
737 DeviceID string
738 kvStorePrefix string
cbabuabf02352019-10-15 13:14:56 +0200739 }
740 tests := []struct {
741 name string
742 args args
sbarbaria8910ba2019-11-05 10:12:23 -0500743 want *db.Backend
cbabuabf02352019-10-15 13:14:56 +0200744 }{
serkant.uluderya7b8211e2021-02-24 16:39:18 +0300745 {"setKVClient-1", args{"etcd", "1.1.1.1:1", "olt1", "service/voltha"}, &db.Backend{}},
cbabuabf02352019-10-15 13:14:56 +0200746 }
747 for _, tt := range tests {
748 t.Run(tt.name, func(t *testing.T) {
Matteo Scandolodfa7a972020-11-06 13:03:40 -0800749 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 +0200750 t.Errorf("SetKVClient() = %v, want %v", got, tt.want)
751 }
752 })
753 }
754}
755
cbabuabf02352019-10-15 13:14:56 +0200756func Test_newKVClient(t *testing.T) {
757 type args struct {
758 storeType string
759 address string
Neha Sharmacc656962020-04-14 14:26:11 +0000760 timeout time.Duration
cbabuabf02352019-10-15 13:14:56 +0200761 }
762 var kvClient kvstore.Client
763 tests := []struct {
764 name string
765 args args
766 want kvstore.Client
767 wantErr error
768 }{
769 {"newKVClient-1", args{"", "3.3.3.3", 1}, kvClient, errors.New("unsupported-kv-store")},
770 }
771 for _, tt := range tests {
772 t.Run(tt.name, func(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000773 got, err := newKVClient(context.Background(), tt.args.storeType, tt.args.address, tt.args.timeout)
cbabuabf02352019-10-15 13:14:56 +0200774 if got != nil && reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
775 t.Errorf("newKVClient() got = %v, want %v", got, tt.want)
776 }
777 if (err != nil) && reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr) {
778 t.Errorf("newKVClient() error = %v, wantErr %v", err, tt.wantErr)
779 return
780 }
781
782 })
783 }
784}
Esin Karamanccb714b2019-11-29 15:02:06 +0000785
786func TestOpenOltResourceMgr_AddMcastQueueForIntf(t *testing.T) {
787 type args struct {
788 intf uint32
789 gem uint32
790 servicePriority uint32
791 }
792 tests := []struct {
793 name string
794 args args
795 fields *fields
796 }{
797 {"AddMcastQueueForIntf-1", args{0, 4000, 0}, getResMgr()},
798 {"AddMcastQueueForIntf-2", args{1, 4000, 1}, getResMgr()},
799 {"AddMcastQueueForIntf-3", args{2, 4000, 2}, getResMgr()},
800 }
801 for _, tt := range tests {
802 t.Run(tt.name, func(t *testing.T) {
803 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530804 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
805 defer cancel()
806 err := RsrcMgr.AddMcastQueueForIntf(ctx, tt.args.intf, tt.args.gem, tt.args.servicePriority)
Esin Karamanccb714b2019-11-29 15:02:06 +0000807 if err != nil {
808 t.Errorf("%s got err= %s wants nil", tt.name, err)
809 return
810 }
811 })
812 }
813}
814
815func newGroup(groupID uint32, outPorts []uint32) *ofp.OfpGroupEntry {
816 groupDesc := ofp.OfpGroupDesc{
817 Type: ofp.OfpGroupType_OFPGT_ALL,
818 GroupId: groupID,
819 }
820 groupEntry := ofp.OfpGroupEntry{
821 Desc: &groupDesc,
822 }
Esin Karamanccb714b2019-11-29 15:02:06 +0000823 for i := 0; i < len(outPorts); i++ {
Esin Karaman0ebd2a32020-02-09 18:45:36 +0000824 var acts []*ofp.OfpAction
Esin Karamanccb714b2019-11-29 15:02:06 +0000825 acts = append(acts, fu.Output(outPorts[i]))
Esin Karaman0ebd2a32020-02-09 18:45:36 +0000826 bucket := ofp.OfpBucket{
827 Actions: acts,
828 }
829 groupDesc.Buckets = append(groupDesc.Buckets, &bucket)
Esin Karamanccb714b2019-11-29 15:02:06 +0000830 }
Esin Karamanccb714b2019-11-29 15:02:06 +0000831 return &groupEntry
832}
833
834func TestOpenOltResourceMgr_AddFlowGroupToKVStore(t *testing.T) {
835 type args struct {
836 group *ofp.OfpGroupEntry
837 cached bool
838 }
839 //create group 1
840 group1 := newGroup(1, []uint32{1})
841 //create group 2
842 group2 := newGroup(2, []uint32{2})
843 //define test set
844 tests := []struct {
845 name string
846 args args
847 fields *fields
848 }{
849 {"AddFlowGroupToKVStore-1", args{group1, true}, getResMgr()},
850 {"AddFlowGroupToKVStore-2", args{group2, false}, getResMgr()},
851 }
852 //execute tests
853 for _, tt := range tests {
854 t.Run(tt.name, func(t *testing.T) {
855 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530856 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
857 defer cancel()
858 err := RsrcMgr.AddFlowGroupToKVStore(ctx, tt.args.group, tt.args.cached)
Esin Karamanccb714b2019-11-29 15:02:06 +0000859 if err != nil {
860 t.Errorf("%s got err= %s wants nil", tt.name, err)
861 return
862 }
863 })
864 }
865}
866
867func TestOpenOltResourceMgr_RemoveFlowGroupFromKVStore(t *testing.T) {
868 type args struct {
869 groupID uint32
870 cached bool
871 }
872 //define test set
873 tests := []struct {
874 name string
875 args args
876 fields *fields
877 }{
878 {"RemoveFlowGroupFromKVStore-1", args{1, true}, getResMgr()},
879 {"RemoveFlowGroupFromKVStore-2", args{2, false}, getResMgr()},
880 }
881 //execute tests
882 for _, tt := range tests {
883 t.Run(tt.name, func(t *testing.T) {
884 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530885 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
886 defer cancel()
Esin Karamand519bbf2020-07-01 11:16:03 +0000887 err := RsrcMgr.RemoveFlowGroupFromKVStore(ctx, tt.args.groupID, tt.args.cached)
888 if err != nil {
Esin Karamanccb714b2019-11-29 15:02:06 +0000889 t.Errorf("%s got false but wants true", tt.name)
890 return
891 }
892 })
893 }
894}
895
896func TestOpenOltResourceMgr_GetFlowGroupFromKVStore(t *testing.T) {
897 type args struct {
898 groupID uint32
899 cached bool
900 }
901 //define test set
902 tests := []struct {
903 name string
904 args args
905 fields *fields
906 }{
907 {"GetFlowGroupFromKVStore-1", args{1, true}, getResMgr()},
908 {"GetFlowGroupFromKVStore-2", args{2, false}, getResMgr()},
909 {"GetFlowGroupFromKVStore-3", args{1000, false}, getResMgr()},
910 }
911 //execute tests
912 for _, tt := range tests {
913 t.Run(tt.name, func(t *testing.T) {
914 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530915 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
916 defer cancel()
917 exists, groupInfo, err := RsrcMgr.GetFlowGroupFromKVStore(ctx, tt.args.groupID, tt.args.cached)
Esin Karamanccb714b2019-11-29 15:02:06 +0000918 if err != nil {
919 t.Errorf("%s got error but wants nil error", tt.name)
920 return
921 } else if exists && (groupInfo.GroupID == 0) {
922 t.Errorf("%s got true and nil group info but expected not nil group info", tt.name)
923 return
924 } else if tt.args.groupID == 3 && exists {
925 t.Errorf("%s got true but wants false", tt.name)
926 return
927 }
928 })
929 }
930}