sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [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 | package model |
| 17 | |
| 18 | import ( |
| 19 | "crypto/md5" |
| 20 | "fmt" |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 21 | "reflect" |
| 22 | "testing" |
| 23 | |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 24 | "github.com/golang/protobuf/ptypes/any" |
serkant.uluderya | 2ae470f | 2020-01-21 11:13:09 -0800 | [diff] [blame] | 25 | "github.com/opencord/voltha-protos/v3/go/common" |
| 26 | "github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 27 | "github.com/opencord/voltha-protos/v3/go/voltha" |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 28 | ) |
| 29 | |
| 30 | var ( |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 31 | TestNodeDevice = &voltha.Device{ |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 32 | Id: "Config-SomeNode-01-new-test", |
| 33 | Type: "simulated_olt", |
| 34 | Root: true, |
| 35 | ParentId: "", |
| 36 | ParentPortNo: 0, |
| 37 | Vendor: "voltha-test", |
| 38 | Model: "GetLatest-voltha-simulated-olt", |
| 39 | HardwareVersion: "1.0.0", |
| 40 | FirmwareVersion: "1.0.0", |
| 41 | Images: &voltha.Images{}, |
| 42 | SerialNumber: "abcdef-123456", |
| 43 | VendorId: "DEADBEEF-INC", |
| 44 | Adapter: "simulated_olt", |
| 45 | Vlan: 1234, |
| 46 | Address: &voltha.Device_HostAndPort{HostAndPort: "1.2.3.4:5555"}, |
| 47 | ExtraArgs: "", |
| 48 | ProxyAddress: &voltha.Device_ProxyAddress{}, |
| 49 | AdminState: voltha.AdminState_PREPROVISIONED, |
| 50 | OperStatus: common.OperStatus_ACTIVE, |
| 51 | Reason: "", |
| 52 | ConnectStatus: common.ConnectStatus_REACHABLE, |
| 53 | Custom: &any.Any{}, |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 54 | Ports: TestNodePort, |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 55 | Flows: &openflow_13.Flows{}, |
| 56 | FlowGroups: &openflow_13.FlowGroups{}, |
| 57 | PmConfigs: &voltha.PmConfigs{}, |
| 58 | ImageDownloads: []*voltha.ImageDownload{}, |
| 59 | } |
| 60 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 61 | TestNodeTxid = fmt.Sprintf("%x", md5.Sum([]byte("node_transaction_id"))) |
| 62 | TestNodeRoot = &root{RevisionClass: reflect.TypeOf(NonPersistedRevision{})} |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 63 | ) |
| 64 | |
| 65 | // Exercise node creation code |
| 66 | // This test will |
| 67 | func TestNode_01_NewNode(t *testing.T) { |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 68 | node := newNode(TestNodeRoot, TestNodeDevice, false, TestNodeTxid) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 69 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 70 | if reflect.ValueOf(node.Type).Type() != reflect.TypeOf(TestNodeDevice) { |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 71 | t.Errorf("Node type does not match original data type: %+v", reflect.ValueOf(node.Type).Type()) |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 72 | } else if node.GetBranch(TestNodeTxid) == nil || node.GetBranch(TestNodeTxid).Latest == nil { |
| 73 | t.Errorf("No branch associated to txid: %s", TestNodeTxid) |
| 74 | } else if node.GetBranch(TestNodeTxid).Latest == nil { |
| 75 | t.Errorf("Branch has no latest revision : %s", TestNodeTxid) |
| 76 | } else if node.GetBranch(TestNodeTxid).GetLatest().GetConfig() == nil { |
| 77 | t.Errorf("Latest revision has no assigned data: %+v", node.GetBranch(TestNodeTxid).GetLatest()) |
sbarbari | 17d7e22 | 2019-11-05 10:02:29 -0500 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | t.Logf("Created new node successfully : %+v\n", node) |
| 81 | } |