more tests for code coverage

This commit is contained in:
Pratham Gadkari 2025-11-30 15:58:56 +05:30
parent ef09093976
commit ee1f501d4a

View File

@ -7,6 +7,7 @@ package binding
import ( import (
"encoding/hex" "encoding/hex"
"errors" "errors"
"fmt"
"mime/multipart" "mime/multipart"
"reflect" "reflect"
"strconv" "strconv"
@ -734,3 +735,29 @@ func TestTrySetCustomIntegration(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
assert.Equal(t, "prefix_hello", s.F.Value) assert.Equal(t, "prefix_hello", s.F.Value)
} }
type badCustom struct{}
func (b *badCustom) UnmarshalParam(s string) error {
return fmt.Errorf("boom")
}
func TestTrySetCustomError(t *testing.T) {
var s struct {
F badCustom `form:"f"`
}
err := mappingByPtr(&s, formSource{"f": {"hello"}}, "form")
require.Error(t, err)
assert.Contains(t, err.Error(), "invalid value")
}
func TestTrySetCustomNotApplicable(t *testing.T) {
var s struct {
N int `form:"n"`
}
err := mappingByPtr(&s, formSource{"n": {"42"}}, "form")
require.NoError(t, err)
assert.Equal(t, 42, s.N)
}