-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathconfig_test.go
95 lines (84 loc) · 1.95 KB
/
config_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
// SPDX-License-Identifier: Apache-2.0
// Copyright 2022-present Open Networking Foundation
package pfcpiface
import (
"io/fs"
"os"
"testing"
"go.uber.org/zap"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func mustWriteStringToDisk(s string, path string) {
err := os.WriteFile(path, []byte(s), fs.ModePerm)
if err != nil {
panic(err)
}
}
func TestLoadConfigFile(t *testing.T) {
t.Run("sample config is valid", func(t *testing.T) {
s := `{
"mode": "dpdk",
"log_level": "info",
"workers": 1,
"max_sessions": 50000,
"table_sizes": {
"pdrLookup": 50000,
"appQERLookup": 200000,
"sessionQERLookup": 100000,
"farLookup": 150000
},
"access": {
"ifname": "access"
},
"core": {
"ifname": "core"
},
"measure_upf": true,
"measure_flow": true,
"enable_notify_bess": true,
"notify_sockaddr": "/pod-share/notifycp",
"cpiface": {
"dnn": "internet",
"hostname": "upf",
"http_port": "8080"
},
"n6_bps": 1000000000,
"n6_burst_bytes": 12500000,
"n3_bps": 1000000000,
"n3_burst_bytes": 12500000,
"qci_qos_config": [{
"qci": 0,
"cbs": 50000,
"ebs": 50000,
"pbs": 50000,
"burst_duration_ms": 10,
"priority": 7
}]
}`
confPath := t.TempDir() + "/conf.jsonc"
mustWriteStringToDisk(s, confPath)
_, err := LoadConfigFile(confPath)
require.NoError(t, err)
})
t.Run("empty config has log level info", func(t *testing.T) {
s := `{
"mode": "dpdk"
}`
confPath := t.TempDir() + "/conf.jsonc"
mustWriteStringToDisk(s, confPath)
conf, err := LoadConfigFile(confPath)
require.NoError(t, err)
require.Equal(t, conf.LogLevel, zap.InfoLevel)
})
t.Run("all sample configs must be valid", func(t *testing.T) {
paths := []string{
"../conf/upf.jsonc",
"../ptf/config/upf.jsonc",
}
for _, path := range paths {
_, err := LoadConfigFile(path)
assert.NoError(t, err, "config %v is not valid", path)
}
})
}