1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
package git
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestNewGitIdentifier(t *testing.T) {
tests := []struct {
url string
expected GitIdentifier
}{
{
url: "ssh://root@subdomain.example.hostname:2222/root/my/really/weird/path/foo.git",
expected: GitIdentifier{
Remote: "ssh://root@subdomain.example.hostname:2222/root/my/really/weird/path/foo.git",
},
},
{
url: "ssh://root@subdomain.example.hostname:2222/root/my/really/weird/path/foo.git#main",
expected: GitIdentifier{
Remote: "ssh://root@subdomain.example.hostname:2222/root/my/really/weird/path/foo.git",
Ref: "main",
},
},
{
url: "git@github.com:moby/buildkit.git",
expected: GitIdentifier{
Remote: "git@github.com:moby/buildkit.git",
},
},
{
url: "github.com/moby/buildkit.git#main",
expected: GitIdentifier{
Remote: "https://github.com/moby/buildkit.git",
Ref: "main",
},
},
{
url: "git://github.com/user/repo.git",
expected: GitIdentifier{
Remote: "git://github.com/user/repo.git",
},
},
{
url: "git://github.com/user/repo.git#mybranch:mydir/mysubdir/",
expected: GitIdentifier{
Remote: "git://github.com/user/repo.git",
Ref: "mybranch",
Subdir: "mydir/mysubdir/",
},
},
{
url: "git://github.com/user/repo.git#:mydir/mysubdir/",
expected: GitIdentifier{
Remote: "git://github.com/user/repo.git",
Subdir: "mydir/mysubdir/",
},
},
{
url: "https://github.com/user/repo.git",
expected: GitIdentifier{
Remote: "https://github.com/user/repo.git",
},
},
{
url: "https://github.com/user/repo.git#mybranch:mydir/mysubdir/",
expected: GitIdentifier{
Remote: "https://github.com/user/repo.git",
Ref: "mybranch",
Subdir: "mydir/mysubdir/",
},
},
{
url: "git@github.com:user/repo.git",
expected: GitIdentifier{
Remote: "git@github.com:user/repo.git",
},
},
{
url: "git@github.com:user/repo.git#mybranch:mydir/mysubdir/",
expected: GitIdentifier{
Remote: "git@github.com:user/repo.git",
Ref: "mybranch",
Subdir: "mydir/mysubdir/",
},
},
{
url: "ssh://github.com/user/repo.git",
expected: GitIdentifier{
Remote: "ssh://github.com/user/repo.git",
},
},
{
url: "ssh://github.com/user/repo.git#mybranch:mydir/mysubdir/",
expected: GitIdentifier{
Remote: "ssh://github.com/user/repo.git",
Ref: "mybranch",
Subdir: "mydir/mysubdir/",
},
},
{
url: "ssh://foo%40barcorp.com@github.com/user/repo.git#mybranch:mydir/mysubdir/",
expected: GitIdentifier{
Remote: "ssh://foo%40barcorp.com@github.com/user/repo.git",
Ref: "mybranch",
Subdir: "mydir/mysubdir/",
},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.url, func(t *testing.T) {
gi, err := NewGitIdentifier(tt.url)
require.NoError(t, err)
require.Equal(t, tt.expected, *gi)
})
}
}
|