config_cache_test.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 := CreateInboundConfig(protocol, nil)
  17. assert.Bool(configObj.(bool)).IsTrue()
  18. assert.Error(err).IsNil()
  19. configObj, err = CreateOutboundConfig(protocol, nil)
  20. assert.Error(err).IsNotNil()
  21. assert.Pointer(configObj).IsNil()
  22. }
  23. func TestRegisterOutboundConfig(t *testing.T) {
  24. v2testing.Current(t)
  25. initializeConfigCache()
  26. protocol := "test_protocol"
  27. creator := func([]byte) (interface{}, error) {
  28. return true, nil
  29. }
  30. err := RegisterOutboundConfig(protocol, creator)
  31. assert.Error(err).IsNil()
  32. configObj, err := CreateOutboundConfig(protocol, nil)
  33. assert.Bool(configObj.(bool)).IsTrue()
  34. assert.Error(err).IsNil()
  35. configObj, err = CreateInboundConfig(protocol, nil)
  36. assert.Error(err).IsNotNil()
  37. assert.Pointer(configObj).IsNil()
  38. }