chore(conf): add default value for max_concurrent_pushes (#646)

This commit is contained in:
Bo-Yi Wu 2021-12-09 23:46:49 +08:00 committed by GitHub
parent 20e6566183
commit 4c1c87aecc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View File

@ -277,10 +277,17 @@ type SectionGRPC struct {
Port string `yaml:"port"`
}
func setDefault() {
viper.SetDefault("ios.max_concurrent_pushes", uint(100))
}
// LoadConf load config from file and read in environment variables that match
func LoadConf(confPath ...string) (*ConfYaml, error) {
conf := &ConfYaml{}
// load default values
setDefault()
viper.SetConfigType("yaml")
viper.AutomaticEnv() // read in environment variables that match
viper.SetEnvPrefix("gorush") // will be uppercased automatically

View File

@ -17,6 +17,15 @@ func TestMissingFile(t *testing.T) {
assert.NotNil(t, err)
}
func TestEmptyConfig(t *testing.T) {
conf, err := LoadConf("testdata/empty.yml")
if err != nil {
panic("failed to load config.yml from file")
}
assert.Equal(t, uint(100), conf.Ios.MaxConcurrentPushes)
}
type ConfigTestSuite struct {
suite.Suite
ConfGorushDefault *ConfYaml

0
config/testdata/empty.yml vendored Normal file
View File