Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for utils sorting function #694

Merged
merged 1 commit into from
Nov 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
})
}
}