From 94760ac32b7a3fb02a5f983f4ec2fe4027df0c7a Mon Sep 17 00:00:00 2001 From: andig Date: Tue, 5 Dec 2023 10:28:30 +0100 Subject: [PATCH] chore: fix panic when dumping OnIdentified --- api/actionconfig.go | 8 +++----- api/actionconfig_test.go | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 api/actionconfig_test.go diff --git a/api/actionconfig.go b/api/actionconfig.go index 16bc86300..f48742ce7 100644 --- a/api/actionconfig.go +++ b/api/actionconfig.go @@ -2,7 +2,6 @@ package api import ( "fmt" - "reflect" "strings" "github.com/fatih/structs" @@ -19,10 +18,9 @@ type ActionConfig struct { // String implements Stringer and returns the ActionConfig as comma-separated key:value string func (a ActionConfig) String() string { var s []string - for k, v := range structs.Map(a) { - val := reflect.ValueOf(v) - if v != nil && !val.IsNil() { - s = append(s, fmt.Sprintf("%s:%v", k, val.Elem())) + for _, f := range structs.Fields(a) { + if !f.IsZero() { + s = append(s, fmt.Sprintf("%s:%v", f.Name(), f.Value())) } } return strings.Join(s, ", ") diff --git a/api/actionconfig_test.go b/api/actionconfig_test.go new file mode 100644 index 000000000..870eb8613 --- /dev/null +++ b/api/actionconfig_test.go @@ -0,0 +1,14 @@ +package api + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestActionConfigString(t *testing.T) { + var a ActionConfig + assert.NotPanics(t, func() { + _ = a.String() + }) +}