mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 17:38:41 +00:00
v1.0.0
This commit is contained in:
parent
47d23e9972
commit
c7f7c08ead
711 changed files with 82154 additions and 2 deletions
36
infra/conf/general_test.go
Normal file
36
infra/conf/general_test.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
package conf_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/xtls/xray-core/v1/common"
|
||||
. "github.com/xtls/xray-core/v1/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)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue