Skip to content

Commit

Permalink
program parameter should not be overwritten from program-default sect…
Browse files Browse the repository at this point in the history
…ion if the parameter already exists #228
  • Loading branch information
ochinchina committed Oct 14, 2020
1 parent 430235c commit 7322541
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ func (c *Config) setProgramDefaultParams(cfg *ini.Ini) {
continue
}
for _, key := range program_default_section.Keys() {
section.Add(key.Name(), key.ValueWithDefault(""))
if !section.HasKey(key.Name()) {
section.Add(key.Name(), key.ValueWithDefault(""))
}
}

}
Expand Down
3 changes: 2 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ func TestConfigWithInclude(t *testing.T) {
}

func TestDefaultParams(t *testing.T) {
config, _ := parse([]byte("[program:test]\nautorestart=true\ntest=1\n[program-default]\ncommand=/usr/bin/ls\nrestart=true\nautorestart=false"))
s := "[program:test]\nautorestart=true\ntest=1\n[program-default]\ncommand=/usr/bin/ls\nrestart=true\nautorestart=false"
config, _ := parse([]byte(s))
entry := config.GetProgram("test")
if entry.GetString("command", "") != "/usr/bin/ls" {
t.Error("fail to get command of program")
Expand Down

0 comments on commit 7322541

Please sign in to comment.