-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be260db
commit 3ce6a3c
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
}) | ||
} | ||
} |