mirror of https://github.com/rocboss/paopao-ce
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
2.8 KiB
115 lines
2.8 KiB
2 years ago
|
package cfg
|
||
3 years ago
|
|
||
|
import (
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestUseDefault(t *testing.T) {
|
||
|
suites := map[string][]string{
|
||
|
"default": {"Sms", "Alipay", "Zinc", "MySQL", "Redis", "AliOSS", "LogZinc"},
|
||
|
"develop": {"Zinc", "MySQL", "AliOSS", "LogFile"},
|
||
|
"slim": {"Zinc", "MySQL", "Redis", "AliOSS", "LogFile"},
|
||
|
}
|
||
|
kv := map[string]string{
|
||
|
"sms": "SmsJuhe",
|
||
|
}
|
||
2 years ago
|
f := NewFeatures(suites, kv)
|
||
3 years ago
|
for _, data := range []struct {
|
||
|
key string
|
||
|
expect string
|
||
|
exist bool
|
||
|
}{
|
||
|
{"Sms", "SmsJuhe", true},
|
||
|
{"Alipay", "", true},
|
||
|
{"Zinc", "", true},
|
||
|
{"Redis", "", true},
|
||
|
{"Database", "", false},
|
||
|
} {
|
||
2 years ago
|
if v, ok := f.Cfg(data.key); ok != data.exist || v != data.expect {
|
||
3 years ago
|
t.Errorf("key: %s expect: %s exist: %t got v: %s ok: %t", data.key, data.expect, data.exist, v, ok)
|
||
|
}
|
||
|
}
|
||
|
for exp, res := range map[string]bool{
|
||
|
"Sms": true,
|
||
|
"Sms = SmsJuhe": true,
|
||
|
"SmsJuhe": false,
|
||
3 years ago
|
"default": true,
|
||
|
} {
|
||
2 years ago
|
if ok := f.CfgIf(exp); res != ok {
|
||
3 years ago
|
t.Errorf("CfgIf(%s) want %t got %t", exp, res, ok)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestUse(t *testing.T) {
|
||
|
suites := map[string][]string{
|
||
|
"default": {"Sms", "Alipay", "Zinc", "MySQL", "Redis", "AliOSS", "LogZinc"},
|
||
|
"develop": {"Zinc", "MySQL", "AliOSS", "LogFile"},
|
||
|
"slim": {"Zinc", "MySQL", "Redis", "AliOSS", "LogFile"},
|
||
|
}
|
||
|
kv := map[string]string{
|
||
|
"sms": "SmsJuhe",
|
||
|
}
|
||
2 years ago
|
f := NewFeatures(suites, kv)
|
||
3 years ago
|
|
||
2 years ago
|
f.Use([]string{"develop"}, true)
|
||
3 years ago
|
for _, data := range []struct {
|
||
|
key string
|
||
|
expect string
|
||
|
exist bool
|
||
|
}{
|
||
|
{"Sms", "", false},
|
||
|
{"Alipay", "", false},
|
||
|
{"Zinc", "", true},
|
||
|
{"Redis", "", false},
|
||
|
{"Database", "", false},
|
||
|
} {
|
||
2 years ago
|
if v, ok := f.Cfg(data.key); ok != data.exist || v != data.expect {
|
||
3 years ago
|
t.Errorf("key: %s expect: %s exist: %t got v: %s ok: %t", data.key, data.expect, data.exist, v, ok)
|
||
|
}
|
||
|
}
|
||
|
for exp, res := range map[string]bool{
|
||
|
"Sms": false,
|
||
|
"Sms = SmsJuhe": false,
|
||
|
"SmsJuhe": false,
|
||
|
"default": false,
|
||
|
"develop": true,
|
||
|
} {
|
||
2 years ago
|
if ok := f.CfgIf(exp); res != ok {
|
||
3 years ago
|
t.Errorf("CfgIf(%s) want %t got %t", exp, res, ok)
|
||
|
}
|
||
|
}
|
||
|
|
||
2 years ago
|
f.UseDefault()
|
||
|
f.Use([]string{"slim", "", "demo"}, false)
|
||
3 years ago
|
for _, data := range []struct {
|
||
|
key string
|
||
|
expect string
|
||
|
exist bool
|
||
|
}{
|
||
|
{"Sms", "SmsJuhe", true},
|
||
|
{"Alipay", "", true},
|
||
|
{"Zinc", "", true},
|
||
|
{"Redis", "", true},
|
||
|
{"Database", "", false},
|
||
|
{"demo", "", true},
|
||
|
} {
|
||
2 years ago
|
if v, ok := f.Cfg(data.key); ok != data.exist || v != data.expect {
|
||
3 years ago
|
t.Errorf("key: %s expect: %s exist: %t got v: %s ok: %t", data.key, data.expect, data.exist, v, ok)
|
||
|
}
|
||
|
}
|
||
|
for exp, res := range map[string]bool{
|
||
|
"Sms": true,
|
||
|
"Sms = SmsJuhe": true,
|
||
|
"SmsJuhe": false,
|
||
|
"default": true,
|
||
|
"develop": false,
|
||
|
"slim": true,
|
||
|
"demo": true,
|
||
3 years ago
|
} {
|
||
2 years ago
|
if ok := f.CfgIf(exp); res != ok {
|
||
3 years ago
|
t.Errorf("CfgIf(%s) want %t got %t", exp, res, ok)
|
||
|
}
|
||
|
}
|
||
|
}
|