cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
cbabu | bef8943 | 2019-10-18 11:47:27 +0200 | [diff] [blame] | 17 | /* |
| 18 | This file contains unit test cases for functions in the file resourcemanager.go. |
| 19 | This file also implements the Client interface to mock the kv-client, fields struct to mock OpenOltResourceMgr |
| 20 | and few utility functions. |
| 21 | */ |
| 22 | |
| 23 | //Package adaptercore provides the utility for olt devices, flows and statistics |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 24 | package resourcemanager |
| 25 | |
| 26 | import ( |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 27 | "context" |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 28 | "encoding/json" |
| 29 | "errors" |
Matteo Scandolo | 8458537 | 2021-03-18 14:21:22 -0700 | [diff] [blame] | 30 | tp "github.com/opencord/voltha-lib-go/v4/pkg/techprofile" |
serkant.uluderya | 7b8211e | 2021-02-24 16:39:18 +0300 | [diff] [blame] | 31 | "reflect" |
| 32 | "strconv" |
| 33 | "strings" |
| 34 | "sync" |
| 35 | "testing" |
| 36 | "time" |
| 37 | |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 38 | "github.com/opencord/voltha-lib-go/v4/pkg/db" |
| 39 | "github.com/opencord/voltha-lib-go/v4/pkg/db/kvstore" |
| 40 | fu "github.com/opencord/voltha-lib-go/v4/pkg/flows" |
| 41 | "github.com/opencord/voltha-lib-go/v4/pkg/log" |
| 42 | ponrmgr "github.com/opencord/voltha-lib-go/v4/pkg/ponresourcemanager" |
| 43 | ofp "github.com/opencord/voltha-protos/v4/go/openflow_13" |
| 44 | "github.com/opencord/voltha-protos/v4/go/openolt" |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 45 | ) |
| 46 | |
| 47 | func init() { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 48 | _, _ = log.SetDefaultLogger(log.JSON, log.DebugLevel, nil) |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | const ( |
| 52 | // MeterConfig meter to extract meter |
| 53 | MeterConfig = "meter_id" |
| 54 | // TpIDSuffixPath to extract Techprofile |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 55 | // TpIDSuffixPath = "tp_id" |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 56 | // FlowIDInfo to extract flows |
| 57 | FlowIDInfo = "flow_id_info" |
| 58 | // FlowIds to extract flows |
| 59 | FlowIDs = "flow_ids" |
| 60 | // GemportIDs to gemport_ids |
| 61 | GemportIDs = "gemport_ids" |
| 62 | // AllocIDs to extract alloc_ids |
| 63 | AllocIDs = "alloc_ids" |
| 64 | // GemportIDPool to extract gemport |
| 65 | GemportIDPool = "gemport_id_pool" |
| 66 | // AllocIDPool to extract allocid |
| 67 | AllocIDPool = "alloc_id_pool" |
| 68 | // FlowIDpool to extract Flow ids |
| 69 | FlowIDpool = "flow_id_pool" |
| 70 | ) |
| 71 | |
cbabu | bef8943 | 2019-10-18 11:47:27 +0200 | [diff] [blame] | 72 | // fields mocks OpenOltResourceMgr struct. |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 73 | type fields struct { |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 74 | DeviceID string |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 75 | Address string |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 76 | Args string |
| 77 | KVStore *db.Backend |
| 78 | DeviceType string |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 79 | DevInfo *openolt.DeviceInfo |
| 80 | ResourceMgrs map[uint32]*ponrmgr.PONResourceManager |
| 81 | NumOfPonPorts uint32 |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 82 | } |
cbabu | bef8943 | 2019-10-18 11:47:27 +0200 | [diff] [blame] | 83 | |
| 84 | // MockKVClient mocks the AdapterProxy interface. |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 85 | type MockResKVClient struct { |
| 86 | } |
| 87 | |
cbabu | bef8943 | 2019-10-18 11:47:27 +0200 | [diff] [blame] | 88 | // getResMgr mocks OpenOltResourceMgr struct. |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 89 | func getResMgr() *fields { |
Matteo Scandolo | 8458537 | 2021-03-18 14:21:22 -0700 | [diff] [blame] | 90 | ctx := context.TODO() |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 91 | var resMgr fields |
sbarbari | a8910ba | 2019-11-05 10:12:23 -0500 | [diff] [blame] | 92 | resMgr.KVStore = &db.Backend{ |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 93 | Client: &MockResKVClient{}, |
| 94 | } |
| 95 | resMgr.ResourceMgrs = make(map[uint32]*ponrmgr.PONResourceManager) |
| 96 | ranges := make(map[string]interface{}) |
| 97 | sharedIdxByType := make(map[string]string) |
| 98 | sharedIdxByType["ALLOC_ID"] = "ALLOC_ID" |
| 99 | sharedIdxByType["ONU_ID"] = "ONU_ID" |
| 100 | sharedIdxByType["GEMPORT_ID"] = "GEMPORT_ID" |
| 101 | sharedIdxByType["FLOW_ID"] = "FLOW_ID" |
| 102 | ranges["ONU_ID"] = uint32(0) |
| 103 | ranges["GEMPORT_ID"] = uint32(0) |
| 104 | ranges["ALLOC_ID"] = uint32(0) |
| 105 | ranges["FLOW_ID"] = uint32(0) |
| 106 | ranges["onu_id_shared"] = uint32(0) |
| 107 | ranges["alloc_id_shared"] = uint32(0) |
| 108 | ranges["gemport_id_shared"] = uint32(0) |
| 109 | ranges["flow_id_shared"] = uint32(0) |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 110 | resMgr.NumOfPonPorts = 16 |
Matteo Scandolo | 8458537 | 2021-03-18 14:21:22 -0700 | [diff] [blame] | 111 | ponMgr := &ponrmgr.PONResourceManager{} |
| 112 | tpMgr, err := tp.NewTechProfile(ctx, ponMgr, "etcd", "127.0.0.1", "/") |
| 113 | if err != nil { |
| 114 | logger.Fatal(ctx, err.Error()) |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 115 | } |
Matteo Scandolo | 8458537 | 2021-03-18 14:21:22 -0700 | [diff] [blame] | 116 | |
| 117 | ponMgr.DeviceID = "onu-1" |
| 118 | ponMgr.IntfIDs = []uint32{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} |
| 119 | ponMgr.KVStore = &db.Backend{ |
| 120 | Client: &MockResKVClient{}, |
| 121 | } |
| 122 | ponMgr.PonResourceRanges = ranges |
| 123 | ponMgr.SharedIdxByType = sharedIdxByType |
| 124 | ponMgr.TechProfileMgr = tpMgr |
| 125 | |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 126 | var ponIntf uint32 |
| 127 | for ponIntf = 0; ponIntf < resMgr.NumOfPonPorts; ponIntf++ { |
| 128 | resMgr.ResourceMgrs[ponIntf] = ponMgr |
| 129 | } |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 130 | return &resMgr |
| 131 | } |
cbabu | bef8943 | 2019-10-18 11:47:27 +0200 | [diff] [blame] | 132 | |
| 133 | // List function implemented for KVClient. |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 134 | func (kvclient *MockResKVClient) List(ctx context.Context, key string) (map[string]*kvstore.KVPair, error) { |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 135 | return nil, errors.New("key didn't find") |
| 136 | } |
| 137 | |
| 138 | // Get mock function implementation for KVClient |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 139 | func (kvclient *MockResKVClient) Get(ctx context.Context, key string) (*kvstore.KVPair, error) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 140 | logger.Debugw(ctx, "Warning Warning Warning: Get of MockKVClient called", log.Fields{"key": key}) |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 141 | if key != "" { |
| 142 | if strings.Contains(key, MeterConfig) { |
| 143 | var bands []*ofp.OfpMeterBandHeader |
| 144 | bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DSCP_REMARK, |
| 145 | Rate: 1024, Data: &ofp.OfpMeterBandHeader_DscpRemark{DscpRemark: &ofp.OfpMeterBandDscpRemark{PrecLevel: 2}}}) |
| 146 | |
| 147 | bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DSCP_REMARK, |
| 148 | Rate: 1024, Data: &ofp.OfpMeterBandHeader_DscpRemark{DscpRemark: &ofp.OfpMeterBandDscpRemark{PrecLevel: 3}}}) |
| 149 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 150 | sep := strings.Split(key, "/")[1] |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 151 | val, _ := strconv.ParseInt(strings.Split(sep, ",")[1], 10, 32) |
| 152 | if uint32(val) > 1 { |
| 153 | meterConfig := &ofp.OfpMeterConfig{MeterId: uint32(val), Bands: bands} |
| 154 | str, _ := json.Marshal(meterConfig) |
| 155 | |
| 156 | return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil |
| 157 | } |
| 158 | return nil, errors.New("invalid meter") |
| 159 | } |
| 160 | if strings.Contains(key, FlowIDpool) || strings.Contains(key, GemportIDPool) || strings.Contains(key, AllocIDPool) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 161 | logger.Debug(ctx, "Error Error Error Key:", FlowIDpool, GemportIDPool, AllocIDPool) |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 162 | data := make(map[string]interface{}) |
| 163 | data["pool"] = "1024" |
| 164 | data["start_idx"] = 1 |
| 165 | data["end_idx"] = 1024 |
| 166 | str, _ := json.Marshal(data) |
| 167 | return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil |
| 168 | } |
| 169 | if strings.Contains(key, FlowIDInfo) || strings.Contains(key, FlowIDs) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 170 | logger.Debug(ctx, "Error Error Error Key:", FlowIDs, FlowIDInfo) |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 171 | str, _ := json.Marshal([]uint32{1, 2}) |
| 172 | return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil |
| 173 | } |
| 174 | if strings.Contains(key, AllocIDs) || strings.Contains(key, GemportIDs) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 175 | logger.Debug(ctx, "Error Error Error Key:", AllocIDs, GemportIDs) |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 176 | str, _ := json.Marshal(1) |
| 177 | return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil |
| 178 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 179 | if strings.Contains(key, McastQueuesForIntf) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 180 | logger.Debug(ctx, "Error Error Error Key:", McastQueuesForIntf) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 181 | mcastQueues := make(map[uint32][]uint32) |
| 182 | mcastQueues[10] = []uint32{4000, 0} |
| 183 | str, _ := json.Marshal(mcastQueues) |
| 184 | return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil |
| 185 | } |
| 186 | if strings.Contains(key, "flow_groups") && !strings.Contains(key, "1000") { |
| 187 | groupInfo := GroupInfo{GroupID: 2, OutPorts: []uint32{2}} |
| 188 | str, _ := json.Marshal(groupInfo) |
| 189 | return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil |
| 190 | } |
| 191 | |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 192 | maps := make(map[string]*kvstore.KVPair) |
| 193 | maps[key] = &kvstore.KVPair{Key: key} |
| 194 | return maps[key], nil |
| 195 | } |
| 196 | return nil, errors.New("key didn't find") |
| 197 | } |
| 198 | |
| 199 | // Put mock function implementation for KVClient |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 200 | func (kvclient *MockResKVClient) Put(ctx context.Context, key string, value interface{}) error { |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 201 | if key != "" { |
| 202 | return nil |
| 203 | } |
| 204 | return errors.New("key didn't find") |
| 205 | } |
| 206 | |
| 207 | // Delete mock function implementation for KVClient |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 208 | func (kvclient *MockResKVClient) Delete(ctx context.Context, key string) error { |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 209 | return nil |
| 210 | } |
| 211 | |
serkant.uluderya | 7b8211e | 2021-02-24 16:39:18 +0300 | [diff] [blame] | 212 | // DeleteWithPrefix mock function implementation for KVClient |
| 213 | func (kvclient *MockResKVClient) DeleteWithPrefix(ctx context.Context, prefix string) error { |
| 214 | return nil |
| 215 | } |
| 216 | |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 217 | // Reserve mock function implementation for KVClient |
Neha Sharma | cc65696 | 2020-04-14 14:26:11 +0000 | [diff] [blame] | 218 | func (kvclient *MockResKVClient) Reserve(ctx context.Context, key string, value interface{}, ttl time.Duration) (interface{}, error) { |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 219 | return nil, errors.New("key didn't find") |
| 220 | } |
| 221 | |
| 222 | // ReleaseReservation mock function implementation for KVClient |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 223 | func (kvclient *MockResKVClient) ReleaseReservation(ctx context.Context, key string) error { |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 224 | return nil |
| 225 | } |
| 226 | |
| 227 | // ReleaseAllReservations mock function implementation for KVClient |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 228 | func (kvclient *MockResKVClient) ReleaseAllReservations(ctx context.Context) error { |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 229 | return nil |
| 230 | } |
| 231 | |
| 232 | // RenewReservation mock function implementation for KVClient |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 233 | func (kvclient *MockResKVClient) RenewReservation(ctx context.Context, key string) error { |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 234 | return nil |
| 235 | } |
| 236 | |
| 237 | // Watch mock function implementation for KVClient |
Scott Baker | e701b86 | 2020-02-20 16:19:16 -0800 | [diff] [blame] | 238 | func (kvclient *MockResKVClient) Watch(ctx context.Context, key string, withPrefix bool) chan *kvstore.Event { |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 239 | return nil |
| 240 | } |
| 241 | |
| 242 | // AcquireLock mock function implementation for KVClient |
Neha Sharma | cc65696 | 2020-04-14 14:26:11 +0000 | [diff] [blame] | 243 | func (kvclient *MockResKVClient) AcquireLock(ctx context.Context, lockName string, timeout time.Duration) error { |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 244 | return nil |
| 245 | } |
| 246 | |
| 247 | // ReleaseLock mock function implementation for KVClient |
| 248 | func (kvclient *MockResKVClient) ReleaseLock(lockName string) error { |
| 249 | return nil |
| 250 | } |
| 251 | |
| 252 | // IsConnectionUp mock function implementation for KVClient |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 253 | func (kvclient *MockResKVClient) IsConnectionUp(ctx context.Context) bool { // timeout in second |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 254 | return true |
| 255 | } |
| 256 | |
| 257 | // CloseWatch mock function implementation for KVClient |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 258 | func (kvclient *MockResKVClient) CloseWatch(ctx context.Context, key string, ch chan *kvstore.Event) { |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | // Close mock function implementation for KVClient |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 262 | func (kvclient *MockResKVClient) Close(ctx context.Context) { |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 263 | } |
| 264 | |
cbabu | bef8943 | 2019-10-18 11:47:27 +0200 | [diff] [blame] | 265 | // testResMgrObject maps fields type to OpenOltResourceMgr type. |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 266 | func testResMgrObject(testResMgr *fields) *OpenOltResourceMgr { |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 267 | var rsrMgr = OpenOltResourceMgr{ |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 268 | DeviceID: testResMgr.DeviceID, |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 269 | Args: testResMgr.Args, |
| 270 | KVStore: testResMgr.KVStore, |
| 271 | DeviceType: testResMgr.DeviceType, |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 272 | Address: testResMgr.Address, |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 273 | DevInfo: testResMgr.DevInfo, |
| 274 | ResourceMgrs: testResMgr.ResourceMgrs, |
| 275 | } |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 276 | |
| 277 | rsrMgr.AllocIDMgmtLock = make([]sync.RWMutex, testResMgr.NumOfPonPorts) |
| 278 | rsrMgr.GemPortIDMgmtLock = make([]sync.RWMutex, testResMgr.NumOfPonPorts) |
| 279 | rsrMgr.OnuIDMgmtLock = make([]sync.RWMutex, testResMgr.NumOfPonPorts) |
| 280 | |
| 281 | return &rsrMgr |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | func TestNewResourceMgr(t *testing.T) { |
| 285 | type args struct { |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 286 | deviceID string |
| 287 | KVStoreAddress string |
| 288 | kvStoreType string |
| 289 | deviceType string |
| 290 | devInfo *openolt.DeviceInfo |
Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 291 | kvStorePrefix string |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 292 | } |
| 293 | tests := []struct { |
| 294 | name string |
| 295 | args args |
| 296 | want *OpenOltResourceMgr |
| 297 | }{ |
serkant.uluderya | 7b8211e | 2021-02-24 16:39:18 +0300 | [diff] [blame] | 298 | {"NewResourceMgr-2", args{"olt1", "1:2", "etcd", |
Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 299 | "onu", &openolt.DeviceInfo{OnuIdStart: 1, OnuIdEnd: 1}, "service/voltha"}, &OpenOltResourceMgr{}}, |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 300 | } |
| 301 | for _, tt := range tests { |
| 302 | t.Run(tt.name, func(t *testing.T) { |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 303 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 304 | defer cancel() |
Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 305 | if got := NewResourceMgr(ctx, 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) { |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 306 | t.Errorf("NewResourceMgr() = %v, want %v", got, tt.want) |
| 307 | } |
| 308 | }) |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | func TestOpenOltResourceMgr_Delete(t *testing.T) { |
| 313 | tests := []struct { |
| 314 | name string |
| 315 | fields *fields |
| 316 | wantErr error |
| 317 | }{ |
| 318 | {"Delete-1", getResMgr(), errors.New("failed to clear device resource pool")}, |
| 319 | } |
| 320 | for _, tt := range tests { |
| 321 | t.Run(tt.name, func(t *testing.T) { |
| 322 | RsrcMgr := testResMgrObject(tt.fields) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 323 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 324 | defer cancel() |
| 325 | if err := RsrcMgr.Delete(ctx); (err != nil) && reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr) { |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 326 | t.Errorf("Delete() error = %v, wantErr %v", err, tt.wantErr) |
| 327 | } |
| 328 | }) |
| 329 | } |
| 330 | } |
| 331 | |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 332 | func TestOpenOltResourceMgr_FreePONResourcesForONU(t *testing.T) { |
| 333 | type args struct { |
| 334 | intfID uint32 |
| 335 | onuID uint32 |
| 336 | uniID uint32 |
| 337 | } |
| 338 | tests := []struct { |
| 339 | name string |
| 340 | fields *fields |
| 341 | args args |
| 342 | }{ |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 343 | {"FreePONResourcesForONU-1", getResMgr(), args{1, 0, 2}}, |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 344 | } |
| 345 | for _, tt := range tests { |
| 346 | t.Run(tt.name, func(t *testing.T) { |
| 347 | RsrcMgr := testResMgrObject(tt.fields) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 348 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 349 | defer cancel() |
| 350 | RsrcMgr.FreePONResourcesForONU(ctx, tt.args.intfID, tt.args.onuID, tt.args.uniID) |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 351 | }) |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | func TestOpenOltResourceMgr_FreeonuID(t *testing.T) { |
| 356 | type args struct { |
| 357 | intfID uint32 |
| 358 | onuID []uint32 |
| 359 | } |
| 360 | tests := []struct { |
| 361 | name string |
| 362 | fields *fields |
| 363 | args args |
| 364 | }{ |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 365 | {"FreeOnuID-1", getResMgr(), args{1, []uint32{1, 2}}}, |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 366 | } |
| 367 | for _, tt := range tests { |
| 368 | t.Run(tt.name, func(t *testing.T) { |
| 369 | RsrcMgr := testResMgrObject(tt.fields) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 370 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 371 | defer cancel() |
| 372 | RsrcMgr.FreeonuID(ctx, tt.args.intfID, tt.args.onuID) |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 373 | }) |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | func TestOpenOltResourceMgr_GetAllocID(t *testing.T) { |
| 378 | |
| 379 | type args struct { |
| 380 | intfID uint32 |
| 381 | onuID uint32 |
| 382 | uniID uint32 |
| 383 | } |
| 384 | tests := []struct { |
| 385 | name string |
| 386 | fields *fields |
| 387 | args args |
| 388 | want uint32 |
| 389 | }{ |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 390 | {"GetAllocID-1", getResMgr(), args{1, 2, 2}, 0}, |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 391 | } |
| 392 | for _, tt := range tests { |
| 393 | t.Run(tt.name, func(t *testing.T) { |
| 394 | RsrcMgr := testResMgrObject(tt.fields) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 395 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 396 | defer cancel() |
| 397 | if got := RsrcMgr.GetAllocID(ctx, tt.args.intfID, tt.args.onuID, tt.args.uniID); reflect.TypeOf(got) != reflect.TypeOf(tt.want) { |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 398 | t.Errorf("GetAllocID() = %v, want %v", got, tt.want) |
| 399 | } |
| 400 | }) |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | func TestOpenOltResourceMgr_GetCurrentAllocIDForOnu(t *testing.T) { |
| 405 | type args struct { |
| 406 | intfID uint32 |
| 407 | onuID uint32 |
| 408 | uniID uint32 |
| 409 | } |
| 410 | tests := []struct { |
| 411 | name string |
| 412 | fields *fields |
| 413 | args args |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 414 | want []uint32 |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 415 | }{ |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 416 | {"GetCurrentAllocIDForOnu-1", getResMgr(), args{1, 2, 2}, []uint32{}}, |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 417 | } |
| 418 | for _, tt := range tests { |
| 419 | t.Run(tt.name, func(t *testing.T) { |
| 420 | RsrcMgr := testResMgrObject(tt.fields) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 421 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 422 | defer cancel() |
| 423 | if got := RsrcMgr.GetCurrentAllocIDsForOnu(ctx, tt.args.intfID, tt.args.onuID, tt.args.uniID); !reflect.DeepEqual(got, tt.want) { |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 424 | t.Errorf("GetCurrentAllocIDsForOnu() = %v, want %v", got, tt.want) |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 425 | } |
| 426 | }) |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | func TestOpenOltResourceMgr_GetCurrentFlowIDsForOnu(t *testing.T) { |
| 431 | |
| 432 | type args struct { |
| 433 | PONIntfID uint32 |
Abhilash Laxmeshwar | ab0bd52 | 2019-10-21 15:05:15 +0530 | [diff] [blame] | 434 | ONUID int32 |
| 435 | UNIID int32 |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 436 | } |
| 437 | tests := []struct { |
| 438 | name string |
| 439 | fields *fields |
| 440 | args args |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 441 | want []uint64 |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 442 | }{ |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 443 | {"GetCurrentFlowIDsForOnu-1", getResMgr(), args{1, 2, 2}, []uint64{1, 2}}, |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 444 | } |
| 445 | for _, tt := range tests { |
| 446 | t.Run(tt.name, func(t *testing.T) { |
| 447 | RsrcMgr := testResMgrObject(tt.fields) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 448 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 449 | defer cancel() |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 450 | got, err := RsrcMgr.GetCurrentFlowIDsForOnu(ctx, tt.args.PONIntfID, tt.args.ONUID, tt.args.UNIID) |
| 451 | if err != nil { |
| 452 | t.Errorf("GetCurrentFlowIDsForOnu() returned error") |
| 453 | } |
| 454 | if reflect.TypeOf(got) != reflect.TypeOf(tt.want) { |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 455 | t.Errorf("GetCurrentFlowIDsForOnu() = %v, want %v", got, tt.want) |
| 456 | } |
| 457 | }) |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | func TestOpenOltResourceMgr_GetCurrentGEMPortIDsForOnu(t *testing.T) { |
| 462 | type args struct { |
| 463 | intfID uint32 |
| 464 | onuID uint32 |
| 465 | uniID uint32 |
| 466 | } |
| 467 | tests := []struct { |
| 468 | name string |
| 469 | fields *fields |
| 470 | args args |
| 471 | want []uint32 |
| 472 | }{ |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 473 | {"GetCurrentGEMPortIDsForOnu-1", getResMgr(), args{1, 2, 2}, []uint32{}}, |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 474 | } |
| 475 | for _, tt := range tests { |
| 476 | t.Run(tt.name, func(t *testing.T) { |
| 477 | RsrcMgr := testResMgrObject(tt.fields) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 478 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 479 | defer cancel() |
| 480 | if got := RsrcMgr.GetCurrentGEMPortIDsForOnu(ctx, tt.args.intfID, tt.args.onuID, tt.args.uniID); reflect.TypeOf(got) != reflect.TypeOf(tt.want) { |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 481 | t.Errorf("GetCurrentGEMPortIDsForOnu() = %v, want %v", got, tt.want) |
| 482 | } |
| 483 | }) |
| 484 | } |
| 485 | } |
| 486 | |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 487 | func TestOpenOltResourceMgr_GetGEMPortID(t *testing.T) { |
| 488 | type args struct { |
| 489 | ponPort uint32 |
| 490 | onuID uint32 |
| 491 | uniID uint32 |
| 492 | NumOfPorts uint32 |
| 493 | } |
| 494 | tests := []struct { |
| 495 | name string |
| 496 | fields *fields |
| 497 | args args |
| 498 | want []uint32 |
| 499 | wantErr error |
| 500 | }{ |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 501 | {"GetGEMPortID-1", getResMgr(), args{1, 2, 2, 2}, []uint32{}, |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 502 | errors.New("failed to get gem port")}, |
| 503 | } |
| 504 | for _, tt := range tests { |
| 505 | t.Run(tt.name, func(t *testing.T) { |
| 506 | RsrcMgr := testResMgrObject(tt.fields) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 507 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 508 | defer cancel() |
| 509 | got, err := RsrcMgr.GetGEMPortID(ctx, tt.args.ponPort, tt.args.onuID, tt.args.uniID, tt.args.NumOfPorts) |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 510 | if reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr) && err != nil { |
| 511 | t.Errorf("GetGEMPortID() error = %v, wantErr %v", err, tt.wantErr) |
| 512 | return |
| 513 | } |
| 514 | if reflect.TypeOf(got) != reflect.TypeOf(tt.want) { |
| 515 | t.Errorf("GetGEMPortID() got = %v, want %v", got, tt.want) |
| 516 | } |
| 517 | }) |
| 518 | } |
| 519 | } |
| 520 | |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 521 | func TestOpenOltResourceMgr_GetMeterInfoForOnu(t *testing.T) { |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 522 | type args struct { |
| 523 | Direction string |
| 524 | IntfID uint32 |
| 525 | OnuID uint32 |
| 526 | UniID uint32 |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 527 | tpID uint32 |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 528 | } |
| 529 | tests := []struct { |
| 530 | name string |
| 531 | fields *fields |
| 532 | args args |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 533 | want *MeterInfo |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 534 | wantErr error |
| 535 | }{ |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 536 | {"GetMeterInfoForOnu", getResMgr(), args{"DOWNSTREAM", 0, 1, 1, 64}, |
| 537 | &MeterInfo{}, errors.New("failed to get Meter config from kvstore for path")}, |
| 538 | {"GetMeterInfoForOnu", getResMgr(), args{"DOWNSTREAM", 1, 2, 2, 65}, |
| 539 | &MeterInfo{}, errors.New("failed to get Meter config from kvstore for path")}, |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 540 | } |
| 541 | for _, tt := range tests { |
| 542 | t.Run(tt.name, func(t *testing.T) { |
| 543 | RsrcMgr := testResMgrObject(tt.fields) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 544 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 545 | defer cancel() |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 546 | got, err := RsrcMgr.GetMeterInfoForOnu(ctx, tt.args.Direction, tt.args.IntfID, tt.args.OnuID, tt.args.UniID, tt.args.tpID) |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 547 | if reflect.TypeOf(got) != reflect.TypeOf(tt.want) && err != nil { |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 548 | t.Errorf("GetMeterInfoForOnu() got = %v, want %v", got, tt.want) |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 549 | } |
| 550 | }) |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | func TestOpenOltResourceMgr_GetONUID(t *testing.T) { |
| 555 | type args struct { |
| 556 | ponIntfID uint32 |
| 557 | } |
| 558 | tests := []struct { |
| 559 | name string |
| 560 | fields *fields |
| 561 | args args |
| 562 | want uint32 |
| 563 | wantErr error |
| 564 | }{ |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 565 | {"GetONUID-1", getResMgr(), args{1}, uint32(0), errors.New("json errors")}, |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 566 | } |
| 567 | for _, tt := range tests { |
| 568 | t.Run(tt.name, func(t *testing.T) { |
| 569 | RsrcMgr := testResMgrObject(tt.fields) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 570 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 571 | defer cancel() |
| 572 | got, err := RsrcMgr.GetONUID(ctx, tt.args.ponIntfID) |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 573 | if got != tt.want && err != nil { |
| 574 | t.Errorf("GetONUID() got = %v, want %v", got, tt.want) |
| 575 | } |
| 576 | }) |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | func TestOpenOltResourceMgr_GetTechProfileIDForOnu(t *testing.T) { |
| 581 | |
| 582 | type args struct { |
| 583 | IntfID uint32 |
| 584 | OnuID uint32 |
| 585 | UniID uint32 |
| 586 | } |
| 587 | tests := []struct { |
| 588 | name string |
| 589 | fields *fields |
| 590 | args args |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 591 | want []uint32 |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 592 | }{ |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 593 | {"GetTechProfileIDForOnu-1", getResMgr(), args{1, 2, 2}, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 594 | []uint32{1}}, |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 595 | } |
| 596 | for _, tt := range tests { |
| 597 | t.Run(tt.name, func(t *testing.T) { |
| 598 | RsrcMgr := testResMgrObject(tt.fields) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 599 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 600 | defer cancel() |
| 601 | if got := RsrcMgr.GetTechProfileIDForOnu(ctx, tt.args.IntfID, tt.args.OnuID, tt.args.UniID); reflect.TypeOf(got) != reflect.TypeOf(tt.want) { |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 602 | t.Errorf("GetTechProfileIDForOnu() = %v, want %v", got, tt.want) |
| 603 | } |
| 604 | }) |
| 605 | } |
| 606 | } |
| 607 | |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 608 | func TestOpenOltResourceMgr_RemoveMeterIDForOnu(t *testing.T) { |
| 609 | |
| 610 | type args struct { |
| 611 | Direction string |
| 612 | IntfID uint32 |
| 613 | OnuID uint32 |
| 614 | UniID uint32 |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 615 | tpID uint32 |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 616 | } |
| 617 | tests := []struct { |
| 618 | name string |
| 619 | fields *fields |
| 620 | args args |
| 621 | wantErr error |
| 622 | }{ |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 623 | {"RemoveMeterIdForOnu-1", getResMgr(), args{"DOWNSTREAM", 1, 1, 1, 64}, |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 624 | errors.New("failed to delete meter id %s from kvstore")}, |
| 625 | } |
| 626 | for _, tt := range tests { |
| 627 | t.Run(tt.name, func(t *testing.T) { |
| 628 | RsrcMgr := testResMgrObject(tt.fields) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 629 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 630 | defer cancel() |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 631 | if err := RsrcMgr.RemoveMeterInfoForOnu(ctx, tt.args.Direction, tt.args.IntfID, tt.args.OnuID, tt.args.UniID, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 632 | tt.args.tpID); reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr) && err != nil { |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 633 | t.Errorf("RemoveMeterIDForOnu() error = %v, wantErr %v", err, tt.wantErr) |
| 634 | } |
| 635 | }) |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | func TestOpenOltResourceMgr_RemoveTechProfileIDForOnu(t *testing.T) { |
| 640 | type args struct { |
| 641 | IntfID uint32 |
| 642 | OnuID uint32 |
| 643 | UniID uint32 |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 644 | tpID uint32 |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 645 | } |
| 646 | tests := []struct { |
| 647 | name string |
| 648 | fields *fields |
| 649 | args args |
| 650 | wantErr error |
| 651 | }{ |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 652 | {"RemoveTechProfileIDForOnu-1", getResMgr(), args{1, 2, 2, 64}, |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 653 | errors.New("failed to delete techprofile id resource %s in KV store")}, |
| 654 | } |
| 655 | for _, tt := range tests { |
| 656 | t.Run(tt.name, func(t *testing.T) { |
| 657 | RsrcMgr := testResMgrObject(tt.fields) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 658 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 659 | defer cancel() |
| 660 | if err := RsrcMgr.RemoveTechProfileIDForOnu(ctx, tt.args.IntfID, tt.args.OnuID, tt.args.UniID, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 661 | tt.args.tpID); reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr) && err != nil { |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 662 | t.Errorf("RemoveTechProfileIDForOnu() error = %v, wantErr %v", err, tt.wantErr) |
| 663 | } |
| 664 | }) |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | func TestOpenOltResourceMgr_UpdateAllocIdsForOnu(t *testing.T) { |
| 669 | type args struct { |
| 670 | ponPort uint32 |
| 671 | onuID uint32 |
| 672 | uniID uint32 |
| 673 | allocID []uint32 |
| 674 | } |
| 675 | tests := []struct { |
| 676 | name string |
| 677 | fields *fields |
| 678 | args args |
| 679 | wantErr error |
| 680 | }{ |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 681 | {"UpdateAllocIdsForOnu-1", getResMgr(), args{1, 2, 2, []uint32{1, 2}}, |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 682 | errors.New("")}, |
| 683 | } |
| 684 | for _, tt := range tests { |
| 685 | t.Run(tt.name, func(t *testing.T) { |
| 686 | RsrcMgr := testResMgrObject(tt.fields) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 687 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 688 | defer cancel() |
| 689 | 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) { |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 690 | t.Errorf("UpdateAllocIdsForOnu() error = %v, wantErr %v", err, tt.wantErr) |
| 691 | } |
| 692 | }) |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | func TestOpenOltResourceMgr_UpdateFlowIDInfo(t *testing.T) { |
| 697 | type args struct { |
| 698 | ponIntfID int32 |
| 699 | onuID int32 |
| 700 | uniID int32 |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 701 | flowID uint64 |
| 702 | flowData FlowInfo |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 703 | } |
| 704 | tests := []struct { |
| 705 | name string |
| 706 | fields *fields |
| 707 | args args |
| 708 | wantErr error |
| 709 | }{ |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 710 | {"UpdateFlowIDInfo-1", getResMgr(), args{1, 2, 2, 2, FlowInfo{}}, errors.New("")}, |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 711 | } |
| 712 | for _, tt := range tests { |
| 713 | t.Run(tt.name, func(t *testing.T) { |
| 714 | RsrcMgr := testResMgrObject(tt.fields) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 715 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 716 | defer cancel() |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 717 | if err := RsrcMgr.UpdateFlowIDInfo(ctx, uint32(tt.args.ponIntfID), tt.args.onuID, tt.args.uniID, tt.args.flowID, tt.args.flowData); err != nil && reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr) { |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 718 | t.Errorf("UpdateFlowIDInfo() error = %v, wantErr %v", err, tt.wantErr) |
| 719 | } |
| 720 | }) |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | func TestOpenOltResourceMgr_UpdateGEMPortIDsForOnu(t *testing.T) { |
| 725 | |
| 726 | type args struct { |
| 727 | ponPort uint32 |
| 728 | onuID uint32 |
| 729 | uniID uint32 |
| 730 | GEMPortList []uint32 |
| 731 | } |
| 732 | tests := []struct { |
| 733 | name string |
| 734 | fields *fields |
| 735 | args args |
| 736 | wantErr error |
| 737 | }{ |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 738 | {"UpdateGEMPortIDsForOnu-1", getResMgr(), args{1, 2, 2, |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 739 | []uint32{1, 2}}, errors.New("failed to update resource")}, |
| 740 | } |
| 741 | for _, tt := range tests { |
| 742 | t.Run(tt.name, func(t *testing.T) { |
| 743 | RsrcMgr := testResMgrObject(tt.fields) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 744 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 745 | defer cancel() |
| 746 | 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) { |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 747 | t.Errorf("UpdateGEMPortIDsForOnu() error = %v, wantErr %v", err, tt.wantErr) |
| 748 | } |
| 749 | }) |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | func TestOpenOltResourceMgr_UpdateGEMportsPonportToOnuMapOnKVStore(t *testing.T) { |
| 754 | type args struct { |
| 755 | gemPorts []uint32 |
| 756 | PonPort uint32 |
| 757 | onuID uint32 |
| 758 | uniID uint32 |
| 759 | } |
| 760 | tests := []struct { |
| 761 | name string |
| 762 | fields *fields |
| 763 | args args |
| 764 | wantErr error |
| 765 | }{ |
| 766 | {"UpdateGEMportsPonportToOnuMapOnKVStore-1", getResMgr(), args{[]uint32{1, 2}, |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 767 | 1, 2, 2}, errors.New("failed to update resource")}, |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 768 | } |
| 769 | for _, tt := range tests { |
| 770 | t.Run(tt.name, func(t *testing.T) { |
| 771 | RsrcMgr := testResMgrObject(tt.fields) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 772 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 773 | defer cancel() |
| 774 | if err := RsrcMgr.UpdateGEMportsPonportToOnuMapOnKVStore(ctx, tt.args.gemPorts, tt.args.PonPort, |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 775 | tt.args.onuID, tt.args.uniID); err != nil && reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr) { |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 776 | t.Errorf("UpdateGEMportsPonportToOnuMapOnKVStore() error = %v, wantErr %v", err, tt.wantErr) |
| 777 | } |
| 778 | }) |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | func TestOpenOltResourceMgr_UpdateMeterIDForOnu(t *testing.T) { |
| 783 | type args struct { |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 784 | Direction string |
| 785 | IntfID uint32 |
| 786 | OnuID uint32 |
| 787 | UniID uint32 |
| 788 | tpID uint32 |
| 789 | MeterInfo *MeterInfo |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 790 | } |
| 791 | tests := []struct { |
| 792 | name string |
| 793 | fields *fields |
| 794 | args args |
| 795 | wantErr error |
| 796 | }{ |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 797 | {"UpdateMeterIDForOnu-1", getResMgr(), args{"DOWNSTREAM", 1, 2, |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 798 | 2, 64, &MeterInfo{}}, errors.New("failed to get Meter config from kvstore for path")}, |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 799 | } |
| 800 | for _, tt := range tests { |
| 801 | t.Run(tt.name, func(t *testing.T) { |
| 802 | RsrcMgr := testResMgrObject(tt.fields) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 803 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 804 | defer cancel() |
Girish Gowdra | a482f27 | 2021-03-24 23:04:19 -0700 | [diff] [blame] | 805 | if err := RsrcMgr.StoreMeterInfoForOnu(ctx, tt.args.Direction, tt.args.IntfID, tt.args.OnuID, tt.args.UniID, |
| 806 | tt.args.tpID, tt.args.MeterInfo); reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr) && err != nil { |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 807 | t.Errorf("UpdateMeterIDForOnu() got = %v, want %v", err, tt.wantErr) |
| 808 | } |
| 809 | }) |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | func TestOpenOltResourceMgr_UpdateTechProfileIDForOnu(t *testing.T) { |
| 814 | type args struct { |
| 815 | IntfID uint32 |
| 816 | OnuID uint32 |
| 817 | UniID uint32 |
| 818 | TpID uint32 |
| 819 | } |
| 820 | tests := []struct { |
| 821 | name string |
| 822 | fields *fields |
| 823 | args args |
| 824 | wantErr error |
| 825 | }{ |
Girish Gowdra | 38d533d | 2020-03-30 20:38:51 -0700 | [diff] [blame] | 826 | {"UpdateTechProfileIDForOnu-1", getResMgr(), args{1, 2, 2, |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 827 | 2}, errors.New("failed to update resource")}, |
| 828 | } |
| 829 | for _, tt := range tests { |
| 830 | t.Run(tt.name, func(t *testing.T) { |
| 831 | RsrcMgr := testResMgrObject(tt.fields) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 832 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 833 | defer cancel() |
| 834 | 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 { |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 835 | t.Errorf("UpdateTechProfileIDForOnu() got = %v, want %v", err, tt.wantErr) |
| 836 | } |
| 837 | }) |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | func TestSetKVClient(t *testing.T) { |
| 842 | type args struct { |
Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 843 | backend string |
| 844 | address string |
| 845 | DeviceID string |
| 846 | kvStorePrefix string |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 847 | } |
| 848 | tests := []struct { |
| 849 | name string |
| 850 | args args |
sbarbari | a8910ba | 2019-11-05 10:12:23 -0500 | [diff] [blame] | 851 | want *db.Backend |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 852 | }{ |
serkant.uluderya | 7b8211e | 2021-02-24 16:39:18 +0300 | [diff] [blame] | 853 | {"setKVClient-1", args{"etcd", "1.1.1.1:1", "olt1", "service/voltha"}, &db.Backend{}}, |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 854 | } |
| 855 | for _, tt := range tests { |
| 856 | t.Run(tt.name, func(t *testing.T) { |
Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 857 | if got := SetKVClient(context.Background(), tt.args.backend, tt.args.address, tt.args.DeviceID, tt.args.kvStorePrefix); reflect.TypeOf(got) != reflect.TypeOf(tt.want) { |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 858 | t.Errorf("SetKVClient() = %v, want %v", got, tt.want) |
| 859 | } |
| 860 | }) |
| 861 | } |
| 862 | } |
| 863 | |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 864 | func Test_newKVClient(t *testing.T) { |
| 865 | type args struct { |
| 866 | storeType string |
| 867 | address string |
Neha Sharma | cc65696 | 2020-04-14 14:26:11 +0000 | [diff] [blame] | 868 | timeout time.Duration |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 869 | } |
| 870 | var kvClient kvstore.Client |
| 871 | tests := []struct { |
| 872 | name string |
| 873 | args args |
| 874 | want kvstore.Client |
| 875 | wantErr error |
| 876 | }{ |
| 877 | {"newKVClient-1", args{"", "3.3.3.3", 1}, kvClient, errors.New("unsupported-kv-store")}, |
| 878 | } |
| 879 | for _, tt := range tests { |
| 880 | t.Run(tt.name, func(t *testing.T) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 881 | got, err := newKVClient(context.Background(), tt.args.storeType, tt.args.address, tt.args.timeout) |
cbabu | abf0235 | 2019-10-15 13:14:56 +0200 | [diff] [blame] | 882 | if got != nil && reflect.TypeOf(got) != reflect.TypeOf(tt.want) { |
| 883 | t.Errorf("newKVClient() got = %v, want %v", got, tt.want) |
| 884 | } |
| 885 | if (err != nil) && reflect.TypeOf(err) != reflect.TypeOf(tt.wantErr) { |
| 886 | t.Errorf("newKVClient() error = %v, wantErr %v", err, tt.wantErr) |
| 887 | return |
| 888 | } |
| 889 | |
| 890 | }) |
| 891 | } |
| 892 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 893 | |
| 894 | func TestOpenOltResourceMgr_AddMcastQueueForIntf(t *testing.T) { |
| 895 | type args struct { |
| 896 | intf uint32 |
| 897 | gem uint32 |
| 898 | servicePriority uint32 |
| 899 | } |
| 900 | tests := []struct { |
| 901 | name string |
| 902 | args args |
| 903 | fields *fields |
| 904 | }{ |
| 905 | {"AddMcastQueueForIntf-1", args{0, 4000, 0}, getResMgr()}, |
| 906 | {"AddMcastQueueForIntf-2", args{1, 4000, 1}, getResMgr()}, |
| 907 | {"AddMcastQueueForIntf-3", args{2, 4000, 2}, getResMgr()}, |
| 908 | } |
| 909 | for _, tt := range tests { |
| 910 | t.Run(tt.name, func(t *testing.T) { |
| 911 | RsrcMgr := testResMgrObject(tt.fields) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 912 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 913 | defer cancel() |
| 914 | err := RsrcMgr.AddMcastQueueForIntf(ctx, tt.args.intf, tt.args.gem, tt.args.servicePriority) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 915 | if err != nil { |
| 916 | t.Errorf("%s got err= %s wants nil", tt.name, err) |
| 917 | return |
| 918 | } |
| 919 | }) |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | func newGroup(groupID uint32, outPorts []uint32) *ofp.OfpGroupEntry { |
| 924 | groupDesc := ofp.OfpGroupDesc{ |
| 925 | Type: ofp.OfpGroupType_OFPGT_ALL, |
| 926 | GroupId: groupID, |
| 927 | } |
| 928 | groupEntry := ofp.OfpGroupEntry{ |
| 929 | Desc: &groupDesc, |
| 930 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 931 | for i := 0; i < len(outPorts); i++ { |
Esin Karaman | 0ebd2a3 | 2020-02-09 18:45:36 +0000 | [diff] [blame] | 932 | var acts []*ofp.OfpAction |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 933 | acts = append(acts, fu.Output(outPorts[i])) |
Esin Karaman | 0ebd2a3 | 2020-02-09 18:45:36 +0000 | [diff] [blame] | 934 | bucket := ofp.OfpBucket{ |
| 935 | Actions: acts, |
| 936 | } |
| 937 | groupDesc.Buckets = append(groupDesc.Buckets, &bucket) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 938 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 939 | return &groupEntry |
| 940 | } |
| 941 | |
| 942 | func TestOpenOltResourceMgr_AddFlowGroupToKVStore(t *testing.T) { |
| 943 | type args struct { |
| 944 | group *ofp.OfpGroupEntry |
| 945 | cached bool |
| 946 | } |
| 947 | //create group 1 |
| 948 | group1 := newGroup(1, []uint32{1}) |
| 949 | //create group 2 |
| 950 | group2 := newGroup(2, []uint32{2}) |
| 951 | //define test set |
| 952 | tests := []struct { |
| 953 | name string |
| 954 | args args |
| 955 | fields *fields |
| 956 | }{ |
| 957 | {"AddFlowGroupToKVStore-1", args{group1, true}, getResMgr()}, |
| 958 | {"AddFlowGroupToKVStore-2", args{group2, false}, getResMgr()}, |
| 959 | } |
| 960 | //execute tests |
| 961 | for _, tt := range tests { |
| 962 | t.Run(tt.name, func(t *testing.T) { |
| 963 | RsrcMgr := testResMgrObject(tt.fields) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 964 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 965 | defer cancel() |
| 966 | err := RsrcMgr.AddFlowGroupToKVStore(ctx, tt.args.group, tt.args.cached) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 967 | if err != nil { |
| 968 | t.Errorf("%s got err= %s wants nil", tt.name, err) |
| 969 | return |
| 970 | } |
| 971 | }) |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | func TestOpenOltResourceMgr_RemoveFlowGroupFromKVStore(t *testing.T) { |
| 976 | type args struct { |
| 977 | groupID uint32 |
| 978 | cached bool |
| 979 | } |
| 980 | //define test set |
| 981 | tests := []struct { |
| 982 | name string |
| 983 | args args |
| 984 | fields *fields |
| 985 | }{ |
| 986 | {"RemoveFlowGroupFromKVStore-1", args{1, true}, getResMgr()}, |
| 987 | {"RemoveFlowGroupFromKVStore-2", args{2, false}, getResMgr()}, |
| 988 | } |
| 989 | //execute tests |
| 990 | for _, tt := range tests { |
| 991 | t.Run(tt.name, func(t *testing.T) { |
| 992 | RsrcMgr := testResMgrObject(tt.fields) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 993 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 994 | defer cancel() |
Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 995 | err := RsrcMgr.RemoveFlowGroupFromKVStore(ctx, tt.args.groupID, tt.args.cached) |
| 996 | if err != nil { |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 997 | t.Errorf("%s got false but wants true", tt.name) |
| 998 | return |
| 999 | } |
| 1000 | }) |
| 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | func TestOpenOltResourceMgr_GetFlowGroupFromKVStore(t *testing.T) { |
| 1005 | type args struct { |
| 1006 | groupID uint32 |
| 1007 | cached bool |
| 1008 | } |
| 1009 | //define test set |
| 1010 | tests := []struct { |
| 1011 | name string |
| 1012 | args args |
| 1013 | fields *fields |
| 1014 | }{ |
| 1015 | {"GetFlowGroupFromKVStore-1", args{1, true}, getResMgr()}, |
| 1016 | {"GetFlowGroupFromKVStore-2", args{2, false}, getResMgr()}, |
| 1017 | {"GetFlowGroupFromKVStore-3", args{1000, false}, getResMgr()}, |
| 1018 | } |
| 1019 | //execute tests |
| 1020 | for _, tt := range tests { |
| 1021 | t.Run(tt.name, func(t *testing.T) { |
| 1022 | RsrcMgr := testResMgrObject(tt.fields) |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 1023 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 1024 | defer cancel() |
| 1025 | exists, groupInfo, err := RsrcMgr.GetFlowGroupFromKVStore(ctx, tt.args.groupID, tt.args.cached) |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 1026 | if err != nil { |
| 1027 | t.Errorf("%s got error but wants nil error", tt.name) |
| 1028 | return |
| 1029 | } else if exists && (groupInfo.GroupID == 0) { |
| 1030 | t.Errorf("%s got true and nil group info but expected not nil group info", tt.name) |
| 1031 | return |
| 1032 | } else if tt.args.groupID == 3 && exists { |
| 1033 | t.Errorf("%s got true but wants false", tt.name) |
| 1034 | return |
| 1035 | } |
| 1036 | }) |
| 1037 | } |
| 1038 | } |