github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/pkg/types/urls_test.go (about)

     1  // Copyright 2020 PingCAP, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package types
    15  
    16  import (
    17  	"strings"
    18  	"testing"
    19  
    20  	"github.com/pingcap/check"
    21  	"github.com/pingcap/ticdc/pkg/util/testleak"
    22  )
    23  
    24  func Test(t *testing.T) {
    25  	check.TestingT(t)
    26  }
    27  
    28  var _ = check.Suite(&testTypesSuite{})
    29  
    30  type testTypesSuite struct{}
    31  
    32  func (s *testTypesSuite) TestURLs(c *check.C) {
    33  	defer testleak.AfterTest(c)()
    34  	urlstrs := []string{
    35  		"http://www.google.com:12306",
    36  		"http://192.168.199.111:1080",
    37  		"http://hostname:9000",
    38  	}
    39  	sorted := []string{
    40  		"http://192.168.199.111:1080",
    41  		"http://hostname:9000",
    42  		"http://www.google.com:12306",
    43  	}
    44  
    45  	urls, err := NewURLs(urlstrs)
    46  	c.Assert(err, check.IsNil)
    47  	c.Assert(urls.String(), check.Equals, strings.Join(sorted, ","))
    48  }
    49  
    50  func (s *testTypesSuite) TestBadURLs(c *check.C) {
    51  	defer testleak.AfterTest(c)()
    52  	badurls := [][]string{
    53  		{"http://192.168.199.111"},
    54  		{"127.0.0.1:1080"},
    55  		{"http://192.168.199.112:8080/api/v1"},
    56  	}
    57  
    58  	for _, badurl := range badurls {
    59  		_, err := NewURLs(badurl)
    60  		c.Assert(err, check.NotNil)
    61  	}
    62  }