github.com/v2fly/v2ray-core/v4@v4.45.2/infra/conf/general_test.go (about) 1 package conf_test 2 3 import ( 4 "encoding/json" 5 "testing" 6 7 "github.com/golang/protobuf/proto" 8 9 "github.com/v2fly/v2ray-core/v4/common" 10 . "github.com/v2fly/v2ray-core/v4/infra/conf" 11 ) 12 13 func loadJSON(creator func() Buildable) func(string) (proto.Message, error) { 14 return func(s string) (proto.Message, error) { 15 instance := creator() 16 if err := json.Unmarshal([]byte(s), instance); err != nil { 17 return nil, err 18 } 19 return instance.Build() 20 } 21 } 22 23 type TestCase struct { 24 Input string 25 Parser func(string) (proto.Message, error) 26 Output proto.Message 27 } 28 29 func runMultiTestCase(t *testing.T, testCases []TestCase) { 30 for _, testCase := range testCases { 31 actual, err := testCase.Parser(testCase.Input) 32 common.Must(err) 33 if !proto.Equal(actual, testCase.Output) { 34 t.Fatalf("Failed in test case:\n%s\nActual:\n%v\nExpected:\n%v", testCase.Input, actual, testCase.Output) 35 } 36 } 37 }