Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [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" |
| 21 | "github.com/golang/protobuf/ptypes/any" |
Scott Baker | f1b096c | 2019-11-01 12:36:30 -0700 | [diff] [blame] | 22 | "github.com/opencord/voltha-protos/v2/go/common" |
| 23 | "github.com/opencord/voltha-protos/v2/go/openflow_13" |
| 24 | "github.com/opencord/voltha-protos/v2/go/voltha" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 25 | "reflect" |
| 26 | "testing" |
| 27 | ) |
| 28 | |
| 29 | var ( |
| 30 | TestNode_Port = []*voltha.Port{ |
| 31 | { |
| 32 | PortNo: 123, |
| 33 | Label: "test-etcd_port-0", |
| 34 | Type: voltha.Port_PON_OLT, |
| 35 | AdminState: common.AdminState_ENABLED, |
| 36 | OperStatus: common.OperStatus_ACTIVE, |
| 37 | DeviceId: "etcd_port-0-device-id", |
| 38 | Peers: []*voltha.Port_PeerPort{}, |
| 39 | }, |
| 40 | } |
| 41 | |
| 42 | TestNode_Device = &voltha.Device{ |
| 43 | Id: "Config-SomeNode-01-new-test", |
| 44 | Type: "simulated_olt", |
| 45 | Root: true, |
| 46 | ParentId: "", |
| 47 | ParentPortNo: 0, |
| 48 | Vendor: "voltha-test", |
| 49 | Model: "GetLatest-voltha-simulated-olt", |
| 50 | HardwareVersion: "1.0.0", |
| 51 | FirmwareVersion: "1.0.0", |
| 52 | Images: &voltha.Images{}, |
| 53 | SerialNumber: "abcdef-123456", |
| 54 | VendorId: "DEADBEEF-INC", |
| 55 | Adapter: "simulated_olt", |
| 56 | Vlan: 1234, |
| 57 | Address: &voltha.Device_HostAndPort{HostAndPort: "1.2.3.4:5555"}, |
| 58 | ExtraArgs: "", |
| 59 | ProxyAddress: &voltha.Device_ProxyAddress{}, |
| 60 | AdminState: voltha.AdminState_PREPROVISIONED, |
| 61 | OperStatus: common.OperStatus_ACTIVE, |
| 62 | Reason: "", |
| 63 | ConnectStatus: common.ConnectStatus_REACHABLE, |
| 64 | Custom: &any.Any{}, |
| 65 | Ports: TestNode_Port, |
| 66 | Flows: &openflow_13.Flows{}, |
| 67 | FlowGroups: &openflow_13.FlowGroups{}, |
| 68 | PmConfigs: &voltha.PmConfigs{}, |
| 69 | ImageDownloads: []*voltha.ImageDownload{}, |
| 70 | } |
| 71 | |
| 72 | TestNode_Data = TestNode_Device |
| 73 | |
| 74 | TestNode_Txid = fmt.Sprintf("%x", md5.Sum([]byte("node_transaction_id"))) |
| 75 | TestNode_Root = &root{RevisionClass: reflect.TypeOf(NonPersistedRevision{})} |
| 76 | ) |
| 77 | |
| 78 | // Exercise node creation code |
| 79 | // This test will |
| 80 | func TestNode_01_NewNode(t *testing.T) { |
| 81 | node := NewNode(TestNode_Root, TestNode_Data, false, TestNode_Txid) |
| 82 | |
| 83 | if reflect.ValueOf(node.Type).Type() != reflect.TypeOf(TestNode_Data) { |
| 84 | t.Errorf("Node type does not match original data type: %+v", reflect.ValueOf(node.Type).Type()) |
| 85 | } else if node.GetBranch(TestNode_Txid) == nil || node.GetBranch(TestNode_Txid).Latest == nil { |
| 86 | t.Errorf("No branch associated to txid: %s", TestNode_Txid) |
| 87 | } else if node.GetBranch(TestNode_Txid).Latest == nil { |
| 88 | t.Errorf("Branch has no latest revision : %s", TestNode_Txid) |
| 89 | } else if node.GetBranch(TestNode_Txid).GetLatest().GetConfig() == nil { |
| 90 | t.Errorf("Latest revision has no assigned data: %+v", node.GetBranch(TestNode_Txid).GetLatest()) |
| 91 | } |
| 92 | |
| 93 | t.Logf("Created new node successfully : %+v\n", node) |
| 94 | } |