Daniele Rossi | 566c75c | 2019-11-06 16:55:56 +0100 | [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 | "github.com/opencord/voltha-go/ro_core/config" |
| 20 | "github.com/phayes/freeport" |
| 21 | "github.com/stretchr/testify/assert" |
| 22 | "strconv" |
| 23 | "testing" |
| 24 | ) |
| 25 | |
| 26 | func MakeTestLogDevAgConfig() (*Core, error) { |
| 27 | var core *Core |
| 28 | var roCoreFlgs *config.ROCoreFlags |
| 29 | var roC *roCore |
| 30 | |
| 31 | freePort, errP := freeport.GetFreePort() |
| 32 | if errP == nil { |
| 33 | freePortStr := strconv.Itoa(freePort) |
| 34 | |
| 35 | roCoreFlgs = config.NewROCoreFlags() |
| 36 | roC = newROCore(roCoreFlgs) |
| 37 | if (roC != nil) && (roCoreFlgs != nil) { |
| 38 | addr := "127.0.0.1" + ":" + freePortStr |
| 39 | cli, err := newKVClient("etcd", addr, 5) |
| 40 | if err == nil { |
| 41 | roC.kvClient = cli |
| 42 | //return roCoreFlgs, roC |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | core = NewCore("ro_core", roCoreFlgs, roC.kvClient) |
| 48 | |
| 49 | return core, nil |
| 50 | } |
| 51 | |
| 52 | // newLogicalDeviceAgent test |
| 53 | func TestNewLogicalDeviceAgent(t *testing.T) { |
| 54 | core, _ := MakeTestLogDevAgConfig() |
| 55 | assert.NotNil(t, core) |
| 56 | logAgent := newLogicalDeviceAgent("log-dev", "", core.logicalDeviceMgr, core.deviceMgr, core.clusterDataProxy) |
| 57 | assert.NotNil(t, logAgent) |
| 58 | } |
| 59 | |
| 60 | // GetLogicalDevice, Flows, Ports test |
| 61 | func TestGetLogicalDevice(t *testing.T) { |
| 62 | core, _ := MakeTestLogDevAgConfig() |
| 63 | assert.NotNil(t, core) |
| 64 | |
| 65 | logDevMgr := newLogicalDeviceManager(core.deviceMgr, core.clusterDataProxy) |
| 66 | assert.NotNil(t, logDevMgr) |
| 67 | |
| 68 | logAgent := newLogicalDeviceAgent("log-dev-ag", "", logDevMgr, core.deviceMgr, logDevMgr.clusterDataProxy) |
| 69 | assert.NotNil(t, logAgent) |
| 70 | |
| 71 | logDevMgr.addLogicalDeviceAgentToMap(logAgent) |
| 72 | |
| 73 | logDev, err := logAgent.GetLogicalDevice() |
| 74 | assert.Nil(t, logDev) |
| 75 | assert.NotNil(t, err) |
| 76 | |
| 77 | Flws, err := logAgent.ListLogicalDeviceFlows() |
| 78 | assert.Nil(t, Flws) |
| 79 | assert.NotNil(t, err) |
| 80 | FlwsGrp, err := logAgent.ListLogicalDeviceFlowGroups() |
| 81 | assert.Nil(t, FlwsGrp) |
| 82 | assert.NotNil(t, err) |
| 83 | |
| 84 | logDevPorts, err := logAgent.ListLogicalDevicePorts() |
| 85 | assert.Nil(t, logDevPorts) |
| 86 | assert.NotNil(t, err) |
| 87 | |
| 88 | } |