Files
gonic/server/handler/handler_admin_utils_test.go
2019-05-30 14:52:39 +01:00

33 lines
594 B
Go

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"},
{"all missing",
[]string{"", "", ""}, "default",
"default"},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
actu := firstExisting(tc.or, tc.values...)
if actu != tc.exp {
t.Errorf("expected %q, got %q", tc.exp, actu)
}
})
}
}