gitlab.com/evatix-go/core@v1.3.55/tests/integratedtests/corevalidatortests/TestValidators_test.go (about)

     1  package corevalidatortests
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/smartystreets/goconvey/convey"
     7  	"gitlab.com/evatix-go/core/constants"
     8  	"gitlab.com/evatix-go/core/corevalidator"
     9  	"gitlab.com/evatix-go/core/enums/stringcompareas"
    10  	"gitlab.com/evatix-go/core/errcore"
    11  	"gitlab.com/evatix-go/core/tests/testwrappers/corevalidatortestwrappers"
    12  )
    13  
    14  func Test_TestValidators(t *testing.T) {
    15  	for caseIndex, testCase := range corevalidatortestwrappers.TextValidatorsTestCases {
    16  		// Arrange
    17  		paramsBase := corevalidator.ValidatorParamsBase{
    18  			CaseIndex:                         constants.Zero, // fixing test case number here as it is fixed data
    19  			IsIgnoreCompareOnActualInputEmpty: testCase.IsSkipOnContentsEmpty,
    20  			IsAttachUserInputs:                true,
    21  			IsCaseSensitive:                   testCase.IsCaseSensitive,
    22  		}
    23  
    24  		err := testCase.Validators.AllVerifyErrorMany(
    25  			&paramsBase,
    26  			testCase.ComparingLines...)
    27  
    28  		errorLines := errcore.ErrorToSplitLines(
    29  			err)
    30  
    31  		sliceValidator := corevalidator.SliceValidator{
    32  			ActualLines:   errorLines,
    33  			ExpectedLines: testCase.ExpectationLines,
    34  			ValidatorCoreCondition: corevalidator.ValidatorCoreCondition{
    35  				IsTrimCompare:        false,
    36  				IsNonEmptyWhitespace: false,
    37  				IsSortStringsBySpace: false,
    38  			},
    39  			CompareAs: stringcompareas.Equal,
    40  		}
    41  
    42  		paramsBase2 := corevalidator.ValidatorParamsBase{
    43  			CaseIndex:                         caseIndex,
    44  			IsIgnoreCompareOnActualInputEmpty: false,
    45  			IsAttachUserInputs:                true,
    46  			IsCaseSensitive:                   testCase.IsCaseSensitive,
    47  		}
    48  
    49  		// Act
    50  		validationFinalError := sliceValidator.AllVerifyError(
    51  			&paramsBase2)
    52  
    53  		isValid := validationFinalError == nil
    54  
    55  		// Assert
    56  		convey.Convey(testCase.Header, t, func() {
    57  			errcore.ErrPrintWithTestIndex(caseIndex, validationFinalError)
    58  
    59  			convey.So(isValid, convey.ShouldBeTrue)
    60  		})
    61  	}
    62  }