mirror of
https://github.com/TECHNOFAB11/jsonnet-bundler.git
synced 2025-12-12 08:00:05 +01:00
fix: Git ssh-scp syntax (#69)
* fix(deps): proper git ssh scheme * feat(deps): git scp style Adds support for the git ssh-scp style (`git@github.com:user/repo.git`), which is an alternative form for ssh (note no ssh://). * fix(deps): githubSlug also matching gitSSH * test(deps): other hosts than github
This commit is contained in:
parent
7b8a7836a4
commit
8f14d63f95
3 changed files with 62 additions and 55 deletions
|
|
@ -17,9 +17,23 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestParseGit(t *testing.T) {
|
||||
sshWant := func(host string) *Dependency {
|
||||
return &Dependency{
|
||||
Version: "v1",
|
||||
Source: Source{GitSource: &Git{
|
||||
Scheme: GitSchemeSSH,
|
||||
Host: host,
|
||||
User: "user",
|
||||
Repo: "repo",
|
||||
Subdir: "/foobar",
|
||||
}},
|
||||
}
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
uri string
|
||||
|
|
@ -27,7 +41,7 @@ func TestParseGit(t *testing.T) {
|
|||
wantRemote string
|
||||
}{
|
||||
{
|
||||
name: "GitHub",
|
||||
name: "github-slug",
|
||||
uri: "github.com/ksonnet/ksonnet-lib/ksonnet.beta.3",
|
||||
want: &Dependency{
|
||||
Version: "master",
|
||||
|
|
@ -42,26 +56,28 @@ func TestParseGit(t *testing.T) {
|
|||
wantRemote: "https://github.com/ksonnet/ksonnet-lib",
|
||||
},
|
||||
{
|
||||
name: "SSH",
|
||||
uri: "git+ssh://git@my.host:user/repo.git/foobar@v1",
|
||||
want: &Dependency{
|
||||
Version: "v1",
|
||||
Source: Source{GitSource: &Git{
|
||||
Scheme: GitSchemeSSH,
|
||||
Host: "my.host",
|
||||
User: "user",
|
||||
Repo: "repo",
|
||||
Subdir: "/foobar",
|
||||
}},
|
||||
},
|
||||
wantRemote: "ssh://git@my.host:user/repo.git",
|
||||
name: "ssh.ssh",
|
||||
uri: "ssh://git@example.com/user/repo.git/foobar@v1",
|
||||
want: sshWant("example.com"),
|
||||
wantRemote: "ssh://git@example.com/user/repo.git",
|
||||
},
|
||||
{
|
||||
name: "ssh.scp",
|
||||
uri: "git@my.host:user/repo.git/foobar@v1",
|
||||
want: sshWant("my.host"),
|
||||
wantRemote: "ssh://git@my.host/user/repo.git", // want ssh format here
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range tests {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
got := Parse("", c.uri)
|
||||
require.NotNilf(t, got, "parsed dependency is nil. Most likely, no regex matched the format.")
|
||||
|
||||
assert.Equal(t, c.want, got)
|
||||
|
||||
require.NotNil(t, got.Source)
|
||||
require.NotNil(t, got.Source.GitSource)
|
||||
assert.Equal(t, c.wantRemote, got.Source.GitSource.Remote())
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue