blob: aadf21ae876dfe68a19125133824ed537d4c1767 [file] [log] [blame]
sbarbari17d7e222019-11-05 10:02:29 -05001/*
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 */
16package model
17
18import (
19 "crypto/md5"
20 "fmt"
npujar9a30c702019-11-14 17:06:39 +053021 "reflect"
22 "testing"
23
sbarbari17d7e222019-11-05 10:02:29 -050024 "github.com/golang/protobuf/ptypes/any"
serkant.uluderya2ae470f2020-01-21 11:13:09 -080025 "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"
sbarbari17d7e222019-11-05 10:02:29 -050028)
29
30var (
npujar9a30c702019-11-14 17:06:39 +053031 TestNodeDevice = &voltha.Device{
sbarbari17d7e222019-11-05 10:02:29 -050032 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{},
npujar9a30c702019-11-14 17:06:39 +053054 Ports: TestNodePort,
sbarbari17d7e222019-11-05 10:02:29 -050055 Flows: &openflow_13.Flows{},
56 FlowGroups: &openflow_13.FlowGroups{},
57 PmConfigs: &voltha.PmConfigs{},
58 ImageDownloads: []*voltha.ImageDownload{},
59 }
60
npujar9a30c702019-11-14 17:06:39 +053061 TestNodeTxid = fmt.Sprintf("%x", md5.Sum([]byte("node_transaction_id")))
62 TestNodeRoot = &root{RevisionClass: reflect.TypeOf(NonPersistedRevision{})}
sbarbari17d7e222019-11-05 10:02:29 -050063)
64
65// Exercise node creation code
66// This test will
67func TestNode_01_NewNode(t *testing.T) {
npujar9a30c702019-11-14 17:06:39 +053068 node := newNode(TestNodeRoot, TestNodeDevice, false, TestNodeTxid)
sbarbari17d7e222019-11-05 10:02:29 -050069
npujar9a30c702019-11-14 17:06:39 +053070 if reflect.ValueOf(node.Type).Type() != reflect.TypeOf(TestNodeDevice) {
sbarbari17d7e222019-11-05 10:02:29 -050071 t.Errorf("Node type does not match original data type: %+v", reflect.ValueOf(node.Type).Type())
npujar9a30c702019-11-14 17:06:39 +053072 } 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())
sbarbari17d7e222019-11-05 10:02:29 -050078 }
79
80 t.Logf("Created new node successfully : %+v\n", node)
81}