mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-30 05:56:54 -05:00
Test case for config cache.
This commit is contained in:
parent
46c0d457d9
commit
3765826602
@ -7,7 +7,7 @@ import (
|
||||
type ConfigObjectCreator func() interface{}
|
||||
|
||||
var (
|
||||
configCache = make(map[string]ConfigObjectCreator)
|
||||
configCache map[string]ConfigObjectCreator
|
||||
)
|
||||
|
||||
func getConfigKey(protocol string, cType config.Type) string {
|
||||
@ -35,3 +35,11 @@ func CreateConfig(protocol string, cType config.Type) interface{} {
|
||||
}
|
||||
return creator()
|
||||
}
|
||||
|
||||
func initializeConfigCache() {
|
||||
configCache = make(map[string]ConfigObjectCreator)
|
||||
}
|
||||
|
||||
func init() {
|
||||
initializeConfigCache()
|
||||
}
|
||||
|
46
proxy/common/config/json/config_cache_test.go
Normal file
46
proxy/common/config/json/config_cache_test.go
Normal file
@ -0,0 +1,46 @@
|
||||
package json
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/v2ray/v2ray-core/proxy/common/config"
|
||||
"github.com/v2ray/v2ray-core/testing/unit"
|
||||
)
|
||||
|
||||
func TestRegisterInboundConfig(t *testing.T) {
|
||||
assert := unit.Assert(t)
|
||||
initializeConfigCache()
|
||||
|
||||
protocol := "test_protocol"
|
||||
creator := func() interface{} {
|
||||
return true
|
||||
}
|
||||
|
||||
err := RegisterInboundConnectionConfig(protocol, creator)
|
||||
assert.Error(err).IsNil()
|
||||
|
||||
configObj := CreateConfig(protocol, config.TypeInbound)
|
||||
assert.Bool(configObj.(bool)).IsTrue()
|
||||
|
||||
configObj = CreateConfig(protocol, config.TypeOutbound)
|
||||
assert.Pointer(configObj).IsNil()
|
||||
}
|
||||
|
||||
func TestRegisterOutboundConfig(t *testing.T) {
|
||||
assert := unit.Assert(t)
|
||||
initializeConfigCache()
|
||||
|
||||
protocol := "test_protocol"
|
||||
creator := func() interface{} {
|
||||
return true
|
||||
}
|
||||
|
||||
err := RegisterOutboundConnectionConfig(protocol, creator)
|
||||
assert.Error(err).IsNil()
|
||||
|
||||
configObj := CreateConfig(protocol, config.TypeOutbound)
|
||||
assert.Bool(configObj.(bool)).IsTrue()
|
||||
|
||||
configObj = CreateConfig(protocol, config.TypeInbound)
|
||||
assert.Pointer(configObj).IsNil()
|
||||
}
|
Loading…
Reference in New Issue
Block a user