Add unit tests for middleware, models, services, handlers, and repository helpers
All checks were successful
CI / ci (push) Successful in 35s
All checks were successful
CI / ci (push) Successful in 35s
This commit is contained in:
35
internal/service/helpers_test.go
Normal file
35
internal/service/helpers_test.go
Normal file
@@ -0,0 +1,35 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user