github.com/remind101/go-getter@v0.0.0-20180809191950-4bda8fa99001/detect_github_test.go (about)

     1  package getter
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestGitHubDetector(t *testing.T) {
     8  	cases := []struct {
     9  		Input  string
    10  		Output string
    11  	}{
    12  		// HTTP
    13  		{"github.com/hashicorp/foo", "git::https://github.com/hashicorp/foo.git"},
    14  		{"github.com/hashicorp/foo.git", "git::https://github.com/hashicorp/foo.git"},
    15  		{
    16  			"github.com/hashicorp/foo/bar",
    17  			"git::https://github.com/hashicorp/foo.git//bar",
    18  		},
    19  		{
    20  			"github.com/hashicorp/foo?foo=bar",
    21  			"git::https://github.com/hashicorp/foo.git?foo=bar",
    22  		},
    23  		{
    24  			"github.com/hashicorp/foo.git?foo=bar",
    25  			"git::https://github.com/hashicorp/foo.git?foo=bar",
    26  		},
    27  
    28  		// SSH
    29  		{"git@github.com:hashicorp/foo.git", "git::ssh://git@github.com/hashicorp/foo.git"},
    30  		{
    31  			"git@github.com:hashicorp/foo.git//bar",
    32  			"git::ssh://git@github.com/hashicorp/foo.git//bar",
    33  		},
    34  		{
    35  			"git@github.com:hashicorp/foo.git?foo=bar",
    36  			"git::ssh://git@github.com/hashicorp/foo.git?foo=bar",
    37  		},
    38  	}
    39  
    40  	pwd := "/pwd"
    41  	f := new(GitHubDetector)
    42  	for i, tc := range cases {
    43  		output, ok, err := f.Detect(tc.Input, pwd)
    44  		if err != nil {
    45  			t.Fatalf("err: %s", err)
    46  		}
    47  		if !ok {
    48  			t.Fatal("not ok")
    49  		}
    50  
    51  		if output != tc.Output {
    52  			t.Fatalf("%d: bad: %#v", i, output)
    53  		}
    54  	}
    55  }