github.com/rentongzhang/docker@v1.8.2-rc1/pkg/urlutil/urlutil_test.go (about)

     1  package 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  )
    22  
    23  func TestValidGitTransport(t *testing.T) {
    24  	for _, url := range gitUrls {
    25  		if IsGitTransport(url) == false {
    26  			t.Fatalf("%q should be detected as valid Git prefix", url)
    27  		}
    28  	}
    29  
    30  	for _, url := range incompleteGitUrls {
    31  		if IsGitTransport(url) == true {
    32  			t.Fatalf("%q should not be detected as valid Git prefix", url)
    33  		}
    34  	}
    35  }
    36  
    37  func TestIsGIT(t *testing.T) {
    38  	for _, url := range gitUrls {
    39  		if IsGitURL(url) == false {
    40  			t.Fatalf("%q should be detected as valid Git url", url)
    41  		}
    42  	}
    43  
    44  	for _, url := range incompleteGitUrls {
    45  		if IsGitURL(url) == false {
    46  			t.Fatalf("%q should be detected as valid Git url", url)
    47  		}
    48  	}
    49  
    50  	for _, url := range invalidGitUrls {
    51  		if IsGitURL(url) == true {
    52  			t.Fatalf("%q should not be detected as valid Git prefix", url)
    53  		}
    54  	}
    55  }