Merge "Getting node for which e2 reset has to be applied"
[ric-plt/e2mgr.git] / E2Manager / e2pdus / x2_reset_response_test.go
1 /*
2  *   Copyright (c) 2019 AT&T Intellectual Property.
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 /*
18  * This source code is part of the near-RT RIC (RAN Intelligent Controller)
19  * platform project (RICP).
20  */
21
22 package e2pdus
23
24 import (
25         "e2mgr/logger"
26         "fmt"
27         "strings"
28         "testing"
29 )
30
31 func TestPrepareX2ResetResponsePDU(t *testing.T) {
32         InfoLevel := int8(3)
33         _,err := logger.InitLogger(InfoLevel)
34         if err!=nil{
35                 t.Errorf("failed to initialize logger, error: %s", err)
36         }
37         packedPdu := "200700080000010011400100"
38         packedX2ResetResponse := PackedX2ResetResponse
39
40         tmp := fmt.Sprintf("%x", packedX2ResetResponse)
41         if len(tmp) != len(packedPdu) {
42                 t.Errorf("want packed len:%d, got: %d\n", len(packedPdu)/2, len(packedX2ResetResponse)/2)
43         }
44
45         if strings.Compare(tmp, packedPdu) != 0 {
46                 t.Errorf("\nwant :\t[%s]\n got: \t\t[%s]\n", packedPdu, tmp)
47         }
48 }
49
50 func TestPrepareX2ResetResponsePDUFailure(t *testing.T) {
51         InfoLevel:= int8(3)
52         _, err := logger.InitLogger(InfoLevel)
53         if err != nil {
54                 t.Errorf("failed to initialize logger, error: %s", err)
55         }
56
57         err  = prepareX2ResetResponsePDU(1, 4096)
58         if err == nil {
59                 t.Errorf("want: error, got: success.\n")
60         }
61
62         expected:= "#x2_reset_response.prepareX2ResetResponsePDU - failed to build and pack the reset response message #src/asn1codec_utils.c.pack_pdu_aux - Encoded output of E2AP-PDU, is too big"
63         if !strings.Contains(err.Error(), expected) {
64                 t.Errorf("want :[%s], got: [%s]\n", expected, err)
65         }
66 }