e2managererrors - err removed
[ric-plt/e2mgr.git] / E2Manager / e2pdus / x2_reset_known_causes_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 TestKnownCausesToX2ResetPDU(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         var testCases = []struct {
33                 cause     string
34                 packedPdu string
35         }{
36                 {
37                         cause:     OmInterventionCause,
38                         packedPdu: "000700080000010005400164",
39                 },
40                 {
41                         cause:     "PROTOCOL:transfer-syntax-error",
42                         packedPdu: "000700080000010005400140",
43                 },
44                 {
45                         cause:     "transport:transport-RESOURCE-unavailable",
46                         packedPdu: "000700080000010005400120",
47                 },
48
49                 {
50                         cause:     "radioNetwork:invalid-MME-groupid",
51                         packedPdu: "00070009000001000540020680",
52                 },
53         }
54
55         for _, tc := range testCases {
56                 t.Run(tc.packedPdu, func(t *testing.T) {
57
58                         payload, ok := KnownCausesToX2ResetPDU(tc.cause)
59                         if !ok {
60                                 t.Errorf("want: success, got: not found.\n")
61                         } else {
62                                 tmp := fmt.Sprintf("%x", payload)
63                                 if len(tmp) != len(tc.packedPdu) {
64                                         t.Errorf("want packed len:%d, got: %d\n", len(tc.packedPdu)/2, len(payload)/2)
65                                 }
66
67                                 if strings.Compare(tmp, tc.packedPdu) != 0 {
68                                         t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", tc.packedPdu, tmp)
69                                 }
70                         }
71                 })
72         }
73 }
74
75 func TestKnownCausesToX2ResetPDUFailure(t *testing.T) {
76         _, err := logger.InitLogger(logger.InfoLevel)
77         if err != nil {
78                 t.Errorf("failed to initialize logger, error: %s", err)
79         }
80
81         _, ok := KnownCausesToX2ResetPDU("xxxx")
82         if ok {
83                 t.Errorf("want: not found, got: success.\n")
84         }
85 }
86
87 func TestPrepareX2ResetPDUsFailure(t *testing.T) {
88         _, err := logger.InitLogger(logger.InfoLevel)
89         if err != nil {
90                 t.Errorf("failed to initialize logger, error: %s", err)
91         }
92
93         err = prepareX2ResetPDUs(1, 4096)
94         if err == nil {
95                 t.Errorf("want: error, got: success.\n")
96         }
97
98         expected := "#x2_reset_known_causes.prepareX2ResetPDUs - failed to build and pack the reset message #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big:"
99         if !strings.Contains(err.Error(), expected) {
100                 t.Errorf("want :[%s], got: [%s]\n", expected, err)
101         }
102 }