code refactor
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
package validators
|
package validators
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin/binding"
|
|
||||||
"github.com/go-playground/validator/v10"
|
"github.com/go-playground/validator/v10"
|
||||||
|
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/core"
|
"github.com/mayswind/ezbookkeeping/pkg/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -17,10 +17,3 @@ func ValidateFiscalYearStart(fl validator.FieldLevel) bool {
|
|||||||
_, _, err := date.GetMonthDay()
|
_, _, err := date.GetMonthDay()
|
||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterFiscalYearStartValidator registers the fiscal year start date validator
|
|
||||||
func RegisterFiscalYearStartValidator() {
|
|
||||||
if v, ok := binding.Validator.Engine().(*validator.Validate); ok {
|
|
||||||
v.RegisterValidation("validFiscalYearStart", ValidateFiscalYearStart)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -4,8 +4,9 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/go-playground/validator/v10"
|
"github.com/go-playground/validator/v10"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/core"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/mayswind/ezbookkeeping/pkg/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
type fiscalYearStartContainer struct {
|
type fiscalYearStartContainer struct {
|
||||||
@@ -14,7 +15,8 @@ type fiscalYearStartContainer struct {
|
|||||||
|
|
||||||
func TestValidateFiscalYearStart_ValidValues(t *testing.T) {
|
func TestValidateFiscalYearStart_ValidValues(t *testing.T) {
|
||||||
validate := validator.New()
|
validate := validator.New()
|
||||||
validate.RegisterValidation("validFiscalYearStart", ValidateFiscalYearStart)
|
err := validate.RegisterValidation("validFiscalYearStart", ValidateFiscalYearStart)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
@@ -37,7 +39,8 @@ func TestValidateFiscalYearStart_ValidValues(t *testing.T) {
|
|||||||
|
|
||||||
func TestValidateFiscalYearStart_InvalidValues(t *testing.T) {
|
func TestValidateFiscalYearStart_InvalidValues(t *testing.T) {
|
||||||
validate := validator.New()
|
validate := validator.New()
|
||||||
validate.RegisterValidation("validFiscalYearStart", ValidateFiscalYearStart)
|
err := validate.RegisterValidation("validFiscalYearStart", ValidateFiscalYearStart)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
|
|||||||
Reference in New Issue
Block a user