merge_test.go 1.3 KB

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