sync R3 content from Azure
[ric-plt/e2mgr.git] / E2Manager / e2pdus / configuration_update_test.go
1 /*******************************************************************************
2  *
3  *   Copyright (c) 2019 AT&T Intellectual Property.
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  *******************************************************************************/
18 package e2pdus
19
20 import (
21         "e2mgr/logger"
22         "fmt"
23         "strings"
24         "testing"
25 )
26
27 func TestPrepareEndcConfigurationUpdateFailurePDU(t *testing.T) {
28         _,err := logger.InitLogger(logger.InfoLevel)
29         if err!=nil{
30                 t.Errorf("failed to initialize logger, error: %s", err)
31         }
32         packedPdu := "402500080000010005400142"
33         packedEndcConfigurationUpdateFailure := PackedEndcConfigurationUpdateFailure
34
35         tmp := fmt.Sprintf("%x", packedEndcConfigurationUpdateFailure)
36         if len(tmp) != len(packedPdu) {
37                 t.Errorf("want packed len:%d, got: %d\n", len(packedPdu)/2, len(packedEndcConfigurationUpdateFailure)/2)
38         }
39
40         if strings.Compare(tmp, packedPdu) != 0 {
41                 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", packedPdu, tmp)
42         }
43 }
44
45 func TestPrepareEndcConfigurationUpdateFailurePDUFailure(t *testing.T) {
46         _, err := logger.InitLogger(logger.InfoLevel)
47         if err != nil {
48                 t.Errorf("failed to initialize logger, error: %s", err)
49         }
50
51         err  = prepareEndcConfigurationUpdateFailurePDU(1, 4096)
52         if err == nil {
53                 t.Errorf("want: error, got: success.\n")
54         }
55
56         expected:= "#configuration_update.prepareEndcConfigurationUpdateFailurePDU - failed to build and pack the endc configuration update failure message #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big"
57         if !strings.Contains(err.Error(), expected) {
58                 t.Errorf("want :[%s], got: [%s]\n", expected, err)
59         }
60 }
61
62 func TestPrepareX2EnbConfigurationUpdateFailurePDU(t *testing.T) {
63         _,err := logger.InitLogger(logger.InfoLevel)
64         if err!=nil{
65                 t.Errorf("failed to initialize logger, error: %s", err)
66         }
67         packedPdu := "400800080000010005400142"
68         packedEndcX2ConfigurationUpdateFailure := PackedX2EnbConfigurationUpdateFailure
69
70         tmp := fmt.Sprintf("%x", packedEndcX2ConfigurationUpdateFailure)
71         if len(tmp) != len(packedPdu) {
72                 t.Errorf("want packed len:%d, got: %d\n", len(packedPdu)/2, len(packedEndcX2ConfigurationUpdateFailure)/2)
73         }
74
75         if strings.Compare(tmp, packedPdu) != 0 {
76                 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", packedPdu, tmp)
77         }
78 }
79
80 func TestPrepareX2EnbConfigurationUpdateFailurePDUFailure(t *testing.T) {
81         _, err := logger.InitLogger(logger.InfoLevel)
82         if err != nil {
83                 t.Errorf("failed to initialize logger, error: %s", err)
84         }
85
86         err  = prepareX2EnbConfigurationUpdateFailurePDU(1, 4096)
87         if err == nil {
88                 t.Errorf("want: error, got: success.\n")
89         }
90
91         expected:= "#configuration_update.prepareX2EnbConfigurationUpdateFailurePDU - failed to build and pack the x2 configuration update failure message #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big"
92         if !strings.Contains(err.Error(), expected) {
93                 t.Errorf("want :[%s], got: [%s]\n", expected, err)
94         }
95 }
96
97 func TestPrepareEndcConfigurationUpdateAckPDU(t *testing.T) {
98         _,err := logger.InitLogger(logger.InfoLevel)
99         if err!=nil{
100                 t.Errorf("failed to initialize logger, error: %s", err)
101         }
102         packedPdu := "2025000a00000100f70003000000"
103         packedEndcConfigurationUpdateAck := PackedEndcConfigurationUpdateAck
104
105         tmp := fmt.Sprintf("%x", packedEndcConfigurationUpdateAck)
106         if len(tmp) != len(packedPdu) {
107                 t.Errorf("want packed len:%d, got: %d\n", len(packedPdu)/2, len(packedEndcConfigurationUpdateAck)/2)
108         }
109
110         if strings.Compare(tmp, packedPdu) != 0 {
111                 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", packedPdu, tmp)
112         }
113 }
114
115 func TestPrepareEndcConfigurationUpdateAckPDUFailure(t *testing.T) {
116         _, err := logger.InitLogger(logger.InfoLevel)
117         if err != nil {
118                 t.Errorf("failed to initialize logger, error: %s", err)
119         }
120
121         err  = prepareEndcConfigurationUpdateAckPDU(1, 4096)
122         if err == nil {
123                 t.Errorf("want: error, got: success.\n")
124         }
125
126         expected:= "#configuration_update.prepareEndcConfigurationUpdateAckPDU - failed to build and pack the endc configuration update ack message #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big"
127         if !strings.Contains(err.Error(), expected) {
128                 t.Errorf("want :[%s], got: [%s]\n", expected, err)
129         }
130 }
131
132 func TestPrepareX2EnbConfigurationUpdateAckPDU(t *testing.T) {
133         _,err := logger.InitLogger(logger.InfoLevel)
134         if err!=nil{
135                 t.Errorf("failed to initialize logger, error: %s", err)
136         }
137         packedPdu := "200800080000010011400100"
138         packedEndcX2ConfigurationUpdateAck := PackedX2EnbConfigurationUpdateAck
139
140         tmp := fmt.Sprintf("%x", packedEndcX2ConfigurationUpdateAck)
141         if len(tmp) != len(packedPdu) {
142                 t.Errorf("want packed len:%d, got: %d\n", len(packedPdu)/2, len(packedEndcX2ConfigurationUpdateAck)/2)
143         }
144
145         if strings.Compare(tmp, packedPdu) != 0 {
146                 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", packedPdu, tmp)
147         }
148 }
149
150 func TestPrepareX2EnbConfigurationUpdateAckPDUFailure(t *testing.T) {
151         _, err := logger.InitLogger(logger.InfoLevel)
152         if err != nil {
153                 t.Errorf("failed to initialize logger, error: %s", err)
154         }
155
156         err  = prepareX2EnbConfigurationUpdateAckPDU(1, 4096)
157         if err == nil {
158                 t.Errorf("want: error, got: success.\n")
159         }
160
161         expected:= "#configuration_update.prepareX2EnbConfigurationUpdateAckPDU - failed to build and pack the x2 configuration update ack message #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big"
162         if !strings.Contains(err.Error(), expected) {
163                 t.Errorf("want :[%s], got: [%s]\n", expected, err)
164         }
165 }