github.com/jenkins-x/jx/v2@v2.1.155/pkg/surveyutils/validators_test.go (about)

     1  // +build unit
     2  
     3  package surveyutils_test
     4  
     5  import (
     6  	"testing"
     7  
     8  	"github.com/jenkins-x/jx/v2/pkg/surveyutils"
     9  	"github.com/stretchr/testify/assert"
    10  	"gopkg.in/AlecAivazis/survey.v1"
    11  )
    12  
    13  func TestNoWhitespaceValidator(t *testing.T) {
    14  	t.Parallel()
    15  
    16  	tests := []struct {
    17  		testName   string
    18  		domainName string
    19  		want       string
    20  	}{
    21  		{"leading whitespace", " fake.com", "supplied value \" fake.com\" must not contain any whitespace"},
    22  		{"trailing whitespace", "fake.com ", "supplied value \"fake.com \" must not contain any whitespace"},
    23  		{"embedded whitespace", "fake .com", "supplied value \"fake .com\" must not contain any whitespace"},
    24  	}
    25  
    26  	for _, tt := range tests {
    27  		t.Run(tt.testName, func(t *testing.T) {
    28  			assert.Equal(t, tt.want, testInputValidation(t, tt.domainName))
    29  		})
    30  	}
    31  }
    32  
    33  func testInputValidation(t *testing.T, s string) interface{} {
    34  	valid := survey.ComposeValidators(
    35  		surveyutils.NoWhiteSpaceValidator(),
    36  	)
    37  	err := valid(s)
    38  	if err != nil {
    39  		return err.Error()
    40  	}
    41  	return ""
    42  }