Skip to content

Commit

Permalink
chore: coverage++
Browse files Browse the repository at this point in the history
Increased coverage on schema register validator.
  • Loading branch information
retr0h committed Mar 7, 2024
1 parent 185799b commit b10b7a2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/config/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import (
"github.com/go-playground/validator/v10"
)

// regsiterValidatorsFn function to switch when testing
var registerValidatorsFn = registerValidators

// registerValidators register customer validators.
func registerValidators(v *validator.Validate) error {
// noop - hook for future validators
Expand All @@ -36,7 +39,7 @@ func Validate(
) error {
validate := validator.New()

err := registerValidators(validate)
err := registerValidatorsFn(validate)
if err != nil {
return err
}
Expand Down
23 changes: 23 additions & 0 deletions pkg/config/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package config

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -215,6 +216,28 @@ func (suite *SchemaTestSuite) TestRepositorySchema() {
}
}

func (suite *SchemaTestSuite) TestValidateRegisterValidatorsReturnsError() {
originalRegisterValidatorsFn := registerValidators
registerValidatorsFn = func(_ *validator.Validate) error {
return fmt.Errorf("failed to register validator")
}
defer func() { registerValidatorsFn = originalRegisterValidatorsFn }()

repos := &Repositories{
GiltFile: "giltFile",
GiltDir: "giltDir",
Repositories: []Repository{
{
Git: "gitURL",
Version: "abc1234",
DstDir: "dstDir",
},
},
}
err := Validate(repos)
assert.Error(suite.T(), err)
}

// In order for `go test` to run this suite, we need to create
// a normal test function and pass our suite to suite.Run.
func TestSchemaTestSuite(t *testing.T) {
Expand Down

0 comments on commit b10b7a2

Please sign in to comment.