blob: 76b892306ebf94918449b5f17613b722fb05eb77 [file] [log] [blame]
gerardo.laurenzi444e2502019-11-15 09:26:46 +00001/*
2 * Copyright 2019-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
17package model
18
19import (
20 "github.com/golang/protobuf/ptypes/any"
21 "github.com/opencord/voltha-protos/v2/go/common"
22 "github.com/opencord/voltha-protos/v2/go/openflow_13"
23 "github.com/opencord/voltha-protos/v2/go/voltha"
24 "github.com/stretchr/testify/assert"
25 "reflect"
26 "testing"
27)
28
29var (
30 TestNodePort = []*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 TestNodeData = &voltha.Device{
43 Id: "Config-Node-1",
44 Type: "simulated_olt",
45 Root: true,
46 ParentId: "",
47 ParentPortNo: 0,
48 Vendor: "voltha-test",
49 Model: "Modelxx",
50 HardwareVersion: "0.0.1",
51 FirmwareVersion: "0.0.1",
52 Images: &voltha.Images{},
53 SerialNumber: "1234567890",
54 VendorId: "XXBB-INC",
55 Adapter: "simulated_olt",
56 Vlan: 1234,
57 Address: &voltha.Device_HostAndPort{HostAndPort: "127.0.0.1:1234"},
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: TestNodePort,
66 Flows: &openflow_13.Flows{},
67 FlowGroups: &openflow_13.FlowGroups{},
68 PmConfigs: &voltha.PmConfigs{},
69 ImageDownloads: []*voltha.ImageDownload{},
70 }
71)
72
73func TestNewDataRevision(t *testing.T) {
74
75 TestNodeRoot := &root{RevisionClass: reflect.TypeOf(NonPersistedRevision{})}
76 dr := NewDataRevision(TestNodeRoot, TestNodeData)
77 t.Logf("Data -->%v, Hash-->%v, ", dr.Data, dr.Hash)
78 assert.NotNil(t, dr.Data)
79 assert.True(t, reflect.TypeOf(dr.Data) == reflect.TypeOf(TestNodeData), "Data Type mismatch on NonPersistedRevision")
80 assert.True(t, reflect.ValueOf(dr.Data) == reflect.ValueOf(TestNodeData), "Data Values mismatch on NonPersistedRevision")
81 assert.NotNil(t, dr.Hash)
82
83 drPR := NewDataRevision(&root{RevisionClass: reflect.TypeOf(PersistedRevision{})}, TestNodeData)
84 assert.NotNil(t, drPR)
85 assert.True(t, reflect.TypeOf(drPR.Data) == reflect.TypeOf(TestNodeData), "Data Type mismatc on PersistedRevisionh")
86 assert.True(t, reflect.ValueOf(drPR.Data) == reflect.ValueOf(TestNodeData), "Data Values mismatch PersistedRevision")
87 assert.NotNil(t, drPR.Hash)
88}
89func TestNoDataRevision(t *testing.T) {
90
91 TestNode_Data = nil
92 TestNode_Root = &root{RevisionClass: reflect.TypeOf(NonPersistedRevision{})}
93 rev := NewDataRevision(TestNode_Root, TestNode_Data)
94 assert.Nil(t, rev.Data, "Problem to marshal data when data is nil")
95
96}