gerardo.laurenzi | 444e250 | 2019-11-15 09:26:46 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package model |
| 18 | |
| 19 | import ( |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 20 | "reflect" |
| 21 | "testing" |
| 22 | |
gerardo.laurenzi | 444e250 | 2019-11-15 09:26:46 +0000 | [diff] [blame] | 23 | "github.com/golang/protobuf/ptypes/any" |
serkant.uluderya | 2ae470f | 2020-01-21 11:13:09 -0800 | [diff] [blame] | 24 | "github.com/opencord/voltha-protos/v3/go/common" |
| 25 | "github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 26 | "github.com/opencord/voltha-protos/v3/go/voltha" |
gerardo.laurenzi | 444e250 | 2019-11-15 09:26:46 +0000 | [diff] [blame] | 27 | "github.com/stretchr/testify/assert" |
gerardo.laurenzi | 444e250 | 2019-11-15 09:26:46 +0000 | [diff] [blame] | 28 | ) |
| 29 | |
| 30 | var ( |
| 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 | |
| 74 | func 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 | } |
| 90 | func TestNoDataRevision(t *testing.T) { |
| 91 | |
npujar | 9a30c70 | 2019-11-14 17:06:39 +0530 | [diff] [blame] | 92 | TestNodeData = nil |
| 93 | TestNodeRoot = &root{RevisionClass: reflect.TypeOf(NonPersistedRevision{})} |
| 94 | rev := NewDataRevision(TestNodeRoot, TestNodeData) |
gerardo.laurenzi | 444e250 | 2019-11-15 09:26:46 +0000 | [diff] [blame] | 95 | assert.Nil(t, rev.Data, "Problem to marshal data when data is nil") |
| 96 | |
| 97 | } |