mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-05-01 01:44:15 +00:00
v1.0.0
This commit is contained in:
parent
47d23e9972
commit
c7f7c08ead
711 changed files with 82154 additions and 2 deletions
63
infra/conf/serial/loader_test.go
Normal file
63
infra/conf/serial/loader_test.go
Normal file
|
@ -0,0 +1,63 @@
|
|||
package serial_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/xtls/xray-core/v1/infra/conf/serial"
|
||||
)
|
||||
|
||||
func TestLoaderError(t *testing.T) {
|
||||
testCases := []struct {
|
||||
Input string
|
||||
Output string
|
||||
}{
|
||||
{
|
||||
Input: `{
|
||||
"log": {
|
||||
// abcd
|
||||
0,
|
||||
"loglevel": "info"
|
||||
}
|
||||
}`,
|
||||
Output: "line 4 char 6",
|
||||
},
|
||||
{
|
||||
Input: `{
|
||||
"log": {
|
||||
// abcd
|
||||
"loglevel": "info",
|
||||
}
|
||||
}`,
|
||||
Output: "line 5 char 5",
|
||||
},
|
||||
{
|
||||
Input: `{
|
||||
"port": 1,
|
||||
"inbounds": [{
|
||||
"protocol": "test"
|
||||
}]
|
||||
}`,
|
||||
Output: "parse json config",
|
||||
},
|
||||
{
|
||||
Input: `{
|
||||
"inbounds": [{
|
||||
"port": 1,
|
||||
"listen": 0,
|
||||
"protocol": "test"
|
||||
}]
|
||||
}`,
|
||||
Output: "line 1 char 1",
|
||||
},
|
||||
}
|
||||
for _, testCase := range testCases {
|
||||
reader := bytes.NewReader([]byte(testCase.Input))
|
||||
_, err := serial.LoadJSONConfig(reader)
|
||||
errString := err.Error()
|
||||
if !strings.Contains(errString, testCase.Output) {
|
||||
t.Error("unexpected output from json: ", testCase.Input, ". expected ", testCase.Output, ", but actually ", errString)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue