Skip to content

Commit 9b786e6

Browse files
committed
improve test coverage for validators
1 parent 2d2b294 commit 9b786e6

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

validator/branch_validator_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,16 @@ func (suite *BranchValidatorTestSuite) TestValidate_WhenPassedBranchesAreValid_S
3030
suite.Nil(err)
3131
}
3232

33-
func (suite *BranchValidatorTestSuite) TestValidate_WhenPassedEmptyStringIsPassed_ShouldReturnEmptybranchError() {
33+
func (suite *BranchValidatorTestSuite) TestValidate_WhenNoBranchesArePassed_ShouldReturnEmptyBranchError() {
3434
err := suite.branchValidator.ValidateWithFields()
3535

3636
suite.NotNil(err)
3737
suite.Equal(EmptyBranchName, err)
3838
}
39+
40+
func (suite *BranchValidatorTestSuite) TestValidate_WhenEmptyStringIsPassed_ShouldReturnEmptyBranchError() {
41+
err := suite.branchValidator.ValidateWithFields("")
42+
43+
suite.NotNil(err)
44+
suite.Equal(EmptyBranchName, err)
45+
}

validator/repo_validator_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,12 @@ func (suite *RepoValidatorTestSuite) TestValidate_WhenRepoIsNil_ShouldReturnRepo
4242
suite.NotNil(err)
4343
suite.Equal(NilRepoError, err)
4444
}
45+
46+
func (suite *RepoValidatorTestSuite) TestValidate_WhenWrongTypeOfInputIsPassed_ShouldReturnRepoNilError() {
47+
suite.repoValidator = NewRepoValidator()
48+
49+
err := suite.repoValidator.Validate("nil")
50+
51+
suite.NotNil(err)
52+
suite.Equal(NilRepoError, err)
53+
}

validator/validation_errors_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package validator
2+
3+
import (
4+
"github.com/stretchr/testify/suite"
5+
"testing"
6+
)
7+
8+
type ValidationErrorTestSuite struct {
9+
suite.Suite
10+
validationError Error
11+
}
12+
13+
func TestValidationErrorTestSuite(t *testing.T) {
14+
suite.Run(t, new(ValidationErrorTestSuite))
15+
}
16+
17+
func (suite *ValidationErrorTestSuite) TestError_ShouldReturnErrorString() {
18+
suite.validationError = NilRepoError
19+
20+
suite.Equal("Repo is nil", suite.validationError.Error())
21+
}

0 commit comments

Comments
 (0)