github.com/artisanhe/tools@v1.0.1-0.20210607022958-19a8fef2eb04/validate/validatetpl/hostname_test.go (about)

     1  package validatetpl
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestValidateHostname(t *testing.T) {
    10  	tt := assert.New(t)
    11  
    12  	{
    13  		got, _ := ValidateHostname("134.255.255.1")
    14  		tt.True(got)
    15  	}
    16  
    17  	{
    18  		got, _ := ValidateHostname("localhost")
    19  		tt.True(got)
    20  	}
    21  
    22  	{
    23  		got, _ := ValidateHostname("service-etc-message.service-etc-message.rancher.internal")
    24  		tt.True(got)
    25  	}
    26  
    27  	{
    28  		got, _ := ValidateHostname("baidu.com")
    29  		tt.True(got)
    30  	}
    31  
    32  	{
    33  		got, errStr := ValidateHostname("134.259.255.1")
    34  		tt.False(got)
    35  		tt.Equal(InvalidHostnameValue, errStr)
    36  	}
    37  
    38  	{
    39  		got, errStr := ValidateHostname("134.255.255.1/")
    40  		tt.False(got)
    41  		tt.Equal(InvalidHostnameValue, errStr)
    42  	}
    43  
    44  	{
    45  		got, errStr := ValidateHostname(123123)
    46  		tt.False(got)
    47  		tt.Equal(InvalidHostnameType, errStr)
    48  	}
    49  }