blob: 443f418f2fa0a756a871c4aa9fa0a04cba6ec6ef [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"
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070030 "github.com/opencord/voltha-openolt-adapter/pkg/mocks"
serkant.uluderya7b8211e2021-02-24 16:39:18 +030031 "reflect"
32 "strconv"
33 "strings"
serkant.uluderya7b8211e2021-02-24 16:39:18 +030034 "testing"
35 "time"
36
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070037 "github.com/opencord/voltha-lib-go/v5/pkg/db"
38 "github.com/opencord/voltha-lib-go/v5/pkg/db/kvstore"
39 fu "github.com/opencord/voltha-lib-go/v5/pkg/flows"
40 "github.com/opencord/voltha-lib-go/v5/pkg/log"
41 ponrmgr "github.com/opencord/voltha-lib-go/v5/pkg/ponresourcemanager"
Girish Gowdraa09aeab2020-09-14 16:30:52 -070042 ofp "github.com/opencord/voltha-protos/v4/go/openflow_13"
43 "github.com/opencord/voltha-protos/v4/go/openolt"
cbabuabf02352019-10-15 13:14:56 +020044)
45
46func init() {
Kent Hagermane6ff1012020-07-14 15:07:53 -040047 _, _ = log.SetDefaultLogger(log.JSON, log.DebugLevel, nil)
cbabuabf02352019-10-15 13:14:56 +020048}
49
50const (
51 // MeterConfig meter to extract meter
52 MeterConfig = "meter_id"
53 // TpIDSuffixPath to extract Techprofile
Kent Hagermane6ff1012020-07-14 15:07:53 -040054 // TpIDSuffixPath = "tp_id"
cbabuabf02352019-10-15 13:14:56 +020055 // FlowIDInfo to extract flows
56 FlowIDInfo = "flow_id_info"
57 // FlowIds to extract flows
58 FlowIDs = "flow_ids"
59 // GemportIDs to gemport_ids
60 GemportIDs = "gemport_ids"
61 // AllocIDs to extract alloc_ids
62 AllocIDs = "alloc_ids"
63 // GemportIDPool to extract gemport
64 GemportIDPool = "gemport_id_pool"
65 // AllocIDPool to extract allocid
66 AllocIDPool = "alloc_id_pool"
67 // FlowIDpool to extract Flow ids
68 FlowIDpool = "flow_id_pool"
69)
70
cbabubef89432019-10-18 11:47:27 +020071// fields mocks OpenOltResourceMgr struct.
cbabuabf02352019-10-15 13:14:56 +020072type fields struct {
Girish Gowdra38d533d2020-03-30 20:38:51 -070073 DeviceID string
Neha Sharma3f221ae2020-04-29 19:02:12 +000074 Address string
Girish Gowdra38d533d2020-03-30 20:38:51 -070075 Args string
76 KVStore *db.Backend
77 DeviceType string
Girish Gowdra38d533d2020-03-30 20:38:51 -070078 DevInfo *openolt.DeviceInfo
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070079 PonRsrMgr *ponrmgr.PONResourceManager
Girish Gowdra38d533d2020-03-30 20:38:51 -070080 NumOfPonPorts uint32
cbabuabf02352019-10-15 13:14:56 +020081}
cbabubef89432019-10-18 11:47:27 +020082
83// MockKVClient mocks the AdapterProxy interface.
cbabuabf02352019-10-15 13:14:56 +020084type MockResKVClient struct {
85}
86
cbabubef89432019-10-18 11:47:27 +020087// getResMgr mocks OpenOltResourceMgr struct.
cbabuabf02352019-10-15 13:14:56 +020088func getResMgr() *fields {
89 var resMgr fields
sbarbaria8910ba2019-11-05 10:12:23 -050090 resMgr.KVStore = &db.Backend{
cbabuabf02352019-10-15 13:14:56 +020091 Client: &MockResKVClient{},
92 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -070093 resMgr.PonRsrMgr = &ponrmgr.PONResourceManager{}
cbabuabf02352019-10-15 13:14:56 +020094 ranges := make(map[string]interface{})
95 sharedIdxByType := make(map[string]string)
96 sharedIdxByType["ALLOC_ID"] = "ALLOC_ID"
97 sharedIdxByType["ONU_ID"] = "ONU_ID"
98 sharedIdxByType["GEMPORT_ID"] = "GEMPORT_ID"
99 sharedIdxByType["FLOW_ID"] = "FLOW_ID"
100 ranges["ONU_ID"] = uint32(0)
101 ranges["GEMPORT_ID"] = uint32(0)
102 ranges["ALLOC_ID"] = uint32(0)
103 ranges["FLOW_ID"] = uint32(0)
104 ranges["onu_id_shared"] = uint32(0)
105 ranges["alloc_id_shared"] = uint32(0)
106 ranges["gemport_id_shared"] = uint32(0)
107 ranges["flow_id_shared"] = uint32(0)
Girish Gowdrafb3d6102020-10-16 16:32:36 -0700108 resMgr.NumOfPonPorts = 16
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700109 resMgr.PonRsrMgr.DeviceID = "onu-1"
110 resMgr.PonRsrMgr.IntfIDs = []uint32{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
111 resMgr.PonRsrMgr.KVStore = &db.Backend{
Matteo Scandolo84585372021-03-18 14:21:22 -0700112 Client: &MockResKVClient{},
113 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700114 resMgr.PonRsrMgr.Technology = "XGS-PON"
115 resMgr.PonRsrMgr.PonResourceRanges = ranges
116 resMgr.PonRsrMgr.SharedIdxByType = sharedIdxByType
117 /*
118 tpMgr, err := tp.NewTechProfile(ctx, resMgr.PonRsrMgr, "etcd", "127.0.0.1", "/")
119 if err != nil {
120 logger.Fatal(ctx, err.Error())
121 }
122 */
123 resMgr.PonRsrMgr.TechProfileMgr = &mocks.MockTechProfile{TpID: 64}
Matteo Scandolo84585372021-03-18 14:21:22 -0700124
cbabuabf02352019-10-15 13:14:56 +0200125 return &resMgr
126}
cbabubef89432019-10-18 11:47:27 +0200127
128// List function implemented for KVClient.
npujarec5762e2020-01-01 14:08:48 +0530129func (kvclient *MockResKVClient) List(ctx context.Context, key string) (map[string]*kvstore.KVPair, error) {
cbabuabf02352019-10-15 13:14:56 +0200130 return nil, errors.New("key didn't find")
131}
132
133// Get mock function implementation for KVClient
npujarec5762e2020-01-01 14:08:48 +0530134func (kvclient *MockResKVClient) Get(ctx context.Context, key string) (*kvstore.KVPair, error) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000135 logger.Debugw(ctx, "Warning Warning Warning: Get of MockKVClient called", log.Fields{"key": key})
cbabuabf02352019-10-15 13:14:56 +0200136 if key != "" {
137 if strings.Contains(key, MeterConfig) {
138 var bands []*ofp.OfpMeterBandHeader
139 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DSCP_REMARK,
140 Rate: 1024, Data: &ofp.OfpMeterBandHeader_DscpRemark{DscpRemark: &ofp.OfpMeterBandDscpRemark{PrecLevel: 2}}})
141
142 bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DSCP_REMARK,
143 Rate: 1024, Data: &ofp.OfpMeterBandHeader_DscpRemark{DscpRemark: &ofp.OfpMeterBandDscpRemark{PrecLevel: 3}}})
144
Gamze Abakafee36392019-10-03 11:17:24 +0000145 sep := strings.Split(key, "/")[1]
cbabuabf02352019-10-15 13:14:56 +0200146 val, _ := strconv.ParseInt(strings.Split(sep, ",")[1], 10, 32)
147 if uint32(val) > 1 {
148 meterConfig := &ofp.OfpMeterConfig{MeterId: uint32(val), Bands: bands}
149 str, _ := json.Marshal(meterConfig)
150
151 return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
152 }
153 return nil, errors.New("invalid meter")
154 }
155 if strings.Contains(key, FlowIDpool) || strings.Contains(key, GemportIDPool) || strings.Contains(key, AllocIDPool) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000156 logger.Debug(ctx, "Error Error Error Key:", FlowIDpool, GemportIDPool, AllocIDPool)
cbabuabf02352019-10-15 13:14:56 +0200157 data := make(map[string]interface{})
158 data["pool"] = "1024"
159 data["start_idx"] = 1
160 data["end_idx"] = 1024
161 str, _ := json.Marshal(data)
162 return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
163 }
164 if strings.Contains(key, FlowIDInfo) || strings.Contains(key, FlowIDs) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000165 logger.Debug(ctx, "Error Error Error Key:", FlowIDs, FlowIDInfo)
cbabuabf02352019-10-15 13:14:56 +0200166 str, _ := json.Marshal([]uint32{1, 2})
167 return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
168 }
169 if strings.Contains(key, AllocIDs) || strings.Contains(key, GemportIDs) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000170 logger.Debug(ctx, "Error Error Error Key:", AllocIDs, GemportIDs)
cbabuabf02352019-10-15 13:14:56 +0200171 str, _ := json.Marshal(1)
172 return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
173 }
Esin Karamanccb714b2019-11-29 15:02:06 +0000174 if strings.Contains(key, McastQueuesForIntf) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000175 logger.Debug(ctx, "Error Error Error Key:", McastQueuesForIntf)
Esin Karamanccb714b2019-11-29 15:02:06 +0000176 mcastQueues := make(map[uint32][]uint32)
177 mcastQueues[10] = []uint32{4000, 0}
178 str, _ := json.Marshal(mcastQueues)
179 return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
180 }
181 if strings.Contains(key, "flow_groups") && !strings.Contains(key, "1000") {
182 groupInfo := GroupInfo{GroupID: 2, OutPorts: []uint32{2}}
183 str, _ := json.Marshal(groupInfo)
184 return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil
185 }
186
cbabuabf02352019-10-15 13:14:56 +0200187 maps := make(map[string]*kvstore.KVPair)
188 maps[key] = &kvstore.KVPair{Key: key}
189 return maps[key], nil
190 }
191 return nil, errors.New("key didn't find")
192}
193
194// Put mock function implementation for KVClient
npujarec5762e2020-01-01 14:08:48 +0530195func (kvclient *MockResKVClient) Put(ctx context.Context, key string, value interface{}) error {
cbabuabf02352019-10-15 13:14:56 +0200196 if key != "" {
197 return nil
198 }
199 return errors.New("key didn't find")
200}
201
202// Delete mock function implementation for KVClient
npujarec5762e2020-01-01 14:08:48 +0530203func (kvclient *MockResKVClient) Delete(ctx context.Context, key string) error {
cbabuabf02352019-10-15 13:14:56 +0200204 return nil
205}
206
serkant.uluderya7b8211e2021-02-24 16:39:18 +0300207// DeleteWithPrefix mock function implementation for KVClient
208func (kvclient *MockResKVClient) DeleteWithPrefix(ctx context.Context, prefix string) error {
209 return nil
210}
211
cbabuabf02352019-10-15 13:14:56 +0200212// Reserve mock function implementation for KVClient
Neha Sharmacc656962020-04-14 14:26:11 +0000213func (kvclient *MockResKVClient) Reserve(ctx context.Context, key string, value interface{}, ttl time.Duration) (interface{}, error) {
cbabuabf02352019-10-15 13:14:56 +0200214 return nil, errors.New("key didn't find")
215}
216
217// ReleaseReservation mock function implementation for KVClient
npujarec5762e2020-01-01 14:08:48 +0530218func (kvclient *MockResKVClient) ReleaseReservation(ctx context.Context, key string) error {
cbabuabf02352019-10-15 13:14:56 +0200219 return nil
220}
221
222// ReleaseAllReservations mock function implementation for KVClient
npujarec5762e2020-01-01 14:08:48 +0530223func (kvclient *MockResKVClient) ReleaseAllReservations(ctx context.Context) error {
cbabuabf02352019-10-15 13:14:56 +0200224 return nil
225}
226
227// RenewReservation mock function implementation for KVClient
npujarec5762e2020-01-01 14:08:48 +0530228func (kvclient *MockResKVClient) RenewReservation(ctx context.Context, key string) error {
cbabuabf02352019-10-15 13:14:56 +0200229 return nil
230}
231
232// Watch mock function implementation for KVClient
Scott Bakere701b862020-02-20 16:19:16 -0800233func (kvclient *MockResKVClient) Watch(ctx context.Context, key string, withPrefix bool) chan *kvstore.Event {
cbabuabf02352019-10-15 13:14:56 +0200234 return nil
235}
236
237// AcquireLock mock function implementation for KVClient
Neha Sharmacc656962020-04-14 14:26:11 +0000238func (kvclient *MockResKVClient) AcquireLock(ctx context.Context, lockName string, timeout time.Duration) error {
cbabuabf02352019-10-15 13:14:56 +0200239 return nil
240}
241
242// ReleaseLock mock function implementation for KVClient
243func (kvclient *MockResKVClient) ReleaseLock(lockName string) error {
244 return nil
245}
246
247// IsConnectionUp mock function implementation for KVClient
npujarec5762e2020-01-01 14:08:48 +0530248func (kvclient *MockResKVClient) IsConnectionUp(ctx context.Context) bool { // timeout in second
cbabuabf02352019-10-15 13:14:56 +0200249 return true
250}
251
252// CloseWatch mock function implementation for KVClient
Neha Sharma96b7bf22020-06-15 10:37:32 +0000253func (kvclient *MockResKVClient) CloseWatch(ctx context.Context, key string, ch chan *kvstore.Event) {
cbabuabf02352019-10-15 13:14:56 +0200254}
255
256// Close mock function implementation for KVClient
Neha Sharma96b7bf22020-06-15 10:37:32 +0000257func (kvclient *MockResKVClient) Close(ctx context.Context) {
cbabuabf02352019-10-15 13:14:56 +0200258}
259
cbabubef89432019-10-18 11:47:27 +0200260// testResMgrObject maps fields type to OpenOltResourceMgr type.
cbabuabf02352019-10-15 13:14:56 +0200261func testResMgrObject(testResMgr *fields) *OpenOltResourceMgr {
Girish Gowdra38d533d2020-03-30 20:38:51 -0700262 var rsrMgr = OpenOltResourceMgr{
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700263 DeviceID: testResMgr.DeviceID,
264 Args: testResMgr.Args,
265 KVStore: testResMgr.KVStore,
266 DeviceType: testResMgr.DeviceType,
267 Address: testResMgr.Address,
268 DevInfo: testResMgr.DevInfo,
269 PonRsrMgr: testResMgr.PonRsrMgr,
cbabuabf02352019-10-15 13:14:56 +0200270 }
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700271 rsrMgr.InitLocalCache()
Girish Gowdra38d533d2020-03-30 20:38:51 -0700272
273 return &rsrMgr
cbabuabf02352019-10-15 13:14:56 +0200274}
275
276func TestNewResourceMgr(t *testing.T) {
277 type args struct {
Neha Sharma3f221ae2020-04-29 19:02:12 +0000278 deviceID string
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700279 intfID uint32
Neha Sharma3f221ae2020-04-29 19:02:12 +0000280 KVStoreAddress string
281 kvStoreType string
282 deviceType string
283 devInfo *openolt.DeviceInfo
Matteo Scandolodfa7a972020-11-06 13:03:40 -0800284 kvStorePrefix string
cbabuabf02352019-10-15 13:14:56 +0200285 }
286 tests := []struct {
287 name string
288 args args
289 want *OpenOltResourceMgr
290 }{
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700291 {"NewResourceMgr-2", args{"olt1", 0, "1:2", "etcd",
Matteo Scandolodfa7a972020-11-06 13:03:40 -0800292 "onu", &openolt.DeviceInfo{OnuIdStart: 1, OnuIdEnd: 1}, "service/voltha"}, &OpenOltResourceMgr{}},
cbabuabf02352019-10-15 13:14:56 +0200293 }
294 for _, tt := range tests {
295 t.Run(tt.name, func(t *testing.T) {
npujarec5762e2020-01-01 14:08:48 +0530296 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
297 defer cancel()
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700298 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 +0200299 t.Errorf("NewResourceMgr() = %v, want %v", got, tt.want)
300 }
301 })
302 }
303}
304
305func TestOpenOltResourceMgr_Delete(t *testing.T) {
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700306 type args struct {
307 intfID uint32
308 }
cbabuabf02352019-10-15 13:14:56 +0200309 tests := []struct {
310 name string
311 fields *fields
312 wantErr error
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700313 args args
cbabuabf02352019-10-15 13:14:56 +0200314 }{
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700315 {"Delete-1", getResMgr(), errors.New("failed to clear device resource pool"), args{intfID: 0}},
cbabuabf02352019-10-15 13:14:56 +0200316 }
317 for _, tt := range tests {
318 t.Run(tt.name, func(t *testing.T) {
319 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530320 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
321 defer cancel()
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700322 if err := RsrcMgr.Delete(ctx, tt.args.intfID); (err != nil) && reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr) {
cbabuabf02352019-10-15 13:14:56 +0200323 t.Errorf("Delete() error = %v, wantErr %v", err, tt.wantErr)
324 }
325 })
326 }
327}
328
cbabuabf02352019-10-15 13:14:56 +0200329func TestOpenOltResourceMgr_FreePONResourcesForONU(t *testing.T) {
330 type args struct {
331 intfID uint32
332 onuID uint32
333 uniID uint32
334 }
335 tests := []struct {
336 name string
337 fields *fields
338 args args
339 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700340 {"FreePONResourcesForONU-1", getResMgr(), args{1, 0, 2}},
cbabuabf02352019-10-15 13:14:56 +0200341 }
342 for _, tt := range tests {
343 t.Run(tt.name, func(t *testing.T) {
344 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530345 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
346 defer cancel()
347 RsrcMgr.FreePONResourcesForONU(ctx, tt.args.intfID, tt.args.onuID, tt.args.uniID)
cbabuabf02352019-10-15 13:14:56 +0200348 })
349 }
350}
351
352func TestOpenOltResourceMgr_FreeonuID(t *testing.T) {
353 type args struct {
354 intfID uint32
355 onuID []uint32
356 }
357 tests := []struct {
358 name string
359 fields *fields
360 args args
361 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700362 {"FreeOnuID-1", getResMgr(), args{1, []uint32{1, 2}}},
cbabuabf02352019-10-15 13:14:56 +0200363 }
364 for _, tt := range tests {
365 t.Run(tt.name, func(t *testing.T) {
366 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530367 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
368 defer cancel()
369 RsrcMgr.FreeonuID(ctx, tt.args.intfID, tt.args.onuID)
cbabuabf02352019-10-15 13:14:56 +0200370 })
371 }
372}
373
cbabuabf02352019-10-15 13:14:56 +0200374func TestOpenOltResourceMgr_GetCurrentAllocIDForOnu(t *testing.T) {
375 type args struct {
376 intfID uint32
377 onuID uint32
378 uniID uint32
379 }
380 tests := []struct {
381 name string
382 fields *fields
383 args args
Gamze Abakafee36392019-10-03 11:17:24 +0000384 want []uint32
cbabuabf02352019-10-15 13:14:56 +0200385 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700386 {"GetCurrentAllocIDForOnu-1", getResMgr(), args{1, 2, 2}, []uint32{}},
cbabuabf02352019-10-15 13:14:56 +0200387 }
388 for _, tt := range tests {
389 t.Run(tt.name, func(t *testing.T) {
390 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530391 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
392 defer cancel()
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700393 got := RsrcMgr.GetCurrentAllocIDsForOnu(ctx, tt.args.intfID, tt.args.onuID, tt.args.uniID)
394 if len(got) != len(tt.want) {
Gamze Abakafee36392019-10-03 11:17:24 +0000395 t.Errorf("GetCurrentAllocIDsForOnu() = %v, want %v", got, tt.want)
Girish Gowdra8a0bdcd2021-05-13 12:31:04 -0700396 } else {
397 for i := range tt.want {
398 if got[i] != tt.want[i] {
399 t.Errorf("GetCurrentAllocIDsForOnu() = %v, want %v", got, tt.want)
400 break
401 }
402 }
cbabuabf02352019-10-15 13:14:56 +0200403 }
404 })
405 }
406}
407
408func TestOpenOltResourceMgr_GetCurrentFlowIDsForOnu(t *testing.T) {
409
410 type args struct {
411 PONIntfID uint32
Abhilash Laxmeshwarab0bd522019-10-21 15:05:15 +0530412 ONUID int32
413 UNIID int32
cbabuabf02352019-10-15 13:14:56 +0200414 }
415 tests := []struct {
416 name string
417 fields *fields
418 args args
Girish Gowdraa09aeab2020-09-14 16:30:52 -0700419 want []uint64
cbabuabf02352019-10-15 13:14:56 +0200420 }{
Girish Gowdraa09aeab2020-09-14 16:30:52 -0700421 {"GetCurrentFlowIDsForOnu-1", getResMgr(), args{1, 2, 2}, []uint64{1, 2}},
cbabuabf02352019-10-15 13:14:56 +0200422 }
423 for _, tt := range tests {
424 t.Run(tt.name, func(t *testing.T) {
425 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530426 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
427 defer cancel()
Girish Gowdraa09aeab2020-09-14 16:30:52 -0700428 got, err := RsrcMgr.GetCurrentFlowIDsForOnu(ctx, tt.args.PONIntfID, tt.args.ONUID, tt.args.UNIID)
429 if err != nil {
430 t.Errorf("GetCurrentFlowIDsForOnu() returned error")
431 }
432 if reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
cbabuabf02352019-10-15 13:14:56 +0200433 t.Errorf("GetCurrentFlowIDsForOnu() = %v, want %v", got, tt.want)
434 }
435 })
436 }
437}
438
439func TestOpenOltResourceMgr_GetCurrentGEMPortIDsForOnu(t *testing.T) {
440 type args struct {
441 intfID uint32
442 onuID uint32
443 uniID uint32
444 }
445 tests := []struct {
446 name string
447 fields *fields
448 args args
449 want []uint32
450 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700451 {"GetCurrentGEMPortIDsForOnu-1", getResMgr(), args{1, 2, 2}, []uint32{}},
cbabuabf02352019-10-15 13:14:56 +0200452 }
453 for _, tt := range tests {
454 t.Run(tt.name, func(t *testing.T) {
455 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530456 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
457 defer cancel()
458 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 +0200459 t.Errorf("GetCurrentGEMPortIDsForOnu() = %v, want %v", got, tt.want)
460 }
461 })
462 }
463}
464
Girish Gowdraa482f272021-03-24 23:04:19 -0700465func TestOpenOltResourceMgr_GetMeterInfoForOnu(t *testing.T) {
cbabuabf02352019-10-15 13:14:56 +0200466 type args struct {
467 Direction string
468 IntfID uint32
469 OnuID uint32
470 UniID uint32
Gamze Abakafee36392019-10-03 11:17:24 +0000471 tpID uint32
cbabuabf02352019-10-15 13:14:56 +0200472 }
473 tests := []struct {
474 name string
475 fields *fields
476 args args
Girish Gowdraa482f272021-03-24 23:04:19 -0700477 want *MeterInfo
cbabuabf02352019-10-15 13:14:56 +0200478 wantErr error
479 }{
Girish Gowdraa482f272021-03-24 23:04:19 -0700480 {"GetMeterInfoForOnu", getResMgr(), args{"DOWNSTREAM", 0, 1, 1, 64},
481 &MeterInfo{}, errors.New("failed to get Meter config from kvstore for path")},
482 {"GetMeterInfoForOnu", getResMgr(), args{"DOWNSTREAM", 1, 2, 2, 65},
483 &MeterInfo{}, errors.New("failed to get Meter config from kvstore for path")},
cbabuabf02352019-10-15 13:14:56 +0200484 }
485 for _, tt := range tests {
486 t.Run(tt.name, func(t *testing.T) {
487 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530488 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
489 defer cancel()
Girish Gowdraa482f272021-03-24 23:04:19 -0700490 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 +0200491 if reflect.TypeOf(got) != reflect.TypeOf(tt.want) && err != nil {
Girish Gowdraa482f272021-03-24 23:04:19 -0700492 t.Errorf("GetMeterInfoForOnu() got = %v, want %v", got, tt.want)
cbabuabf02352019-10-15 13:14:56 +0200493 }
494 })
495 }
496}
497
498func TestOpenOltResourceMgr_GetONUID(t *testing.T) {
499 type args struct {
500 ponIntfID uint32
501 }
502 tests := []struct {
503 name string
504 fields *fields
505 args args
506 want uint32
507 wantErr error
508 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700509 {"GetONUID-1", getResMgr(), args{1}, uint32(0), errors.New("json errors")},
cbabuabf02352019-10-15 13:14:56 +0200510 }
511 for _, tt := range tests {
512 t.Run(tt.name, func(t *testing.T) {
513 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530514 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
515 defer cancel()
516 got, err := RsrcMgr.GetONUID(ctx, tt.args.ponIntfID)
cbabuabf02352019-10-15 13:14:56 +0200517 if got != tt.want && err != nil {
518 t.Errorf("GetONUID() got = %v, want %v", got, tt.want)
519 }
520 })
521 }
522}
523
524func TestOpenOltResourceMgr_GetTechProfileIDForOnu(t *testing.T) {
525
526 type args struct {
527 IntfID uint32
528 OnuID uint32
529 UniID uint32
530 }
531 tests := []struct {
532 name string
533 fields *fields
534 args args
Gamze Abakafee36392019-10-03 11:17:24 +0000535 want []uint32
cbabuabf02352019-10-15 13:14:56 +0200536 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700537 {"GetTechProfileIDForOnu-1", getResMgr(), args{1, 2, 2},
Gamze Abakafee36392019-10-03 11:17:24 +0000538 []uint32{1}},
cbabuabf02352019-10-15 13:14:56 +0200539 }
540 for _, tt := range tests {
541 t.Run(tt.name, func(t *testing.T) {
542 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530543 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
544 defer cancel()
545 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 +0200546 t.Errorf("GetTechProfileIDForOnu() = %v, want %v", got, tt.want)
547 }
548 })
549 }
550}
551
cbabuabf02352019-10-15 13:14:56 +0200552func TestOpenOltResourceMgr_RemoveMeterIDForOnu(t *testing.T) {
553
554 type args struct {
555 Direction string
556 IntfID uint32
557 OnuID uint32
558 UniID uint32
Gamze Abakafee36392019-10-03 11:17:24 +0000559 tpID uint32
cbabuabf02352019-10-15 13:14:56 +0200560 }
561 tests := []struct {
562 name string
563 fields *fields
564 args args
565 wantErr error
566 }{
Gamze Abakafee36392019-10-03 11:17:24 +0000567 {"RemoveMeterIdForOnu-1", getResMgr(), args{"DOWNSTREAM", 1, 1, 1, 64},
cbabuabf02352019-10-15 13:14:56 +0200568 errors.New("failed to delete meter id %s from kvstore")},
569 }
570 for _, tt := range tests {
571 t.Run(tt.name, func(t *testing.T) {
572 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530573 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
574 defer cancel()
Girish Gowdraa482f272021-03-24 23:04:19 -0700575 if err := RsrcMgr.RemoveMeterInfoForOnu(ctx, tt.args.Direction, tt.args.IntfID, tt.args.OnuID, tt.args.UniID,
Gamze Abakafee36392019-10-03 11:17:24 +0000576 tt.args.tpID); reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr) && err != nil {
cbabuabf02352019-10-15 13:14:56 +0200577 t.Errorf("RemoveMeterIDForOnu() error = %v, wantErr %v", err, tt.wantErr)
578 }
579 })
580 }
581}
582
583func TestOpenOltResourceMgr_RemoveTechProfileIDForOnu(t *testing.T) {
584 type args struct {
585 IntfID uint32
586 OnuID uint32
587 UniID uint32
Gamze Abakafee36392019-10-03 11:17:24 +0000588 tpID uint32
cbabuabf02352019-10-15 13:14:56 +0200589 }
590 tests := []struct {
591 name string
592 fields *fields
593 args args
594 wantErr error
595 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700596 {"RemoveTechProfileIDForOnu-1", getResMgr(), args{1, 2, 2, 64},
cbabuabf02352019-10-15 13:14:56 +0200597 errors.New("failed to delete techprofile id resource %s in KV store")},
598 }
599 for _, tt := range tests {
600 t.Run(tt.name, func(t *testing.T) {
601 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530602 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
603 defer cancel()
604 if err := RsrcMgr.RemoveTechProfileIDForOnu(ctx, tt.args.IntfID, tt.args.OnuID, tt.args.UniID,
Gamze Abakafee36392019-10-03 11:17:24 +0000605 tt.args.tpID); reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr) && err != nil {
cbabuabf02352019-10-15 13:14:56 +0200606 t.Errorf("RemoveTechProfileIDForOnu() error = %v, wantErr %v", err, tt.wantErr)
607 }
608 })
609 }
610}
611
612func TestOpenOltResourceMgr_UpdateAllocIdsForOnu(t *testing.T) {
613 type args struct {
614 ponPort uint32
615 onuID uint32
616 uniID uint32
617 allocID []uint32
618 }
619 tests := []struct {
620 name string
621 fields *fields
622 args args
623 wantErr error
624 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700625 {"UpdateAllocIdsForOnu-1", getResMgr(), args{1, 2, 2, []uint32{1, 2}},
cbabuabf02352019-10-15 13:14:56 +0200626 errors.New("")},
627 }
628 for _, tt := range tests {
629 t.Run(tt.name, func(t *testing.T) {
630 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530631 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
632 defer cancel()
633 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 +0200634 t.Errorf("UpdateAllocIdsForOnu() error = %v, wantErr %v", err, tt.wantErr)
635 }
636 })
637 }
638}
639
cbabuabf02352019-10-15 13:14:56 +0200640func TestOpenOltResourceMgr_UpdateGEMPortIDsForOnu(t *testing.T) {
641
642 type args struct {
643 ponPort uint32
644 onuID uint32
645 uniID uint32
646 GEMPortList []uint32
647 }
648 tests := []struct {
649 name string
650 fields *fields
651 args args
652 wantErr error
653 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700654 {"UpdateGEMPortIDsForOnu-1", getResMgr(), args{1, 2, 2,
cbabuabf02352019-10-15 13:14:56 +0200655 []uint32{1, 2}}, errors.New("failed to update resource")},
656 }
657 for _, tt := range tests {
658 t.Run(tt.name, func(t *testing.T) {
659 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530660 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
661 defer cancel()
662 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 +0200663 t.Errorf("UpdateGEMPortIDsForOnu() error = %v, wantErr %v", err, tt.wantErr)
664 }
665 })
666 }
667}
668
cbabuabf02352019-10-15 13:14:56 +0200669func TestOpenOltResourceMgr_UpdateMeterIDForOnu(t *testing.T) {
670 type args struct {
Girish Gowdraa482f272021-03-24 23:04:19 -0700671 Direction string
672 IntfID uint32
673 OnuID uint32
674 UniID uint32
675 tpID uint32
676 MeterInfo *MeterInfo
cbabuabf02352019-10-15 13:14:56 +0200677 }
678 tests := []struct {
679 name string
680 fields *fields
681 args args
682 wantErr error
683 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700684 {"UpdateMeterIDForOnu-1", getResMgr(), args{"DOWNSTREAM", 1, 2,
Girish Gowdraa482f272021-03-24 23:04:19 -0700685 2, 64, &MeterInfo{}}, errors.New("failed to get Meter config from kvstore for path")},
cbabuabf02352019-10-15 13:14:56 +0200686 }
687 for _, tt := range tests {
688 t.Run(tt.name, func(t *testing.T) {
689 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530690 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
691 defer cancel()
Girish Gowdraa482f272021-03-24 23:04:19 -0700692 if err := RsrcMgr.StoreMeterInfoForOnu(ctx, tt.args.Direction, tt.args.IntfID, tt.args.OnuID, tt.args.UniID,
693 tt.args.tpID, tt.args.MeterInfo); reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr) && err != nil {
cbabuabf02352019-10-15 13:14:56 +0200694 t.Errorf("UpdateMeterIDForOnu() got = %v, want %v", err, tt.wantErr)
695 }
696 })
697 }
698}
699
700func TestOpenOltResourceMgr_UpdateTechProfileIDForOnu(t *testing.T) {
701 type args struct {
702 IntfID uint32
703 OnuID uint32
704 UniID uint32
705 TpID uint32
706 }
707 tests := []struct {
708 name string
709 fields *fields
710 args args
711 wantErr error
712 }{
Girish Gowdra38d533d2020-03-30 20:38:51 -0700713 {"UpdateTechProfileIDForOnu-1", getResMgr(), args{1, 2, 2,
cbabuabf02352019-10-15 13:14:56 +0200714 2}, errors.New("failed to update resource")},
715 }
716 for _, tt := range tests {
717 t.Run(tt.name, func(t *testing.T) {
718 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530719 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
720 defer cancel()
721 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 +0200722 t.Errorf("UpdateTechProfileIDForOnu() got = %v, want %v", err, tt.wantErr)
723 }
724 })
725 }
726}
727
728func TestSetKVClient(t *testing.T) {
729 type args struct {
Matteo Scandolodfa7a972020-11-06 13:03:40 -0800730 backend string
731 address string
732 DeviceID string
733 kvStorePrefix string
cbabuabf02352019-10-15 13:14:56 +0200734 }
735 tests := []struct {
736 name string
737 args args
sbarbaria8910ba2019-11-05 10:12:23 -0500738 want *db.Backend
cbabuabf02352019-10-15 13:14:56 +0200739 }{
serkant.uluderya7b8211e2021-02-24 16:39:18 +0300740 {"setKVClient-1", args{"etcd", "1.1.1.1:1", "olt1", "service/voltha"}, &db.Backend{}},
cbabuabf02352019-10-15 13:14:56 +0200741 }
742 for _, tt := range tests {
743 t.Run(tt.name, func(t *testing.T) {
Matteo Scandolodfa7a972020-11-06 13:03:40 -0800744 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 +0200745 t.Errorf("SetKVClient() = %v, want %v", got, tt.want)
746 }
747 })
748 }
749}
750
cbabuabf02352019-10-15 13:14:56 +0200751func Test_newKVClient(t *testing.T) {
752 type args struct {
753 storeType string
754 address string
Neha Sharmacc656962020-04-14 14:26:11 +0000755 timeout time.Duration
cbabuabf02352019-10-15 13:14:56 +0200756 }
757 var kvClient kvstore.Client
758 tests := []struct {
759 name string
760 args args
761 want kvstore.Client
762 wantErr error
763 }{
764 {"newKVClient-1", args{"", "3.3.3.3", 1}, kvClient, errors.New("unsupported-kv-store")},
765 }
766 for _, tt := range tests {
767 t.Run(tt.name, func(t *testing.T) {
Neha Sharma96b7bf22020-06-15 10:37:32 +0000768 got, err := newKVClient(context.Background(), tt.args.storeType, tt.args.address, tt.args.timeout)
cbabuabf02352019-10-15 13:14:56 +0200769 if got != nil && reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
770 t.Errorf("newKVClient() got = %v, want %v", got, tt.want)
771 }
772 if (err != nil) && reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr) {
773 t.Errorf("newKVClient() error = %v, wantErr %v", err, tt.wantErr)
774 return
775 }
776
777 })
778 }
779}
Esin Karamanccb714b2019-11-29 15:02:06 +0000780
781func TestOpenOltResourceMgr_AddMcastQueueForIntf(t *testing.T) {
782 type args struct {
783 intf uint32
784 gem uint32
785 servicePriority uint32
786 }
787 tests := []struct {
788 name string
789 args args
790 fields *fields
791 }{
792 {"AddMcastQueueForIntf-1", args{0, 4000, 0}, getResMgr()},
793 {"AddMcastQueueForIntf-2", args{1, 4000, 1}, getResMgr()},
794 {"AddMcastQueueForIntf-3", args{2, 4000, 2}, getResMgr()},
795 }
796 for _, tt := range tests {
797 t.Run(tt.name, func(t *testing.T) {
798 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530799 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
800 defer cancel()
801 err := RsrcMgr.AddMcastQueueForIntf(ctx, tt.args.intf, tt.args.gem, tt.args.servicePriority)
Esin Karamanccb714b2019-11-29 15:02:06 +0000802 if err != nil {
803 t.Errorf("%s got err= %s wants nil", tt.name, err)
804 return
805 }
806 })
807 }
808}
809
810func newGroup(groupID uint32, outPorts []uint32) *ofp.OfpGroupEntry {
811 groupDesc := ofp.OfpGroupDesc{
812 Type: ofp.OfpGroupType_OFPGT_ALL,
813 GroupId: groupID,
814 }
815 groupEntry := ofp.OfpGroupEntry{
816 Desc: &groupDesc,
817 }
Esin Karamanccb714b2019-11-29 15:02:06 +0000818 for i := 0; i < len(outPorts); i++ {
Esin Karaman0ebd2a32020-02-09 18:45:36 +0000819 var acts []*ofp.OfpAction
Esin Karamanccb714b2019-11-29 15:02:06 +0000820 acts = append(acts, fu.Output(outPorts[i]))
Esin Karaman0ebd2a32020-02-09 18:45:36 +0000821 bucket := ofp.OfpBucket{
822 Actions: acts,
823 }
824 groupDesc.Buckets = append(groupDesc.Buckets, &bucket)
Esin Karamanccb714b2019-11-29 15:02:06 +0000825 }
Esin Karamanccb714b2019-11-29 15:02:06 +0000826 return &groupEntry
827}
828
829func TestOpenOltResourceMgr_AddFlowGroupToKVStore(t *testing.T) {
830 type args struct {
831 group *ofp.OfpGroupEntry
832 cached bool
833 }
834 //create group 1
835 group1 := newGroup(1, []uint32{1})
836 //create group 2
837 group2 := newGroup(2, []uint32{2})
838 //define test set
839 tests := []struct {
840 name string
841 args args
842 fields *fields
843 }{
844 {"AddFlowGroupToKVStore-1", args{group1, true}, getResMgr()},
845 {"AddFlowGroupToKVStore-2", args{group2, false}, getResMgr()},
846 }
847 //execute tests
848 for _, tt := range tests {
849 t.Run(tt.name, func(t *testing.T) {
850 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530851 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
852 defer cancel()
853 err := RsrcMgr.AddFlowGroupToKVStore(ctx, tt.args.group, tt.args.cached)
Esin Karamanccb714b2019-11-29 15:02:06 +0000854 if err != nil {
855 t.Errorf("%s got err= %s wants nil", tt.name, err)
856 return
857 }
858 })
859 }
860}
861
862func TestOpenOltResourceMgr_RemoveFlowGroupFromKVStore(t *testing.T) {
863 type args struct {
864 groupID uint32
865 cached bool
866 }
867 //define test set
868 tests := []struct {
869 name string
870 args args
871 fields *fields
872 }{
873 {"RemoveFlowGroupFromKVStore-1", args{1, true}, getResMgr()},
874 {"RemoveFlowGroupFromKVStore-2", args{2, false}, getResMgr()},
875 }
876 //execute tests
877 for _, tt := range tests {
878 t.Run(tt.name, func(t *testing.T) {
879 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530880 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
881 defer cancel()
Esin Karamand519bbf2020-07-01 11:16:03 +0000882 err := RsrcMgr.RemoveFlowGroupFromKVStore(ctx, tt.args.groupID, tt.args.cached)
883 if err != nil {
Esin Karamanccb714b2019-11-29 15:02:06 +0000884 t.Errorf("%s got false but wants true", tt.name)
885 return
886 }
887 })
888 }
889}
890
891func TestOpenOltResourceMgr_GetFlowGroupFromKVStore(t *testing.T) {
892 type args struct {
893 groupID uint32
894 cached bool
895 }
896 //define test set
897 tests := []struct {
898 name string
899 args args
900 fields *fields
901 }{
902 {"GetFlowGroupFromKVStore-1", args{1, true}, getResMgr()},
903 {"GetFlowGroupFromKVStore-2", args{2, false}, getResMgr()},
904 {"GetFlowGroupFromKVStore-3", args{1000, false}, getResMgr()},
905 }
906 //execute tests
907 for _, tt := range tests {
908 t.Run(tt.name, func(t *testing.T) {
909 RsrcMgr := testResMgrObject(tt.fields)
npujarec5762e2020-01-01 14:08:48 +0530910 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
911 defer cancel()
912 exists, groupInfo, err := RsrcMgr.GetFlowGroupFromKVStore(ctx, tt.args.groupID, tt.args.cached)
Esin Karamanccb714b2019-11-29 15:02:06 +0000913 if err != nil {
914 t.Errorf("%s got error but wants nil error", tt.name)
915 return
916 } else if exists && (groupInfo.GroupID == 0) {
917 t.Errorf("%s got true and nil group info but expected not nil group info", tt.name)
918 return
919 } else if tt.args.groupID == 3 && exists {
920 t.Errorf("%s got true but wants false", tt.name)
921 return
922 }
923 })
924 }
925}