wrapper_test.go 908 B

1234567891011121314151617181920212223242526272829303132
  1. package main
  2. import (
  3. "testing"
  4. C "github.com/sagernet/sing-box/constant"
  5. "github.com/sagernet/sing-box/option"
  6. "github.com/stretchr/testify/require"
  7. )
  8. func TestOptionsWrapper(t *testing.T) {
  9. inbound := option.Inbound{
  10. Type: C.TypeHTTP,
  11. HTTPOptions: option.HTTPMixedInboundOptions{
  12. InboundTLSOptionsContainer: option.InboundTLSOptionsContainer{
  13. TLS: &option.InboundTLSOptions{
  14. Enabled: true,
  15. },
  16. },
  17. },
  18. }
  19. rawOptions, err := inbound.RawOptions()
  20. require.NoError(t, err)
  21. tlsOptionsWrapper, loaded := rawOptions.(option.InboundTLSOptionsWrapper)
  22. require.True(t, loaded, "find inbound tls options")
  23. tlsOptions := tlsOptionsWrapper.TakeInboundTLSOptions()
  24. require.NotNil(t, tlsOptions, "find inbound tls options")
  25. tlsOptions.Enabled = false
  26. tlsOptionsWrapper.ReplaceInboundTLSOptions(tlsOptions)
  27. require.False(t, inbound.HTTPOptions.TLS.Enabled, "replace tls enabled")
  28. }