forked from omec-project/amf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
amf_test.go
155 lines (137 loc) · 4.22 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// SPDX-FileCopyrightText: 2021 Open Networking Foundation <[email protected]>
//
// SPDX-License-Identifier: Apache-2.0
//
/*
* AMF Unit Testcases
*
*/
package main
import (
"encoding/json"
"fmt"
"os"
"testing"
"time"
"github.com/omec-project/amf/consumer"
"github.com/omec-project/amf/factory"
"github.com/omec-project/amf/service"
protos "github.com/omec-project/config5g/proto/sdcoreConfig"
"github.com/omec-project/openapi/models"
"github.com/stretchr/testify/require"
)
var AMFTest = &service.AMF{}
func init() {
if err := os.Setenv("POD_IP", "127.0.0.1"); err != nil {
fmt.Printf("Could not set env POD_IP: %+v\n", err)
}
if err := factory.InitConfigFactory("amfTest/amfcfg.yaml"); err != nil {
fmt.Printf("Could not InitConfigFactory: %+v\n", err)
}
}
func GetNetworkSliceConfig() *protos.NetworkSliceResponse {
var rsp protos.NetworkSliceResponse
rsp.NetworkSlice = make([]*protos.NetworkSlice, 0)
ns := protos.NetworkSlice{}
ns.OperationType = protos.OpType_SLICE_ADD
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
Rsp := make(chan *protos.NetworkSliceResponse, 1)
go func() {
AMFTest.UpdateConfig(Rsp)
}()
Rsp <- GetNetworkSliceConfig()
time.Sleep(2 * time.Second)
close(Rsp)
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)
}
Rsp := make(chan *protos.NetworkSliceResponse)
go func() {
Rsp <- &nrp
}()
go func() {
AMFTest.UpdateConfig(Rsp)
}()
time.Sleep(2 * time.Second)
if len(factory.AmfConfig.Configuration.SupportTAIList) == 2 {
fmt.Printf("test passed")
} else {
t.Errorf("test failed")
}
}
func TestRegisterNF(t *testing.T) {
// Save current function and restore at the end:
origRegisterNFInstance := consumer.SendRegisterNFInstance
// origSearchNFInstances := consumer.SendSearchNFInstances
origUpdateNFInstance := consumer.SendUpdateNFInstance
defer func() {
consumer.SendRegisterNFInstance = origRegisterNFInstance
// consumer.SendSearchNFInstances = origSearchNFInstances
consumer.SendUpdateNFInstance = origUpdateNFInstance
}()
fmt.Printf("test case TestRegisterNF \n")
var prof models.NfProfile
consumer.SendRegisterNFInstance = func(nrfUri string, nfInstanceId string, profile models.NfProfile) (models.NfProfile, string, string, error) {
prof = profile
prof.HeartBeatTimer = 1
fmt.Printf("Test RegisterNFInstance called\n")
return prof, "", "", nil
}
/*consumer.SendSearchNFInstances = func(nrfUri string, targetNfType, requestNfType models.NfType, param Nnrf_NFDiscovery.SearchNFInstancesParamOpts) (*models.SearchResult, error) {
fmt.Printf("Test SearchNFInstance called\n")
return &models.SearchResult{}, nil
}*/
consumer.SendUpdateNFInstance = func(patchItem []models.PatchItem) (nfProfile models.NfProfile, problemDetails *models.ProblemDetails, err error) {
return prof, nil, nil
}
go AMFTest.SendNFProfileUpdateToNrf()
service.RocUpdateConfigChannel <- true
time.Sleep(5 * time.Second)
require.Equal(t, service.KeepAliveTimer != nil, true)
/*service.RocUpdateConfigChannel <- false
time.Sleep(1 * time.Second)
require.Equal(t, service.KeepAliveTimer == nil, true)
*/
}