github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/infra/conf/serial/loader_test.go (about) 1 package serial_test 2 3 import ( 4 "bytes" 5 "strings" 6 "testing" 7 8 "v2ray.com/core/infra/conf/serial" 9 ) 10 11 func TestLoaderError(t *testing.T) { 12 testCases := []struct { 13 Input string 14 Output string 15 }{ 16 { 17 Input: `{ 18 "log": { 19 // abcd 20 0, 21 "loglevel": "info" 22 } 23 }`, 24 Output: "line 4 char 6", 25 }, 26 { 27 Input: `{ 28 "log": { 29 // abcd 30 "loglevel": "info", 31 } 32 }`, 33 Output: "line 5 char 5", 34 }, 35 { 36 Input: `{ 37 "port": 1, 38 "inbounds": [{ 39 "protocol": "test" 40 }] 41 }`, 42 Output: "parse json config", 43 }, 44 { 45 Input: `{ 46 "inbounds": [{ 47 "port": 1, 48 "listen": 0, 49 "protocol": "test" 50 }] 51 }`, 52 Output: "line 1 char 1", 53 }, 54 } 55 for _, testCase := range testCases { 56 reader := bytes.NewReader([]byte(testCase.Input)) 57 _, err := serial.LoadJSONConfig(reader) 58 errString := err.Error() 59 if !strings.Contains(errString, testCase.Output) { 60 t.Error("unexpected output from json: ", testCase.Input, ". expected ", testCase.Output, ", but actually ", errString) 61 } 62 } 63 }