Skip to content

Commit

Permalink
feat: added MarshalYAML to severities array
Browse files Browse the repository at this point in the history
  • Loading branch information
Ice3man543 committed May 10, 2024
1 parent eb73228 commit 29c3165
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/model/types/severity/severities.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ func (severities *Severities) Set(values string) error {
return nil
}

func (severities Severities) MarshalYAML() (interface{}, error) {
var stringSeverities = make([]string, 0, len(severities))
for _, severity := range severities {
stringSeverities = append(stringSeverities, severity.String())
}
return stringSeverities, nil
}

func (severities *Severities) UnmarshalYAML(unmarshal func(interface{}) error) error {
var stringSliceValue stringslice.StringSlice
if err := unmarshal(&stringSliceValue); err != nil {
Expand Down
9 changes: 9 additions & 0 deletions pkg/model/types/severity/severity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,12 @@ func TestMarshalJSON(t *testing.T) {
}
require.Equal(t, "[\"low\",\"medium\"]", string(data), "could not marshal json")
}

func TestSeveritiesMarshalYaml(t *testing.T) {
unmarshalled := Severities{Low, Medium}
marshalled, err := yaml.Marshal(unmarshalled)
if err != nil {
panic(err)
}
require.Equal(t, "- low\n- medium\n", string(marshalled), "could not marshal yaml")
}

0 comments on commit 29c3165

Please sign in to comment.