36 lines
685 B
Go
36 lines
685 B
Go
package service
|
|
|
|
import "testing"
|
|
|
|
func TestDefaultString(t *testing.T) {
|
|
tests := []struct {
|
|
val, def, want string
|
|
}{
|
|
{"hello", "default", "hello"},
|
|
{"", "default", "default"},
|
|
{"", "", ""},
|
|
}
|
|
for _, tt := range tests {
|
|
got := defaultString(tt.val, tt.def)
|
|
if got != tt.want {
|
|
t.Errorf("defaultString(%q, %q) = %q, want %q", tt.val, tt.def, got, tt.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestDefaultInt(t *testing.T) {
|
|
tests := []struct {
|
|
val, def, want int
|
|
}{
|
|
{5, 10, 5},
|
|
{0, 10, 10},
|
|
{0, 0, 0},
|
|
}
|
|
for _, tt := range tests {
|
|
got := defaultInt(tt.val, tt.def)
|
|
if got != tt.want {
|
|
t.Errorf("defaultInt(%d, %d) = %d, want %d", tt.val, tt.def, got, tt.want)
|
|
}
|
|
}
|
|
}
|