github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/pkg/urlutil/urlutil_test.go (about)

     1  package urlutil // import "github.com/docker/docker/pkg/urlutil"
     2  
     3  import "testing"
     4  
     5  var (
     6  	gitUrls = []string{
     7  		"git://github.com/docker/docker",
     8  		"git@github.com:docker/docker.git",
     9  		"git@bitbucket.org:atlassianlabs/atlassian-docker.git",
    10  		"https://github.com/docker/docker.git",
    11  		"http://github.com/docker/docker.git",
    12  		"http://github.com/docker/docker.git#branch",
    13  		"http://github.com/docker/docker.git#:dir",
    14  	}
    15  	incompleteGitUrls = []string{
    16  		"github.com/docker/docker",
    17  	}
    18  	invalidGitUrls = []string{
    19  		"http://github.com/docker/docker.git:#branch",
    20  	}
    21  	transportUrls = []string{
    22  		"tcp://example.com",
    23  		"tcp+tls://example.com",
    24  		"udp://example.com",
    25  		"unix:///example",
    26  		"unixgram:///example",
    27  	}
    28  )
    29  
    30  func TestIsGIT(t *testing.T) {
    31  	for _, url := range gitUrls {
    32  		if !IsGitURL(url) {
    33  			t.Fatalf("%q should be detected as valid Git url", url)
    34  		}
    35  	}
    36  
    37  	for _, url := range incompleteGitUrls {
    38  		if !IsGitURL(url) {
    39  			t.Fatalf("%q should be detected as valid Git url", url)
    40  		}
    41  	}
    42  
    43  	for _, url := range invalidGitUrls {
    44  		if IsGitURL(url) {
    45  			t.Fatalf("%q should not be detected as valid Git prefix", url)
    46  		}
    47  	}
    48  }
    49  
    50  func TestIsTransport(t *testing.T) {
    51  	for _, url := range transportUrls {
    52  		if !IsTransportURL(url) {
    53  			t.Fatalf("%q should be detected as valid Transport url", url)
    54  		}
    55  	}
    56  }