config_cache_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package config
  2. import (
  3. "testing"
  4. v2testing "github.com/v2ray/v2ray-core/testing"
  5. "github.com/v2ray/v2ray-core/testing/assert"
  6. )
  7. func TestRegisterInboundConfig(t *testing.T) {
  8. v2testing.Current(t)
  9. initializeConfigCache()
  10. protocol := "test_protocol"
  11. creator := func([]byte) (interface{}, error) {
  12. return true, nil
  13. }
  14. err := RegisterInboundConfig(protocol, creator)
  15. assert.Error(err).IsNil()
  16. configObj, err := CreateInboundConnectionConfig(protocol, nil)
  17. assert.Bool(configObj.(bool)).IsTrue()
  18. assert.Error(err).IsNil()
  19. configObj, err = CreateOutboundConnectionConfig(protocol, nil)
  20. assert.Pointer(configObj).IsNil()
  21. }
  22. func TestRegisterOutboundConfig(t *testing.T) {
  23. v2testing.Current(t)
  24. initializeConfigCache()
  25. protocol := "test_protocol"
  26. creator := func([]byte) (interface{}, error) {
  27. return true, nil
  28. }
  29. err := RegisterOutboundConfig(protocol, creator)
  30. assert.Error(err).IsNil()
  31. configObj, err := CreateOutboundConnectionConfig(protocol, nil)
  32. assert.Bool(configObj.(bool)).IsTrue()
  33. assert.Error(err).IsNil()
  34. configObj, err = CreateInboundConnectionConfig(protocol, nil)
  35. assert.Pointer(configObj).IsNil()
  36. }