1package getter
2
3import (
4	"testing"
5)
6
7func 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
29	pwd := "/pwd"
30	f := new(GitHubDetector)
31	for i, tc := range cases {
32		output, ok, err := f.Detect(tc.Input, pwd)
33		if err != nil {
34			t.Fatalf("err: %s", err)
35		}
36		if !ok {
37			t.Fatal("not ok")
38		}
39
40		if output != tc.Output {
41			t.Fatalf("%d: bad: %#v", i, output)
42		}
43	}
44}
45