x2_reset_response.go was added
[ric-plt/e2mgr.git] / E2Manager / e2pdus / x2_reset_response_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 TestPrepareX2ResetResponsePDU(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 := "200700080000010011400100"
33         packedX2ResetResponse := PackedX2ResetResponse
34
35         tmp := fmt.Sprintf("%x", packedX2ResetResponse)
36         if len(tmp) != len(packedPdu) {
37                 t.Errorf("want packed len:%d, got: %d\n", len(packedPdu)/2, len(packedX2ResetResponse)/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 TestPrepareX2ResetResponsePDUFailure(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  = prepareX2ResetResponsePDU(1, 4096)
52         if err == nil {
53                 t.Errorf("want: error, got: success.\n")
54         }
55
56         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"
57         if !strings.Contains(err.Error(), expected) {
58                 t.Errorf("want :[%s], got: [%s]\n", expected, err)
59         }
60 }