forked from omec-project/amf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
amf_test.go
111 lines (96 loc) · 2.46 KB
/
amf_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// SPDX-FileCopyrightText: 2021 Open Networking Foundation <info@opennetworking.org>
//
// SPDX-License-Identifier: Apache-2.0
//
/*
* AMF Unit Testcases
*
*/
package main
import (
"encoding/json"
"fmt"
"testing"
"time"
"github.com/omec-project/amf/factory"
protos "github.com/omec-project/config5g/proto/sdcoreConfig"
)
//var AMF = &service.AMF{}
func init() {
factory.InitConfigFactory("amfTest/amfcfg.yaml")
}
func GetNetworkSliceConfig() *protos.NetworkSliceResponse {
var rsp protos.NetworkSliceResponse
rsp.NetworkSlice = make([]*protos.NetworkSlice, 0)
ns := protos.NetworkSlice{}
slice := protos.NSSAI{Sst: "1", Sd: "010203"}
ns.Nssai = &slice
site := protos.SiteInfo{SiteName: "siteOne", Gnb: make([]*protos.GNodeB, 0), Plmn: new(protos.PlmnId)}
gNb := protos.GNodeB{Name: "gnb", Tac: 1}
site.Gnb = append(site.Gnb, &gNb)
site.Plmn.Mcc = "208"
site.Plmn.Mnc = "93"
ns.Site = &site
rsp.NetworkSlice = append(rsp.NetworkSlice, &ns)
return &rsp
}
func TestInitialConfig(t *testing.T) {
factory.AmfConfig.Configuration.PlmnSupportList = nil
factory.AmfConfig.Configuration.ServedGumaiList = nil
factory.AmfConfig.Configuration.SupportTAIList = nil
var Rsp chan *protos.NetworkSliceResponse
Rsp = make(chan *protos.NetworkSliceResponse)
go func() {
Rsp <- GetNetworkSliceConfig()
}()
go func() {
AMF.UpdateConfig(Rsp)
}()
time.Sleep(2 * time.Second)
if factory.AmfConfig.Configuration.PlmnSupportList != nil &&
factory.AmfConfig.Configuration.ServedGumaiList != nil &&
factory.AmfConfig.Configuration.SupportTAIList != nil {
fmt.Printf("test passed")
} else {
t.Errorf("test failed")
}
}
// data in JSON format which
// is to be decoded
var Data = []byte(`{
"NetworkSlice": [
{
"Name": "siteOne",
"Nssai": {"Sst": "1", "Sd": "010203"},
"Site": {
"SiteName": "siteOne",
"Gnb": [
{"Name": "gnb1", "Tac": 1},
{"Name": "gnb2", "Tac": 2}
],
"Plmn": {"mcc": "208", "mnc": "93"}
}
}
]}`)
func TestUpdateConfig(t *testing.T) {
var nrp protos.NetworkSliceResponse
err := json.Unmarshal(Data, &nrp)
if err != nil {
panic(err)
}
var Rsp chan *protos.NetworkSliceResponse
Rsp = make(chan *protos.NetworkSliceResponse)
go func() {
Rsp <- &nrp
}()
go func() {
AMF.UpdateConfig(Rsp)
}()
time.Sleep(2 * time.Second)
if factory.AmfConfig.Configuration.SupportTAIList != nil &&
len(factory.AmfConfig.Configuration.SupportTAIList) == 2 {
fmt.Printf("test passed")
} else {
t.Errorf("test failed")
}
}