khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [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 | */ |
Stephane Barbarie | 4a2564d | 2018-07-26 11:02:58 -0400 | [diff] [blame] | 16 | package model |
| 17 | |
| 18 | import ( |
| 19 | "crypto/md5" |
| 20 | "fmt" |
| 21 | "github.com/golang/protobuf/ptypes/any" |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 22 | "github.com/opencord/voltha-go/protos/common" |
| 23 | "github.com/opencord/voltha-go/protos/openflow_13" |
| 24 | "github.com/opencord/voltha-go/protos/voltha" |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame^] | 25 | "reflect" |
Stephane Barbarie | 4a2564d | 2018-07-26 11:02:58 -0400 | [diff] [blame] | 26 | "testing" |
| 27 | ) |
| 28 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame^] | 29 | var ( |
| 30 | TestNode_Port = []*voltha.Port{ |
Stephane Barbarie | 4a2564d | 2018-07-26 11:02:58 -0400 | [diff] [blame] | 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 | } |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame^] | 41 | |
| 42 | TestNode_Device = &voltha.Device{ |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 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{}, |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame^] | 65 | Ports: TestNode_Port, |
Stephane Barbarie | ec0919b | 2018-09-05 14:14:29 -0400 | [diff] [blame] | 66 | Flows: &openflow_13.Flows{}, |
| 67 | FlowGroups: &openflow_13.FlowGroups{}, |
| 68 | PmConfigs: &voltha.PmConfigs{}, |
| 69 | ImageDownloads: []*voltha.ImageDownload{}, |
Stephane Barbarie | 4a2564d | 2018-07-26 11:02:58 -0400 | [diff] [blame] | 70 | } |
Stephane Barbarie | 4a2564d | 2018-07-26 11:02:58 -0400 | [diff] [blame] | 71 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame^] | 72 | TestNode_Data = TestNode_Device |
Stephane Barbarie | 4a2564d | 2018-07-26 11:02:58 -0400 | [diff] [blame] | 73 | |
Stephane Barbarie | 1039ec4 | 2019-02-04 10:43:16 -0500 | [diff] [blame^] | 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) |
Stephane Barbarie | 4a2564d | 2018-07-26 11:02:58 -0400 | [diff] [blame] | 94 | } |