github.com/kamiazya/dot-github@v1.3.0/repository_test.go (about)

     1  package main
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  )
     7  
     8  func TestWebURL(t *testing.T) {
     9  	r := NewRepositoryFromURL("https://github.com/rhysd/dot-github.git")
    10  	if r.User != "rhysd" {
    11  		t.Fatalf("User name is invalid: %v", r.User)
    12  	}
    13  	if r.Name != "dot-github" {
    14  		t.Fatalf("Repository name is invalid: %v", r.Name)
    15  	}
    16  	if !strings.HasSuffix(r.Path, "dot-github") {
    17  		t.Fatalf("Repository root must end with its name: %v", r.Path)
    18  	}
    19  }
    20  
    21  func TestGitURL(t *testing.T) {
    22  	r := NewRepositoryFromURL("git://github.com/rhysd/dot-github.git")
    23  	if r.User != "rhysd" {
    24  		t.Fatalf("User name is invalid: %v", r.User)
    25  	}
    26  	if r.Name != "dot-github" {
    27  		t.Fatalf("Repository name is invalid: %v", r.Name)
    28  	}
    29  	if !strings.HasSuffix(r.Path, "dot-github") {
    30  		t.Fatalf("Repository root must end with its name: %v", r.Path)
    31  	}
    32  }
    33  
    34  func TestSshURL(t *testing.T) {
    35  	r := NewRepositoryFromURL("git@github.com:rhysd/dot-github.git")
    36  	if r.User != "rhysd" {
    37  		t.Fatalf("User name is invalid: %v", r.User)
    38  	}
    39  	if r.Name != "dot-github" {
    40  		t.Fatalf("Repository name is invalid: %v", r.Name)
    41  	}
    42  	if !strings.HasSuffix(r.Path, "dot-github") {
    43  		t.Fatalf("Repository root must end with its name: %v", r.Path)
    44  	}
    45  }
    46  
    47  func TestInvalidPath(t *testing.T) {
    48  	defer func() {
    49  		if r := recover(); r == nil {
    50  			t.Errorf("URL without path must cause panic")
    51  		}
    52  	}()
    53  	NewRepositoryFromURL("https://github.com")
    54  }
    55  
    56  func TestInvalidGitURL(t *testing.T) {
    57  	defer func() {
    58  		if r := recover(); r == nil {
    59  			t.Errorf("Invalid URL must cause panic")
    60  		}
    61  	}()
    62  	NewRepositoryFromURL("invalid-blah")
    63  }
    64  
    65  func TestInvalidURLScheme(t *testing.T) {
    66  	defer func() {
    67  		if r := recover(); r == nil {
    68  			t.Errorf("Invalid Scheme must cause panic")
    69  		}
    70  	}()
    71  	NewRepositoryFromURL("file://blah.jp")
    72  }