2019-02-10 13:04:11 -05:00
|
|
|
package serial_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2021-02-16 15:31:50 -05:00
|
|
|
"github.com/v2fly/v2ray-core/v4/infra/conf/serial"
|
2019-02-10 13:04:11 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|