Adding Unit Test cases for rtmgr
[ric-plt/rtmgr.git] / pkg / sdl / sdl_test.go
1 /*
2 ==================================================================================
3    Copyright (c) 2019 AT&T Intellectual Property.
4    Copyright (c) 2019 Nokia
5
6    Licensed under the Apache License, Version 2.0 (the "License");
7    you may not use this file except in compliance with the License.
8    You may obtain a copy of the License at
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17
18    This source code is part of the near-RT RIC (RAN Intelligent Controller)
19    platform project (RICP).
20
21 ==================================================================================
22 */
23 /*
24         Mnemonic:       sbi_test.go
25         Abstract:
26         Date:           25 April 2019
27 */
28 package sdl
29
30 import (
31         "routing-manager/pkg/stub"
32         "testing"
33 )
34
35 /*
36 RmrPub.GeneratePolicies() method is tested for happy path case
37 */
38 func TestFileWriteAll(t *testing.T) {
39         var err error
40         var file = File{}
41
42         err = file.WriteAll("ut.rt", &stub.ValidRicComponents)
43         t.Log(err)
44         /* This test is for empty file */
45         err = file.WriteAll("", &stub.ValidRicComponents)
46         t.Log(err)
47 }
48
49 /*
50 RmrPush.GeneratePolicies() method is tested for happy path case
51 */
52 func TestFileReadAll(t *testing.T) {
53         var err error
54         var file = File{}
55
56         data, err := file.ReadAll("ut.rt")
57         t.Log(data)
58         t.Log(err)
59         /* Test to read a Directory */
60         data, err = file.ReadAll("/tmp")
61         t.Log(data)
62         t.Log(err)
63 }
64
65 /*
66 WriteXApps
67 */
68 func TestFileWriteXApps(t *testing.T) {
69         var err error
70         var file = File{}
71
72         err = file.WriteXApps("ut.rt", stub.ValidXApps)
73         t.Log(err)
74         /*Write data to a file that doesn't exist */
75         err = file.WriteXApps("ut.rtx", stub.ValidXApps)
76         t.Log(err)
77
78 }
79
80 /*
81 GetSdl instance with correct and incorrect arguments
82 */
83 func TestFileGetSdl(t *testing.T) {
84         var err error
85         _, err = GetSdl("")
86         t.Log(err)
87         _, err = GetSdl("file")
88         t.Log(err)
89 }
90
91 /*
92 WriteNewE2TInstance
93 */
94 func TestWriteNewE2TInstance(t *testing.T) {
95         var err error
96         var file = File{}
97         file.WriteNewE2TInstance("", &stub.ValidE2TInstance)
98         t.Log(err)
99         file.WriteNewE2TInstance("ut.rt", &stub.ValidE2TInstance)
100         t.Log(err)
101 }