github.com/inazumav/sing-box@v0.0.0-20230926072359-ab51429a14f1/common/badjsonmerge/merge_test.go (about) 1 package badjsonmerge 2 3 import ( 4 "testing" 5 6 C "github.com/inazumav/sing-box/constant" 7 "github.com/inazumav/sing-box/option" 8 N "github.com/sagernet/sing/common/network" 9 10 "github.com/stretchr/testify/require" 11 ) 12 13 func TestMergeJSON(t *testing.T) { 14 t.Parallel() 15 options := option.Options{ 16 Log: &option.LogOptions{ 17 Level: "info", 18 }, 19 Route: &option.RouteOptions{ 20 Rules: []option.Rule{ 21 { 22 Type: C.RuleTypeDefault, 23 DefaultOptions: option.DefaultRule{ 24 Network: []string{N.NetworkTCP}, 25 Outbound: "direct", 26 }, 27 }, 28 }, 29 }, 30 } 31 anotherOptions := option.Options{ 32 Outbounds: []option.Outbound{ 33 { 34 Type: C.TypeDirect, 35 Tag: "direct", 36 }, 37 }, 38 } 39 thirdOptions := option.Options{ 40 Route: &option.RouteOptions{ 41 Rules: []option.Rule{ 42 { 43 Type: C.RuleTypeDefault, 44 DefaultOptions: option.DefaultRule{ 45 Network: []string{N.NetworkUDP}, 46 Outbound: "direct", 47 }, 48 }, 49 }, 50 }, 51 } 52 mergeOptions, err := MergeOptions(options, anotherOptions) 53 require.NoError(t, err) 54 mergeOptions, err = MergeOptions(thirdOptions, mergeOptions) 55 require.NoError(t, err) 56 require.Equal(t, "info", mergeOptions.Log.Level) 57 require.Equal(t, 2, len(mergeOptions.Route.Rules)) 58 require.Equal(t, C.TypeDirect, mergeOptions.Outbounds[0].Type) 59 }