blob: 7d8f3875adaa34854fde1d91da3427bc6c8cd728 [file] [log] [blame]
Elia Battistonaa7a0482022-08-17 12:24:02 +00001/*
2* Copyright 2022-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 core
18
19import (
20 "testing"
21
22 "github.com/opencord/voltha-northbound-bbf-adapter/internal/clients"
23 "github.com/stretchr/testify/assert"
24)
25
26func TestLocationsToPortsMap(t *testing.T) {
27 ports := []clients.OnosPort{
28 {
29 Element: "of:00001",
30 Port: "256",
31 Annotations: map[string]string{
32 "portName": "TESTPORT-1",
33 },
34 },
35 {
36 Element: "of:00001",
37 Port: "257",
38 Annotations: map[string]string{
39 "portName": "TESTPORT-2",
40 },
41 },
42 }
43
44 portNames := getLocationsToPortsMap(ports)
45
46 assert.NotEmpty(t, portNames, "Empty map")
47
48 name, ok := portNames["of:00001/256"]
49 assert.True(t, ok, "First port name not found")
50 assert.Equal(t, "TESTPORT-1", name)
51
52 name, ok = portNames["of:00001/257"]
53 assert.True(t, ok, "Second port name not found")
54 assert.Equal(t, "TESTPORT-2", name)
55}
56
57func TestServiceAliasKVPath(t *testing.T) {
58 serviceKey := ServiceKey{
59 Port: "PORT",
60 STag: "100",
61 CTag: "101",
62 TpId: "64",
63 }
64
65 path := getServiceAliasKVPath(serviceKey)
66
67 assert.Equal(t, "services/PORT/100/101/64", path)
68}