github.com/k0marov/go-socnet@v0.0.0-20220715154813-90d07867c782/features/comments/domain/validators/validators_test.go (about)

     1  package validators_test
     2  
     3  import (
     4  	"github.com/k0marov/go-socnet/core/general/client_errors"
     5  	. "github.com/k0marov/go-socnet/core/helpers/test_helpers"
     6  	"strings"
     7  	"testing"
     8  
     9  	"github.com/k0marov/go-socnet/features/comments/domain/validators"
    10  	"github.com/k0marov/go-socnet/features/comments/domain/values"
    11  )
    12  
    13  func TestCommentValidator(t *testing.T) {
    14  	cases := []struct {
    15  		comment values.NewCommentValue
    16  
    17  		isValid bool
    18  		wantErr client_errors.ClientError
    19  	}{
    20  		{values.NewCommentValue{Text: "Normal text"}, true, client_errors.ClientError{}},
    21  		{values.NewCommentValue{Text: ""}, false, client_errors.EmptyText},
    22  		{values.NewCommentValue{Text: strings.Repeat("looooong", 100)}, false, client_errors.TextTooLong},
    23  	}
    24  
    25  	for _, testCase := range cases {
    26  		t.Run(testCase.comment.Text, func(t *testing.T) {
    27  			gotErr, gotValid := validators.NewCommentValidator()(testCase.comment)
    28  			AssertFatal(t, gotValid, testCase.isValid, "the result of validation")
    29  			Assert(t, gotErr, testCase.wantErr, "the returned client error")
    30  		})
    31  	}
    32  }