Hardik Windlass | 8486168 | 2019-11-10 05:44:33 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019-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 | package core |
| 17 | |
| 18 | import ( |
| 19 | "context" |
npujar | 03b018e | 2019-11-13 15:29:36 +0530 | [diff] [blame] | 20 | "reflect" |
| 21 | "testing" |
| 22 | |
Hardik Windlass | 8486168 | 2019-11-10 05:44:33 +0000 | [diff] [blame] | 23 | "github.com/opencord/voltha-go/db/model" |
| 24 | "github.com/opencord/voltha-go/ro_core/config" |
| 25 | "github.com/opencord/voltha-protos/v2/go/openflow_13" |
| 26 | "github.com/opencord/voltha-protos/v2/go/voltha" |
| 27 | "github.com/stretchr/testify/assert" |
Hardik Windlass | 8486168 | 2019-11-10 05:44:33 +0000 | [diff] [blame] | 28 | ) |
| 29 | |
| 30 | func MakeTestNewCoreConfig() *Core { |
| 31 | var core Core |
npujar | 03b018e | 2019-11-13 15:29:36 +0530 | [diff] [blame] | 32 | core.instanceID = "ro_core" |
Hardik Windlass | 8486168 | 2019-11-10 05:44:33 +0000 | [diff] [blame] | 33 | core.config = config.NewROCoreFlags() |
| 34 | core.clusterDataRoot = model.NewRoot(&voltha.Voltha{}, nil) |
| 35 | core.clusterDataProxy = core.clusterDataRoot.CreateProxy(context.Background(), "/", false) |
| 36 | core.genericMgr = newModelProxyManager(core.clusterDataProxy) |
npujar | 03b018e | 2019-11-13 15:29:36 +0530 | [diff] [blame] | 37 | core.deviceMgr = newDeviceManager(core.clusterDataProxy, core.instanceID) |
Hardik Windlass | 8486168 | 2019-11-10 05:44:33 +0000 | [diff] [blame] | 38 | |
| 39 | return &core |
| 40 | } |
| 41 | |
| 42 | func TestNewLogicalDeviceManager(t *testing.T) { |
| 43 | core := MakeTestNewCoreConfig() |
| 44 | |
| 45 | logicalDevMgr := newLogicalDeviceManager(core.deviceMgr, core.clusterDataProxy) |
| 46 | assert.NotNil(t, logicalDevMgr) |
| 47 | } |
| 48 | |
| 49 | func TestAddLogicalDeviceAgentToMap(t *testing.T) { |
| 50 | core := MakeTestNewCoreConfig() |
| 51 | ldMgr := newLogicalDeviceManager(core.deviceMgr, core.clusterDataProxy) |
| 52 | assert.NotNil(t, ldMgr) |
| 53 | |
| 54 | // Before ADD |
| 55 | ldAgentNil := ldMgr.getLogicalDeviceAgent("id") |
| 56 | assert.Nil(t, ldAgentNil) |
| 57 | |
| 58 | /*** Case: addLogicalDeviceAgentToMap() is Success ***/ |
| 59 | ldAgent := newLogicalDeviceAgent("id", "", ldMgr, core.deviceMgr, core.clusterDataProxy) |
| 60 | assert.NotNil(t, ldAgent) |
| 61 | ldMgr.addLogicalDeviceAgentToMap(ldAgent) |
| 62 | |
| 63 | // Verify ADD is successful |
| 64 | ldAgentNotNil := ldMgr.getLogicalDeviceAgent("id") |
| 65 | assert.NotNil(t, ldAgentNotNil) |
npujar | 03b018e | 2019-11-13 15:29:36 +0530 | [diff] [blame] | 66 | assert.Equal(t, "id", ldAgentNotNil.logicalDeviceID) |
Hardik Windlass | 8486168 | 2019-11-10 05:44:33 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | func TestGetLogicalDeviceAgent(t *testing.T) { |
| 70 | core := MakeTestNewCoreConfig() |
| 71 | ldMgr := newLogicalDeviceManager(core.deviceMgr, core.clusterDataProxy) |
| 72 | assert.NotNil(t, ldMgr) |
| 73 | |
| 74 | /*** Case: getLogicalDeviceAgent() is NIL ***/ |
| 75 | ldAgentNil := ldMgr.getLogicalDeviceAgent("id") |
| 76 | assert.Nil(t, ldAgentNil) |
| 77 | |
| 78 | /*** Case: getLogicalDeviceAgent() is Success ***/ |
| 79 | ldAgent := newLogicalDeviceAgent("id", "", ldMgr, core.deviceMgr, core.clusterDataProxy) |
| 80 | assert.NotNil(t, ldAgent) |
| 81 | ldMgr.addLogicalDeviceAgentToMap(ldAgent) |
| 82 | ldAgentNotNil := ldMgr.getLogicalDeviceAgent("id") |
| 83 | assert.NotNil(t, ldAgentNotNil) |
npujar | 03b018e | 2019-11-13 15:29:36 +0530 | [diff] [blame] | 84 | assert.Equal(t, "id", ldAgentNotNil.logicalDeviceID) |
Hardik Windlass | 8486168 | 2019-11-10 05:44:33 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | func TestDeleteLogicalDeviceAgent(t *testing.T) { |
| 88 | core := MakeTestNewCoreConfig() |
| 89 | ldMgr := newLogicalDeviceManager(core.deviceMgr, core.clusterDataProxy) |
| 90 | assert.NotNil(t, ldMgr) |
| 91 | |
| 92 | /*** Case: deleteLogicalDeviceAgent() with Invalid Value ***/ |
| 93 | ldAgentNilChk := ldMgr.getLogicalDeviceAgent("invalid_id") |
| 94 | assert.Nil(t, ldAgentNilChk) |
| 95 | ldMgr.deleteLogicalDeviceAgent("invalid_id") |
| 96 | |
| 97 | /*** Case: deleteLogicalDeviceAgent() is Success ***/ |
| 98 | // Initialize and Add Logical Device Agent |
| 99 | ldAgent := newLogicalDeviceAgent("id", "", ldMgr, core.deviceMgr, core.clusterDataProxy) |
| 100 | assert.NotNil(t, ldAgent) |
| 101 | ldMgr.addLogicalDeviceAgentToMap(ldAgent) |
| 102 | |
| 103 | // Verify ADD is successful |
| 104 | ldAgentNotNil := ldMgr.getLogicalDeviceAgent("id") |
| 105 | assert.NotNil(t, ldAgentNotNil) |
npujar | 03b018e | 2019-11-13 15:29:36 +0530 | [diff] [blame] | 106 | assert.Equal(t, "id", ldAgentNotNil.logicalDeviceID) |
Hardik Windlass | 8486168 | 2019-11-10 05:44:33 +0000 | [diff] [blame] | 107 | |
| 108 | // Method under Test |
| 109 | ldMgr.deleteLogicalDeviceAgent("id") |
| 110 | |
| 111 | // Verify DEL is successful |
| 112 | ldAgentNil := ldMgr.getLogicalDeviceAgent("id") |
| 113 | assert.Nil(t, ldAgentNil) |
| 114 | } |
| 115 | |
| 116 | func TestLdMgrGetLogicalDevice(t *testing.T) { |
| 117 | wantResult := &voltha.LogicalDevice{} |
| 118 | |
| 119 | core := MakeTestNewCoreConfig() |
| 120 | ldMgr := newLogicalDeviceManager(core.deviceMgr, core.clusterDataProxy) |
| 121 | assert.NotNil(t, ldMgr) |
| 122 | |
| 123 | /*** Case: getLogicalDevice() is NIL ***/ |
| 124 | logicalDevNil, errNotNil := ldMgr.getLogicalDevice("id") |
| 125 | assert.Nil(t, logicalDevNil) |
| 126 | assert.NotNil(t, errNotNil) |
| 127 | |
| 128 | /*** Case: getLogicalDevice() is Success ***/ |
| 129 | // Add Data |
| 130 | if added := core.clusterDataProxy.Add( |
| 131 | context.Background(), |
| 132 | "/logical_devices", |
| 133 | &voltha.LogicalDevice{ |
| 134 | Id: "id", |
| 135 | }, |
| 136 | ""); added == nil { |
| 137 | t.Error("Failed to add logical device") |
| 138 | } |
| 139 | ldAgent := newLogicalDeviceAgent("id", "device_id", ldMgr, core.deviceMgr, core.clusterDataProxy) |
| 140 | assert.NotNil(t, ldAgent) |
| 141 | ldMgr.addLogicalDeviceAgentToMap(ldAgent) |
| 142 | |
| 143 | // Verify Add is successful |
| 144 | ldAgentNotNil := ldMgr.getLogicalDeviceAgent("id") |
| 145 | assert.NotNil(t, ldAgentNotNil) |
npujar | 03b018e | 2019-11-13 15:29:36 +0530 | [diff] [blame] | 146 | assert.Equal(t, "id", ldAgentNotNil.logicalDeviceID) |
Hardik Windlass | 8486168 | 2019-11-10 05:44:33 +0000 | [diff] [blame] | 147 | |
| 148 | // Verify getLogicalDevice() is NOT NIL |
| 149 | logicalDevNotNil, errNil := ldMgr.getLogicalDevice("id") |
| 150 | assert.NotNil(t, logicalDevNotNil) |
| 151 | assert.Nil(t, errNil) |
| 152 | if reflect.TypeOf(logicalDevNotNil) != reflect.TypeOf(wantResult) { |
| 153 | t.Errorf("GetLogicalDevice() = %v, want %v", logicalDevNotNil, wantResult) |
| 154 | } |
| 155 | assert.Equal(t, "id", logicalDevNotNil.Id) |
| 156 | } |
| 157 | |
| 158 | func TestListLogicalDevices(t *testing.T) { |
| 159 | wantResult := &voltha.LogicalDevices{} |
| 160 | |
| 161 | core := MakeTestNewCoreConfig() |
| 162 | ldMgr := newLogicalDeviceManager(core.deviceMgr, core.clusterDataProxy) |
| 163 | assert.NotNil(t, ldMgr) |
| 164 | |
| 165 | /*** Case: listLogicalDevices() is Empty ***/ |
| 166 | result, error := ldMgr.listLogicalDevices() |
| 167 | assert.NotNil(t, result) |
| 168 | assert.Nil(t, error) |
| 169 | if reflect.TypeOf(result) != reflect.TypeOf(wantResult) { |
| 170 | t.Errorf("ListLogicalDevices() = %v, want %v", result, wantResult) |
| 171 | } |
| 172 | assert.Empty(t, result) |
| 173 | } |
| 174 | |
| 175 | func TestLoad(t *testing.T) { |
| 176 | core := MakeTestNewCoreConfig() |
| 177 | ldMgr := newLogicalDeviceManager(core.deviceMgr, core.clusterDataProxy) |
| 178 | assert.NotNil(t, ldMgr) |
| 179 | |
| 180 | /*** Case: Error Scenario ***/ |
| 181 | error := ldMgr.load("id") |
| 182 | assert.NotNil(t, error) |
| 183 | } |
| 184 | |
| 185 | func TestGetLogicalDeviceId(t *testing.T) { |
| 186 | core := MakeTestNewCoreConfig() |
| 187 | ldMgr := newLogicalDeviceManager(core.deviceMgr, core.clusterDataProxy) |
| 188 | assert.NotNil(t, ldMgr) |
| 189 | |
| 190 | /*** Case: Logical Device Id Found ***/ |
npujar | 03b018e | 2019-11-13 15:29:36 +0530 | [diff] [blame] | 191 | result0, error0 := ldMgr.getLogicalDeviceID(&voltha.Device{Id: "id", Root: true, ParentId: "parent_id"}) |
Hardik Windlass | 8486168 | 2019-11-10 05:44:33 +0000 | [diff] [blame] | 192 | assert.NotNil(t, result0) |
| 193 | assert.Nil(t, error0) |
| 194 | |
| 195 | /*** Case: Logical Device Id Not Found ***/ |
npujar | 03b018e | 2019-11-13 15:29:36 +0530 | [diff] [blame] | 196 | result1, error1 := ldMgr.getLogicalDeviceID(&voltha.Device{Id: "id", ParentId: "parent_id"}) |
Hardik Windlass | 8486168 | 2019-11-10 05:44:33 +0000 | [diff] [blame] | 197 | assert.Nil(t, result1) |
| 198 | assert.NotNil(t, error1) |
| 199 | } |
| 200 | |
| 201 | func TestGetLogicalPortId(t *testing.T) { |
| 202 | wantResult := &voltha.LogicalPortId{} |
| 203 | |
| 204 | core := MakeTestNewCoreConfig() |
| 205 | ldMgr := newLogicalDeviceManager(core.deviceMgr, core.clusterDataProxy) |
| 206 | assert.NotNil(t, ldMgr) |
| 207 | |
| 208 | /*** Case: Logical Port Id Not Found: getLogicalDeviceId() Error ***/ |
npujar | 03b018e | 2019-11-13 15:29:36 +0530 | [diff] [blame] | 209 | result0, error0 := ldMgr.getLogicalPortID(&voltha.Device{Id: "id", ParentId: "parent_id"}) |
Hardik Windlass | 8486168 | 2019-11-10 05:44:33 +0000 | [diff] [blame] | 210 | assert.Nil(t, result0) |
| 211 | assert.NotNil(t, error0) |
| 212 | |
| 213 | /*** Case: Logical Port Id Not Found: getLogicalDevice() Error ***/ |
npujar | 03b018e | 2019-11-13 15:29:36 +0530 | [diff] [blame] | 214 | result1, error1 := ldMgr.getLogicalPortID(&voltha.Device{Id: "id", Root: true, ParentId: "parent_id"}) |
Hardik Windlass | 8486168 | 2019-11-10 05:44:33 +0000 | [diff] [blame] | 215 | assert.Nil(t, result1) |
| 216 | assert.NotNil(t, error1) |
| 217 | |
| 218 | /*** Case: Logical Port Id Found ***/ |
| 219 | device := &voltha.Device{Id: "id", Root: true, ParentId: "parent_id"} |
| 220 | |
| 221 | // Add Data |
| 222 | if added := core.clusterDataProxy.Add( |
| 223 | context.Background(), |
| 224 | "/logical_devices", |
| 225 | &voltha.LogicalDevice{ |
| 226 | Id: "parent_id", |
| 227 | Ports: []*voltha.LogicalPort{ |
| 228 | { |
| 229 | Id: "123", |
| 230 | DeviceId: "id", |
| 231 | }, |
| 232 | }, |
| 233 | }, |
| 234 | ""); added == nil { |
| 235 | t.Error("Failed to add logical device") |
| 236 | } |
| 237 | ldAgent := newLogicalDeviceAgent("parent_id", "device_id", ldMgr, core.deviceMgr, core.clusterDataProxy) |
| 238 | assert.NotNil(t, ldAgent) |
| 239 | ldMgr.addLogicalDeviceAgentToMap(ldAgent) |
| 240 | |
| 241 | // Verify Add is successful |
| 242 | ldAgentNotNil := ldMgr.getLogicalDeviceAgent("parent_id") |
| 243 | assert.NotNil(t, ldAgentNotNil) |
npujar | 03b018e | 2019-11-13 15:29:36 +0530 | [diff] [blame] | 244 | assert.Equal(t, "parent_id", ldAgentNotNil.logicalDeviceID) |
Hardik Windlass | 8486168 | 2019-11-10 05:44:33 +0000 | [diff] [blame] | 245 | |
| 246 | // Verify getLogicalPortId() is Success |
npujar | 03b018e | 2019-11-13 15:29:36 +0530 | [diff] [blame] | 247 | result2, error2 := ldMgr.getLogicalPortID(device) |
Hardik Windlass | 8486168 | 2019-11-10 05:44:33 +0000 | [diff] [blame] | 248 | assert.NotNil(t, result2) |
| 249 | assert.Nil(t, error2) |
| 250 | if reflect.TypeOf(result2) != reflect.TypeOf(wantResult) { |
| 251 | t.Errorf("GetLogicalPortId() = %v, want %v", result2, wantResult) |
| 252 | } |
| 253 | assert.Equal(t, "parent_id", result2.Id) |
| 254 | } |
| 255 | |
| 256 | func TestListLogicalDevicePorts(t *testing.T) { |
| 257 | core := MakeTestNewCoreConfig() |
| 258 | ldMgr := newLogicalDeviceManager(core.deviceMgr, core.clusterDataProxy) |
| 259 | assert.NotNil(t, ldMgr) |
| 260 | |
| 261 | /*** Case: Logical Device Ports Not Found ***/ |
| 262 | result0, error0 := ldMgr.ListLogicalDevicePorts(context.Background(), "id") |
| 263 | assert.Nil(t, result0) |
| 264 | assert.NotNil(t, error0) |
| 265 | |
| 266 | /*** Case: Logical Device Ports Found ***/ |
| 267 | wantResult := &voltha.LogicalPorts{ |
| 268 | Items: []*voltha.LogicalPort{ |
| 269 | { |
| 270 | Id: "123", |
| 271 | }, |
| 272 | }, |
| 273 | } |
| 274 | |
| 275 | // Add Data |
| 276 | if added := core.clusterDataProxy.Add( |
| 277 | context.Background(), |
| 278 | "/logical_devices", |
| 279 | &voltha.LogicalDevice{ |
| 280 | Id: "id", |
| 281 | Ports: []*voltha.LogicalPort{ |
| 282 | { |
| 283 | Id: "123", |
| 284 | }, |
| 285 | }, |
| 286 | }, |
| 287 | ""); added == nil { |
| 288 | t.Error("Failed to add logical device") |
| 289 | } |
| 290 | ldAgent := newLogicalDeviceAgent("id", "", ldMgr, core.deviceMgr, core.clusterDataProxy) |
| 291 | ldMgr.addLogicalDeviceAgentToMap(ldAgent) |
| 292 | |
| 293 | // Verify Add is successful |
| 294 | ldAgentNotNil := ldMgr.getLogicalDeviceAgent("id") |
| 295 | assert.NotNil(t, ldAgentNotNil) |
npujar | 03b018e | 2019-11-13 15:29:36 +0530 | [diff] [blame] | 296 | assert.Equal(t, "id", ldAgentNotNil.logicalDeviceID) |
Hardik Windlass | 8486168 | 2019-11-10 05:44:33 +0000 | [diff] [blame] | 297 | |
| 298 | // Verify ListLogicalDevicePorts() is Success |
| 299 | result1, error1 := ldMgr.ListLogicalDevicePorts(context.Background(), "id") |
| 300 | assert.NotNil(t, result1) |
| 301 | assert.Nil(t, error1) |
| 302 | if reflect.TypeOf(result1) != reflect.TypeOf(wantResult) { |
| 303 | t.Errorf("ListLogicalDevicePorts() = %v, want %v", result1, wantResult) |
| 304 | } |
| 305 | assert.Equal(t, wantResult, result1) |
| 306 | } |
| 307 | |
| 308 | func TestListLogicalDeviceFlows(t *testing.T) { |
| 309 | core := MakeTestNewCoreConfig() |
| 310 | ldMgr := newLogicalDeviceManager(core.deviceMgr, core.clusterDataProxy) |
| 311 | assert.NotNil(t, ldMgr) |
| 312 | |
| 313 | /*** Case: Logical Device Flows Not Found ***/ |
| 314 | result0, error0 := ldMgr.ListLogicalDeviceFlows(context.Background(), "id") |
| 315 | assert.Nil(t, result0) |
| 316 | assert.NotNil(t, error0) |
| 317 | |
| 318 | /*** Case: Logical Device Flows Found ***/ |
| 319 | wantResult := &voltha.Flows{} |
| 320 | |
| 321 | // Add Data |
| 322 | if added := core.clusterDataProxy.Add( |
| 323 | context.Background(), |
| 324 | "/logical_devices", |
| 325 | &voltha.LogicalDevice{ |
| 326 | Id: "id", |
| 327 | Flows: &openflow_13.Flows{ |
| 328 | Items: []*openflow_13.OfpFlowStats{ |
| 329 | &openflow_13.OfpFlowStats{ |
| 330 | Id: 1111, |
| 331 | }, |
| 332 | }, |
| 333 | }, |
| 334 | }, |
| 335 | ""); added == nil { |
| 336 | t.Error("Failed to add logical device") |
| 337 | } |
| 338 | ldAgent := newLogicalDeviceAgent("id", "", ldMgr, core.deviceMgr, core.clusterDataProxy) |
| 339 | ldMgr.addLogicalDeviceAgentToMap(ldAgent) |
| 340 | |
| 341 | // Verify Add is successful |
| 342 | ldAgentNotNil := ldMgr.getLogicalDeviceAgent("id") |
| 343 | assert.NotNil(t, ldAgentNotNil) |
npujar | 03b018e | 2019-11-13 15:29:36 +0530 | [diff] [blame] | 344 | assert.Equal(t, "id", ldAgentNotNil.logicalDeviceID) |
Hardik Windlass | 8486168 | 2019-11-10 05:44:33 +0000 | [diff] [blame] | 345 | |
| 346 | // Verify ListLogicalDeviceFlows() is Success |
| 347 | result1, error1 := ldMgr.ListLogicalDeviceFlows(context.Background(), "id") |
| 348 | assert.NotNil(t, result1) |
| 349 | assert.Nil(t, error1) |
| 350 | if reflect.TypeOf(result1) != reflect.TypeOf(wantResult) { |
| 351 | t.Errorf("ListLogicalDeviceFlows() = %v, want %v", result1, wantResult) |
| 352 | } |
| 353 | assert.NotEmpty(t, result1) |
| 354 | } |
| 355 | |
| 356 | func TestListLogicalDeviceFlowGroups(t *testing.T) { |
| 357 | core := MakeTestNewCoreConfig() |
| 358 | ldMgr := newLogicalDeviceManager(core.deviceMgr, core.clusterDataProxy) |
| 359 | assert.NotNil(t, ldMgr) |
| 360 | |
| 361 | /*** Case: Logical Device Flow Groups Not Found ***/ |
| 362 | result0, error0 := ldMgr.ListLogicalDeviceFlowGroups(context.Background(), "id") |
| 363 | assert.Nil(t, result0) |
| 364 | assert.NotNil(t, error0) |
| 365 | |
| 366 | /*** Case: Logical Device Flow Groups Found ***/ |
| 367 | wantResult := &voltha.FlowGroups{} |
| 368 | |
| 369 | // Add Data |
| 370 | if added := core.clusterDataProxy.Add( |
| 371 | context.Background(), |
| 372 | "/logical_devices", |
| 373 | &voltha.LogicalDevice{ |
| 374 | Id: "id", |
| 375 | FlowGroups: &openflow_13.FlowGroups{ |
| 376 | Items: []*openflow_13.OfpGroupEntry{ |
| 377 | { |
| 378 | Stats: &openflow_13.OfpGroupStats{ |
| 379 | GroupId: 1, |
| 380 | }, |
| 381 | }, |
| 382 | }, |
| 383 | }, |
| 384 | }, |
| 385 | ""); added == nil { |
| 386 | t.Error("Failed to add logical device") |
| 387 | } |
| 388 | ldAgent := newLogicalDeviceAgent("id", "", ldMgr, core.deviceMgr, core.clusterDataProxy) |
| 389 | ldMgr.addLogicalDeviceAgentToMap(ldAgent) |
| 390 | |
| 391 | // Verify Add is successful |
| 392 | ldAgentNotNil := ldMgr.getLogicalDeviceAgent("id") |
| 393 | assert.NotNil(t, ldAgentNotNil) |
npujar | 03b018e | 2019-11-13 15:29:36 +0530 | [diff] [blame] | 394 | assert.Equal(t, "id", ldAgentNotNil.logicalDeviceID) |
Hardik Windlass | 8486168 | 2019-11-10 05:44:33 +0000 | [diff] [blame] | 395 | |
| 396 | // Verify ListLogicalDeviceFlowGroups() is Success |
| 397 | result1, error1 := ldMgr.ListLogicalDeviceFlowGroups(context.Background(), "id") |
| 398 | assert.NotNil(t, result1) |
| 399 | assert.Nil(t, error1) |
| 400 | if reflect.TypeOf(result1) != reflect.TypeOf(wantResult) { |
| 401 | t.Errorf("ListLogicalDeviceFlowGroups() = %v, want %v", result1, wantResult) |
| 402 | } |
| 403 | assert.NotEmpty(t, result1) |
| 404 | } |
| 405 | |
| 406 | func TestGetLogicalPort(t *testing.T) { |
| 407 | core := MakeTestNewCoreConfig() |
| 408 | ldMgr := newLogicalDeviceManager(core.deviceMgr, core.clusterDataProxy) |
| 409 | assert.NotNil(t, ldMgr) |
| 410 | |
| 411 | /*** Case: Logical Port Not Found: getLogicalDevice() Error ***/ |
| 412 | result0, error0 := ldMgr.getLogicalPort(&voltha.LogicalPortId{Id: "id", PortId: "123"}) |
| 413 | assert.Nil(t, result0) |
| 414 | assert.NotNil(t, error0) |
| 415 | |
| 416 | /*** Case: Logical Port Found ***/ |
| 417 | wantResult := &voltha.LogicalPort{Id: "123"} |
| 418 | |
| 419 | // Add Data |
| 420 | if added := core.clusterDataProxy.Add( |
| 421 | context.Background(), |
| 422 | "/logical_devices", |
| 423 | &voltha.LogicalDevice{ |
| 424 | Id: "id", |
| 425 | Ports: []*voltha.LogicalPort{ |
| 426 | { |
| 427 | Id: "123", |
| 428 | }, |
| 429 | }, |
| 430 | }, |
| 431 | ""); added == nil { |
| 432 | t.Error("Failed to add logical device") |
| 433 | } |
| 434 | ldAgent := newLogicalDeviceAgent("id", "", ldMgr, core.deviceMgr, core.clusterDataProxy) |
| 435 | ldMgr.addLogicalDeviceAgentToMap(ldAgent) |
| 436 | |
| 437 | // Verify Add is successful |
| 438 | ldAgentNotNil := ldMgr.getLogicalDeviceAgent("id") |
| 439 | assert.NotNil(t, ldAgentNotNil) |
npujar | 03b018e | 2019-11-13 15:29:36 +0530 | [diff] [blame] | 440 | assert.Equal(t, "id", ldAgentNotNil.logicalDeviceID) |
Hardik Windlass | 8486168 | 2019-11-10 05:44:33 +0000 | [diff] [blame] | 441 | |
| 442 | // Verify getLogicalPort() is Success |
| 443 | result1, error1 := ldMgr.getLogicalPort(&voltha.LogicalPortId{Id: "id", PortId: "123"}) |
| 444 | assert.NotNil(t, result1) |
| 445 | assert.Nil(t, error1) |
| 446 | if reflect.TypeOf(result1) != reflect.TypeOf(wantResult) { |
| 447 | t.Errorf("getLogicalPort() = %v, want %v", result1, wantResult) |
| 448 | } |
| 449 | assert.Equal(t, wantResult, result1) |
| 450 | } |