From dd32be85c542a8a6793299e94cf2b49f143e523b Mon Sep 17 00:00:00 2001 From: Joseph Kavanagh Date: Fri, 4 Oct 2024 23:43:11 +0100 Subject: [PATCH] fix(config): handle empty services --- config/init.go | 6 ++++++ config/init_test.go | 4 +++- config/yaml_help_test.go | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/config/init.go b/config/init.go index 6ce94493..eb3f895e 100644 --- a/config/init.go +++ b/config/init.go @@ -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, diff --git a/config/init_test.go b/config/init_test.go index b3c1240a..f4021352 100644 --- a/config/init_test.go +++ b/config/init_test.go @@ -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", diff --git a/config/yaml_help_test.go b/config/yaml_help_test.go index 07229687..55868743 100644 --- a/config/yaml_help_test.go +++ b/config/yaml_help_test.go @@ -175,6 +175,7 @@ service: latest_version: type: github url: release-argus/argus + EmptyServiceIsDeleted: ` writeYAML(path, data, t)