Skip to content

Commit

Permalink
Add test for utils sorting function
Browse files Browse the repository at this point in the history
  • Loading branch information
stevemcquaid committed Nov 8, 2023
1 parent be260db commit 3ce6a3c
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions outputs/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package outputs

import (
"reflect"
"testing"
)

func Test_getSortedStringKeys(t *testing.T) {
type args struct {
m map[string]interface{}
}
tests := []struct {
name string
args args
want []string
}{
{
name: "basic sort",
args: args{
m: map[string]interface{}{
"b": "foo",
"c": "baz",
"a": "bar",
},
},
want: []string{"a", "b", "c"},
},
{
name: "In place sort",
args: args{
m: map[string]interface{}{
"a": "",
"b": "",
"c": "",
},
},
want: []string{"a", "b", "c"},
},
{
name: "Non-string emission",
args: args{
m: map[string]interface{}{
"a": "a",
"b": 2,
"c": "c",
},
},
want: []string{"a", "c"},
},
{
name: "Non-string emission - empty result",
args: args{
m: map[string]interface{}{
"a": 1,
"b": 2,
"c": 3,
},
},
want: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := getSortedStringKeys(tt.args.m); !reflect.DeepEqual(got, tt.want) {
t.Errorf("getSortedStringKeys() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 3ce6a3c

Please sign in to comment.