add first exiting test
This commit is contained in:
37
server/handler/handler_admin_utils_test.go
Normal file
37
server/handler/handler_admin_utils_test.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFirstExisting(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
values []string
|
||||
or string
|
||||
exp string
|
||||
}{
|
||||
{"none present",
|
||||
[]string{"one", "two", "three"}, "default",
|
||||
"one"},
|
||||
{"first missing",
|
||||
[]string{"", "two", "three"}, "default",
|
||||
"two"},
|
||||
{"middle missing",
|
||||
[]string{"", "two", ""}, "default",
|
||||
"two"},
|
||||
{"all missing",
|
||||
[]string{"", "", ""}, "default",
|
||||
"default"},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
tc := tc // capture range variable?
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
actu := firstExisting(tc.or, tc.values...)
|
||||
if actu != tc.exp {
|
||||
t.Errorf("expected %q, got %q", tc.exp, actu)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user