[RICPLT-1783] Add ValidateAndBuildRanLoadInformationKey | Fix dependencies | Reformat...
[ric-plt/nodeb-rnib.git] / common / utils_test.go
1 //
2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //      http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16
17 package common
18
19 import (
20         "github.com/stretchr/testify/assert"
21         "testing"
22 )
23
24 func TestValidateAndBuildCellKeySuccess(t *testing.T) {
25         cellId := "aaaa"
26         prefix := "CELL"
27         delimiter := ":"
28         key, err := ValidateAndBuildCellIdKey(cellId)
29         if err != nil{
30                 t.Errorf("#utils_test.TestValidateAndBuildCellKey - failed to validate key parameter")
31         }
32         assert.Contains(t, key, cellId)
33         assert.Contains(t, key, delimiter)
34         assert.Contains(t, key, prefix)
35 }
36
37 func TestValidateAndBuildNodeBNameKeySuccess(t *testing.T) {
38         name := "name"
39         prefix := "RAN"
40         delimiter := ":"
41         key, err := ValidateAndBuildNodeBNameKey(name)
42         if err != nil{
43                 t.Errorf("#utils_test.TestValidateAndBuildNodeBNameKey - failed to validate key parameter")
44         }
45         assert.Contains(t, key, name)
46         assert.Contains(t, key, delimiter)
47         assert.Contains(t, key, prefix)
48 }
49
50 func TestValidateAndBuildNodeBIdKeySuccess(t *testing.T) {
51         nodeType := "ENB"
52         plmnId := "bbbb"
53         nbId := "cccc"
54         delimiter := ":"
55         key, err := ValidateAndBuildNodeBIdKey(nodeType, plmnId, nbId)
56         if err != nil{
57                 t.Errorf("#utils_test.TestValidateAndBuildNodeBIdKey - failed to validate key parameter")
58         }
59         assert.Contains(t, key, nodeType)
60         assert.Contains(t, key, plmnId)
61         assert.Contains(t, key, nbId)
62         assert.Contains(t, key, delimiter)
63 }
64
65 func TestValidateAndBuildCellNamePciKeyNameValidationFailure(t *testing.T){
66         pci := 9999
67         _, err := ValidateAndBuildCellNamePciKey("", uint32(pci))
68         assert.NotNil(t, err)
69         assert.Equal(t, VALIDATION_ERROR, err.GetCode())
70         assert.Equal(t, "3 VALIDATION_ERROR - #utils.ValidateAndBuildCellNamePciKey - an empty inventory name received", err.Error())
71 }
72
73 func TestValidateAndBuildCellKeyCellidValidationFailure(t *testing.T) {
74         _, err := ValidateAndBuildCellIdKey("")
75         assert.NotNil(t, err)
76         assert.Equal(t, VALIDATION_ERROR, err.GetCode())
77         assert.Equal(t, "3 VALIDATION_ERROR - #utils.ValidateAndBuildCellIdKey - an empty cell id received", err.Error())
78 }
79
80 func TestValidateAndBuildNodeBNameKeyNameValidationFailure(t *testing.T) {
81         _, err := ValidateAndBuildNodeBNameKey("")
82         assert.NotNil(t, err)
83         assert.Equal(t, VALIDATION_ERROR, err.GetCode())
84         assert.Equal(t, "3 VALIDATION_ERROR - #utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", err.Error())
85 }
86
87 func TestValidateAndBuildNodeBIdKeyNodeTypeValidationFailure(t *testing.T) {
88         plmnId := "dddd"
89         nbId := "eeee"
90         _, err := ValidateAndBuildNodeBIdKey("", plmnId, nbId)
91         assert.NotNil(t, err)
92         assert.Equal(t, VALIDATION_ERROR, err.GetCode())
93         assert.Equal(t, "3 VALIDATION_ERROR - #utils.ValidateAndBuildNodeBIdKey - an empty node type received", err.Error())
94 }
95
96 func TestValidateAndBuildNodeBIdKeyPlmnIdValidationFailure(t *testing.T) {
97         nodeType := "ffff"
98         nbId := "aaaa"
99         _, err := ValidateAndBuildNodeBIdKey(nodeType, "", nbId)
100         assert.NotNil(t, err)
101         assert.Equal(t, VALIDATION_ERROR, err.GetCode())
102         assert.Equal(t, "3 VALIDATION_ERROR - #utils.ValidateAndBuildNodeBIdKey - an empty plmnId received", err.Error())
103 }
104
105 func TestValidateAndBuildNodeBIdKeyNbIdValidationFailure(t *testing.T) {
106         nodeType := "bbbb"
107         plmnId := "cccc"
108         _, err := ValidateAndBuildNodeBIdKey(nodeType, plmnId, "")
109         assert.NotNil(t, err)
110         assert.Equal(t, VALIDATION_ERROR, err.GetCode())
111         assert.Equal(t, "3 VALIDATION_ERROR - #utils.ValidateAndBuildNodeBIdKey - an empty nbId received", err.Error())
112 }
113
114 func TestValidateAndBuildCellNamePciKeySuccess(t *testing.T){
115         name := "name"
116         prefix := "PCI"
117         pci := 9999
118         delimiter := ":"
119         key, err := ValidateAndBuildCellNamePciKey(name, uint32(pci))
120         if err != nil{
121                 t.Errorf("#utils_test.TestValidateAndBuildCellNamePciKey - failed to validate key parameter")
122         }
123         assert.Contains(t, key, name)
124         assert.Contains(t, key, delimiter)
125         assert.Contains(t, key, prefix)
126         assert.Contains(t, key, "270f")
127 }
128
129
130 func TestValidateAndBuildRanLoadInformationKeySuccess(t *testing.T) {
131         name := "name"
132         prefix := "LOAD"
133         delimiter := ":"
134         key, err := ValidateAndBuildRanLoadInformationKey(name)
135         if err != nil{
136                 t.Errorf("#utils_test.TestValidateAndBuildRanLoadInformationKeySuccess - failed to validate key parameter")
137         }
138         assert.Contains(t, key, name)
139         assert.Contains(t, key, delimiter)
140         assert.Contains(t, key, prefix)
141 }
142
143 func TestValidateAndBuildRanLoadInformationKeyFailure(t *testing.T) {
144         name := ""
145         _, err := ValidateAndBuildRanLoadInformationKey(name)
146         assert.NotNil(t, err)
147         assert.Equal(t, VALIDATION_ERROR, err.GetCode())
148 }