Files
monibuca/pkg/config/config_test.go
2024-07-26 10:21:10 +08:00

55 lines
1.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package config
import (
"testing"
)
// TestModify 测试动态修改配置文件比较值是否修改修改后是否有Modify属性
func TestModify(t *testing.T) {
t.Run(t.Name(), func(t *testing.T) {
var defaultValue struct {
Subscribe
}
defaultValue.SubAudio = false
var conf Config
conf.Parse(&defaultValue)
conf.ParseModifyFile(map[string]any{
"subscribe": map[string]any{
"subaudio": false,
},
})
if conf.Modify != nil {
t.Fail()
}
conf.ParseModifyFile(map[string]any{
"subscribe": map[string]any{
"subaudio": true,
},
})
if conf.Modify == nil {
t.Fail()
}
})
}
// TestGlobal 测试全局配置
func TestGlobal(t *testing.T) {
t.Run(t.Name(), func(t *testing.T) {
var defaultValue struct {
Publish
}
var globalValue struct {
Publish
}
globalValue.Publish.KickExist = true
var conf Config
var globalConf Config
globalConf.Parse(&globalValue)
conf.Parse(&defaultValue)
conf.ParseGlobal(&globalConf)
if defaultValue.Publish.KickExist != true {
t.Fail()
}
})
}