blob: d60cc44eebd2946ff8e1f0341997e203e7b3d5a7 [file] [log] [blame]
khenaidoobf6e7bb2018-08-14 22:27:29 -04001/*
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 Barbarie4a2564d2018-07-26 11:02:58 -040016package model
17
18import (
19 "crypto/md5"
20 "fmt"
21 "github.com/golang/protobuf/ptypes/any"
Stephane Barbarieec0919b2018-09-05 14:14:29 -040022 "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 Barbarie1039ec42019-02-04 10:43:16 -050025 "reflect"
Stephane Barbarie4a2564d2018-07-26 11:02:58 -040026 "testing"
27)
28
Stephane Barbarie1039ec42019-02-04 10:43:16 -050029var (
30 TestNode_Port = []*voltha.Port{
Stephane Barbarie4a2564d2018-07-26 11:02:58 -040031 {
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 Barbarie1039ec42019-02-04 10:43:16 -050041
42 TestNode_Device = &voltha.Device{
Stephane Barbarieec0919b2018-09-05 14:14:29 -040043 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 Barbarie1039ec42019-02-04 10:43:16 -050065 Ports: TestNode_Port,
Stephane Barbarieec0919b2018-09-05 14:14:29 -040066 Flows: &openflow_13.Flows{},
67 FlowGroups: &openflow_13.FlowGroups{},
68 PmConfigs: &voltha.PmConfigs{},
69 ImageDownloads: []*voltha.ImageDownload{},
Stephane Barbarie4a2564d2018-07-26 11:02:58 -040070 }
Stephane Barbarie4a2564d2018-07-26 11:02:58 -040071
Stephane Barbarie1039ec42019-02-04 10:43:16 -050072 TestNode_Data = TestNode_Device
Stephane Barbarie4a2564d2018-07-26 11:02:58 -040073
Stephane Barbarie1039ec42019-02-04 10:43:16 -050074 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
80func 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 Barbarie4a2564d2018-07-26 11:02:58 -040094}