Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Commit

Permalink
fix: fix null pointer dereference error while config parsing (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Matyushentsev authored and alexmt committed Feb 4, 2020
1 parent 7f75e73 commit 71b2049
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,18 @@ func newCommand() *cobra.Command {
command.Flags().StringVar(&namespace, "namespace", "", "Namespace which controller handles. Current namespace if empty.")
return &command
}

func parseConfigMapYaml(configData map[string]string) (cfg *config, err error) {
cfg = &config{}
if data, ok := configData["config.yaml"]; ok {
err = yaml.Unmarshal([]byte(data), &cfg)
if err != nil {
return &config{}, err
return cfg, err
}
}
return cfg, nil
}

func parseConfig(configData map[string]string, notifiersData []byte) (map[string]triggers.Trigger, map[string]notifiers.Notifier, map[string]string, error) {
cfg, err := parseConfigMapYaml(configData)
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ Application details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}.
assert.Equal(t, expectCfg.Context, actualCfg.Context)
}

func TestParseConfigYaml_EmptyMap(t *testing.T) {
cfg, err := parseConfigMapYaml(map[string]string{})
assert.NoError(t, err)
assert.Empty(t, cfg.Templates)
assert.Empty(t, cfg.Triggers)
assert.Empty(t, cfg.Context)
}

func TestMergeConfigTemplate(t *testing.T) {
cfg := config{
Templates: []triggers.NotificationTemplate{{
Expand Down

0 comments on commit 71b2049

Please sign in to comment.