manager_test.go 995 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package policy_test
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. . "github.com/xtls/xray-core/app/policy"
  7. "github.com/xtls/xray-core/common"
  8. "github.com/xtls/xray-core/features/policy"
  9. )
  10. func TestPolicy(t *testing.T) {
  11. manager, err := New(context.Background(), &Config{
  12. Level: map[uint32]*Policy{
  13. 0: {
  14. Timeout: &Policy_Timeout{
  15. Handshake: &Second{
  16. Value: 2,
  17. },
  18. },
  19. },
  20. },
  21. })
  22. common.Must(err)
  23. pDefault := policy.SessionDefault()
  24. {
  25. p := manager.ForLevel(0)
  26. if p.Timeouts.Handshake != 2*time.Second {
  27. t.Error("expect 2 sec timeout, but got ", p.Timeouts.Handshake)
  28. }
  29. if p.Timeouts.ConnectionIdle != pDefault.Timeouts.ConnectionIdle {
  30. t.Error("expect ", pDefault.Timeouts.ConnectionIdle, " sec timeout, but got ", p.Timeouts.ConnectionIdle)
  31. }
  32. }
  33. {
  34. p := manager.ForLevel(1)
  35. if p.Timeouts.Handshake != pDefault.Timeouts.Handshake {
  36. t.Error("expect ", pDefault.Timeouts.Handshake, " sec timeout, but got ", p.Timeouts.Handshake)
  37. }
  38. }
  39. }