Skip to content

Commit

Permalink
fix(config): handle empty services
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephKav committed Oct 4, 2024
1 parent 5e6ffcb commit dd32be8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ func (c *Config) Load(file string, flagset *map[string]bool, log *util.JLog) {
c.SaveChannel = &saveChannel

for key := range c.Service {
if c.Service[key] == nil {
c.Order = util.RemoveElement(c.Order, key)
delete(c.Service, key)
continue
}

c.Service[key].ID = key
c.Service[key].Status = *svcstatus.New(
nil, c.DatabaseChannel, c.SaveChannel,
Expand Down
4 changes: 3 additions & 1 deletion config/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ func TestConfig_Load(t *testing.T) {
"WebHook.Delay": {
got: config.Defaults.WebHook.Delay,
want: "2s"},
"EmptyServiceIsDeleted": {
got: config.Service["EmptyService"].String(""),
want: ""},
}

// THEN they match the config file
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
t.Parallel()

if tc.got != tc.want {
t.Errorf("invalid %s:\nwant: %s\ngot: %s",
Expand Down
1 change: 1 addition & 0 deletions config/yaml_help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ service:
latest_version:
type: github
url: release-argus/argus
EmptyServiceIsDeleted:
`

writeYAML(path, data, t)
Expand Down

0 comments on commit dd32be8

Please sign in to comment.