blob: 635525f14f91c9b31c451bf5ac4544b663fe5b1a [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 (
npujar9a30c702019-11-14 17:06:39 +053020 "reflect"
21 "testing"
22
gerardo.laurenzi444e2502019-11-15 09:26:46 +000023 "github.com/golang/protobuf/ptypes/any"
24 "github.com/opencord/voltha-protos/v2/go/common"
25 "github.com/opencord/voltha-protos/v2/go/openflow_13"
26 "github.com/opencord/voltha-protos/v2/go/voltha"
27 "github.com/stretchr/testify/assert"
gerardo.laurenzi444e2502019-11-15 09:26:46 +000028)
29
30var (
31 TestNodePort = []*voltha.Port{
32 {
33 PortNo: 123,
34 Label: "test-etcd_port-0",
35 Type: voltha.Port_PON_OLT,
36 AdminState: common.AdminState_ENABLED,
37 OperStatus: common.OperStatus_ACTIVE,
38 DeviceId: "etcd_port-0-device-id",
39 Peers: []*voltha.Port_PeerPort{},
40 },
41 }
42
43 TestNodeData = &voltha.Device{
44 Id: "Config-Node-1",
45 Type: "simulated_olt",
46 Root: true,
47 ParentId: "",
48 ParentPortNo: 0,
49 Vendor: "voltha-test",
50 Model: "Modelxx",
51 HardwareVersion: "0.0.1",
52 FirmwareVersion: "0.0.1",
53 Images: &voltha.Images{},
54 SerialNumber: "1234567890",
55 VendorId: "XXBB-INC",
56 Adapter: "simulated_olt",
57 Vlan: 1234,
58 Address: &voltha.Device_HostAndPort{HostAndPort: "127.0.0.1:1234"},
59 ExtraArgs: "",
60 ProxyAddress: &voltha.Device_ProxyAddress{},
61 AdminState: voltha.AdminState_PREPROVISIONED,
62 OperStatus: common.OperStatus_ACTIVE,
63 Reason: "",
64 ConnectStatus: common.ConnectStatus_REACHABLE,
65 Custom: &any.Any{},
66 Ports: TestNodePort,
67 Flows: &openflow_13.Flows{},
68 FlowGroups: &openflow_13.FlowGroups{},
69 PmConfigs: &voltha.PmConfigs{},
70 ImageDownloads: []*voltha.ImageDownload{},
71 }
72)
73
74func TestNewDataRevision(t *testing.T) {
75
76 TestNodeRoot := &root{RevisionClass: reflect.TypeOf(NonPersistedRevision{})}
77 dr := NewDataRevision(TestNodeRoot, TestNodeData)
78 t.Logf("Data -->%v, Hash-->%v, ", dr.Data, dr.Hash)
79 assert.NotNil(t, dr.Data)
80 assert.True(t, reflect.TypeOf(dr.Data) == reflect.TypeOf(TestNodeData), "Data Type mismatch on NonPersistedRevision")
81 assert.True(t, reflect.ValueOf(dr.Data) == reflect.ValueOf(TestNodeData), "Data Values mismatch on NonPersistedRevision")
82 assert.NotNil(t, dr.Hash)
83
84 drPR := NewDataRevision(&root{RevisionClass: reflect.TypeOf(PersistedRevision{})}, TestNodeData)
85 assert.NotNil(t, drPR)
86 assert.True(t, reflect.TypeOf(drPR.Data) == reflect.TypeOf(TestNodeData), "Data Type mismatc on PersistedRevisionh")
87 assert.True(t, reflect.ValueOf(drPR.Data) == reflect.ValueOf(TestNodeData), "Data Values mismatch PersistedRevision")
88 assert.NotNil(t, drPR.Hash)
89}
90func TestNoDataRevision(t *testing.T) {
91
npujar9a30c702019-11-14 17:06:39 +053092 TestNodeData = nil
93 TestNodeRoot = &root{RevisionClass: reflect.TypeOf(NonPersistedRevision{})}
94 rev := NewDataRevision(TestNodeRoot, TestNodeData)
gerardo.laurenzi444e2502019-11-15 09:26:46 +000095 assert.Nil(t, rev.Data, "Problem to marshal data when data is nil")
96
97}