1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-10 09:50:43 +00:00
v2fly/infra/conf/general_test.go
young-zy 6d25d51519
Update protobuf version (#527)
Co-authored-by: loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
2020-12-20 10:50:46 +08:00

37 lines
855 B
Go

package conf_test
import (
"encoding/json"
"testing"
"google.golang.org/protobuf/proto"
"v2ray.com/core/common"
. "v2ray.com/core/infra/conf"
)
func loadJSON(creator func() Buildable) func(string) (proto.Message, error) {
return func(s string) (proto.Message, error) {
instance := creator()
if err := json.Unmarshal([]byte(s), instance); err != nil {
return nil, err
}
return instance.Build()
}
}
type TestCase struct {
Input string
Parser func(string) (proto.Message, error)
Output proto.Message
}
func runMultiTestCase(t *testing.T, testCases []TestCase) {
for _, testCase := range testCases {
actual, err := testCase.Parser(testCase.Input)
common.Must(err)
if !proto.Equal(actual, testCase.Output) {
t.Fatalf("Failed in test case:\n%s\nActual:\n%v\nExpected:\n%v", testCase.Input, actual, testCase.Output)
}
}
}