mirror of
https://github.com/TECHNOFAB11/jsonnet-bundler.git
synced 2025-12-11 23:50:05 +01:00
Fix subgroup parsing on subsequent installs (#93)
* Fix subgroup parsing on subsequent installs * enforce .git as remote suffix * fix integration tests * do not modify pointer receiver in getters * fix merged integration tests
This commit is contained in:
parent
d78a05a86f
commit
50b717beab
6 changed files with 28 additions and 28 deletions
|
|
@ -60,8 +60,8 @@ func testInstallCommandWithJsonnetHome(t *testing.T, jsonnetHome string) {
|
||||||
Name: "OneURL",
|
Name: "OneURL",
|
||||||
URIs: []string{"github.com/jsonnet-bundler/jsonnet-bundler@v0.1.0"},
|
URIs: []string{"github.com/jsonnet-bundler/jsonnet-bundler@v0.1.0"},
|
||||||
ExpectedCode: 0,
|
ExpectedCode: 0,
|
||||||
ExpectedJsonnetFile: []byte(`{"version": 1, "dependencies": [{"source": {"git": {"remote": "https://github.com/jsonnet-bundler/jsonnet-bundler", "subdir": ""}}, "version": "v0.1.0"}], "legacyImports": true}`),
|
ExpectedJsonnetFile: []byte(`{"version": 1, "dependencies": [{"source": {"git": {"remote": "https://github.com/jsonnet-bundler/jsonnet-bundler.git", "subdir": ""}}, "version": "v0.1.0"}], "legacyImports": true}`),
|
||||||
ExpectedJsonnetLockFile: []byte(`{"version": 1, "dependencies": [{"source": {"git": {"remote": "https://github.com/jsonnet-bundler/jsonnet-bundler", "subdir": ""}}, "version": "080f157c7fb85ad0281ea78f6c641eaa570a582f", "sum": "W1uI550rQ66axRpPXA2EZDquyPg/5PHZlvUz1NEzefg="}], "legacyImports": false}`),
|
ExpectedJsonnetLockFile: []byte(`{"version": 1, "dependencies": [{"source": {"git": {"remote": "https://github.com/jsonnet-bundler/jsonnet-bundler.git", "subdir": ""}}, "version": "080f157c7fb85ad0281ea78f6c641eaa570a582f", "sum": "W1uI550rQ66axRpPXA2EZDquyPg/5PHZlvUz1NEzefg="}], "legacyImports": false}`),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "Local",
|
Name: "Local",
|
||||||
|
|
@ -74,8 +74,8 @@ func testInstallCommandWithJsonnetHome(t *testing.T, jsonnetHome string) {
|
||||||
Name: "single",
|
Name: "single",
|
||||||
URIs: []string{"github.com/grafana/loki/production/ksonnet/loki@bd4d516262c107a0bde7a962fa2b1e567a2c21e5"},
|
URIs: []string{"github.com/grafana/loki/production/ksonnet/loki@bd4d516262c107a0bde7a962fa2b1e567a2c21e5"},
|
||||||
ExpectedCode: 0,
|
ExpectedCode: 0,
|
||||||
ExpectedJsonnetFile: []byte(`{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/loki","subdir":"production/ksonnet/loki"}},"version":"bd4d516262c107a0bde7a962fa2b1e567a2c21e5","single":true}],"legacyImports":true}`),
|
ExpectedJsonnetFile: []byte(`{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/loki.git","subdir":"production/ksonnet/loki"}},"version":"bd4d516262c107a0bde7a962fa2b1e567a2c21e5","single":true}],"legacyImports":true}`),
|
||||||
ExpectedJsonnetLockFile: []byte(`{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/loki","subdir":"production/ksonnet/loki"}},"version":"bd4d516262c107a0bde7a962fa2b1e567a2c21e5","sum":"ExovUKXmZ4KwJAv/q8ZwNW9BdIZlrxmoGrne7aR64wo=","single":true}],"legacyImports":false}`),
|
ExpectedJsonnetLockFile: []byte(`{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/loki.git","subdir":"production/ksonnet/loki"}},"version":"bd4d516262c107a0bde7a962fa2b1e567a2c21e5","sum":"ExovUKXmZ4KwJAv/q8ZwNW9BdIZlrxmoGrne7aR64wo=","single":true}],"legacyImports":false}`),
|
||||||
single: true,
|
single: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -102,24 +102,24 @@ func TestUpdate(t *testing.T) {
|
||||||
name: "simple",
|
name: "simple",
|
||||||
uris: []string{}, // no uris
|
uris: []string{}, // no uris
|
||||||
before: &RepoState{
|
before: &RepoState{
|
||||||
File: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib","subdir":""}},"version":"master"}],"legacyImports":true}`,
|
File: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib.git","subdir":""}},"version":"master"}],"legacyImports":true}`,
|
||||||
Lock: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib","subdir":""}},"version":"9f40207f668e382b706e1822f2d46ce2cd0a57cc","sum":"qUJDskVRtmkTms2udvFpLi1t5YKVbGmMSyiZnPjXsMo="}],"legacyImports":false}`,
|
Lock: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib.git","subdir":""}},"version":"9f40207f668e382b706e1822f2d46ce2cd0a57cc","sum":"qUJDskVRtmkTms2udvFpLi1t5YKVbGmMSyiZnPjXsMo="}],"legacyImports":false}`,
|
||||||
},
|
},
|
||||||
after: &RepoState{
|
after: &RepoState{
|
||||||
File: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib","subdir":""}},"version":"master"}],"legacyImports":true}`,
|
File: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib.git","subdir":""}},"version":"master"}],"legacyImports":true}`,
|
||||||
Lock: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib","subdir":""}},"version":"ed7c1aff9e10d3b42fb130446d495f1c769ecd7b","sum":"OraOcUvDIx9Eikaihi8XsRNRsVehO75Ek35im/jYoSA="}],"legacyImports":false}`,
|
Lock: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib.git","subdir":""}},"version":"ed7c1aff9e10d3b42fb130446d495f1c769ecd7b","sum":"OraOcUvDIx9Eikaihi8XsRNRsVehO75Ek35im/jYoSA="}],"legacyImports":false}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "single",
|
name: "single",
|
||||||
uris: []string{"github.com/jsonnet-bundler/frozen-lib"},
|
uris: []string{"github.com/jsonnet-bundler/frozen-lib"},
|
||||||
before: &RepoState{
|
before: &RepoState{
|
||||||
File: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/jsonnet-libs","subdir":"ksonnet-util"}},"version":"master"},{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib","subdir":""}},"version":"master"}],"legacyImports":true}`,
|
File: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/jsonnet-libs.git","subdir":"ksonnet-util"}},"version":"master"},{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib.git","subdir":""}},"version":"master"}],"legacyImports":true}`,
|
||||||
Lock: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/jsonnet-libs","subdir":"ksonnet-util"}},"version":"610b00d219d0a6f3d833dd44e4bb0deda2429da0","sum":"XdIrw3m7I8fJ3CL9eR8LtuYcanf2QK78n4H4OBBOADc="},{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib","subdir":""}},"version":"9f40207f668e382b706e1822f2d46ce2cd0a57cc","sum":"qUJDskVRtmkTms2udvFpLi1t5YKVbGmMSyiZnPjXsMo="}],"legacyImports":false}`,
|
Lock: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/jsonnet-libs.git","subdir":"ksonnet-util"}},"version":"610b00d219d0a6f3d833dd44e4bb0deda2429da0","sum":"XdIrw3m7I8fJ3CL9eR8LtuYcanf2QK78n4H4OBBOADc="},{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib.git","subdir":""}},"version":"9f40207f668e382b706e1822f2d46ce2cd0a57cc","sum":"qUJDskVRtmkTms2udvFpLi1t5YKVbGmMSyiZnPjXsMo="}],"legacyImports":false}`,
|
||||||
},
|
},
|
||||||
after: &RepoState{
|
after: &RepoState{
|
||||||
File: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/jsonnet-libs","subdir":"ksonnet-util"}},"version":"master"},{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib","subdir":""}},"version":"master"}],"legacyImports":true}`,
|
File: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/jsonnet-libs.git","subdir":"ksonnet-util"}},"version":"master"},{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib.git","subdir":""}},"version":"master"}],"legacyImports":true}`,
|
||||||
Lock: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/jsonnet-libs","subdir":"ksonnet-util"}},"version":"610b00d219d0a6f3d833dd44e4bb0deda2429da0","sum":"XdIrw3m7I8fJ3CL9eR8LtuYcanf2QK78n4H4OBBOADc="},{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib","subdir":""}},"version":"ed7c1aff9e10d3b42fb130446d495f1c769ecd7b","sum":"OraOcUvDIx9Eikaihi8XsRNRsVehO75Ek35im/jYoSA="}],"legacyImports":false}`,
|
Lock: `{"version":1,"dependencies":[{"source":{"git":{"remote":"https://github.com/grafana/jsonnet-libs.git","subdir":"ksonnet-util"}},"version":"610b00d219d0a6f3d833dd44e4bb0deda2429da0","sum":"XdIrw3m7I8fJ3CL9eR8LtuYcanf2QK78n4H4OBBOADc="},{"source":{"git":{"remote":"https://github.com/jsonnet-bundler/frozen-lib.git","subdir":""}},"version":"ed7c1aff9e10d3b42fb130446d495f1c769ecd7b","sum":"OraOcUvDIx9Eikaihi8XsRNRsVehO75Ek35im/jYoSA="}],"legacyImports":false}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,7 @@ func (p *GitPackage) Install(ctx context.Context, name, dir, version string) (st
|
||||||
defer os.RemoveAll(tmpDir)
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
// Optimization for GitHub sources: download a tarball archive of the requested
|
// Optimization for GitHub sources: download a tarball archive of the requested
|
||||||
// version instead of cloning the entire repository.
|
// version instead of cloning the entire
|
||||||
isGitHubRemote, err := regexp.MatchString(`^(https|ssh)://github\.com/.+$`, p.Source.Remote())
|
isGitHubRemote, err := regexp.MatchString(`^(https|ssh)://github\.com/.+$`, p.Source.Remote())
|
||||||
if isGitHubRemote {
|
if isGitHubRemote {
|
||||||
// Let git ls-remote decide if "version" is a ref or a commit SHA in the unlikely
|
// Let git ls-remote decide if "version" is a ref or a commit SHA in the unlikely
|
||||||
|
|
@ -197,7 +197,7 @@ func (p *GitPackage) Install(ctx context.Context, name, dir, version string) (st
|
||||||
commitSha = version
|
commitSha = version
|
||||||
}
|
}
|
||||||
|
|
||||||
archiveUrl := fmt.Sprintf("%s/archive/%s.tar.gz", p.Source.Remote(), commitSha)
|
archiveUrl := fmt.Sprintf("%s/archive/%s.tar.gz", strings.TrimSuffix(p.Source.Remote(), ".git"), commitSha)
|
||||||
archiveFilepath := fmt.Sprintf("%s.tar.gz", tmpDir)
|
archiveFilepath := fmt.Sprintf("%s.tar.gz", tmpDir)
|
||||||
|
|
||||||
defer os.Remove(archiveFilepath)
|
defer os.Remove(archiveFilepath)
|
||||||
|
|
|
||||||
|
|
@ -80,18 +80,18 @@ func (gs *Git) UnmarshalJSON(data []byte) error {
|
||||||
|
|
||||||
// Name returns the repository in a go-like format (example.com/user/repo/subdir)
|
// Name returns the repository in a go-like format (example.com/user/repo/subdir)
|
||||||
func (gs *Git) Name() string {
|
func (gs *Git) Name() string {
|
||||||
return fmt.Sprintf("%s/%s/%s%s", gs.Host, gs.User, gs.Repo, gs.Subdir)
|
return fmt.Sprintf("%s/%s/%s%s", gs.Host, gs.User, strings.TrimSuffix(gs.Repo, ".git"), gs.Subdir)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LegacyName returns the last element of the packages path
|
// LegacyName returns the last element of the packages path
|
||||||
// example: github.com/ksonnet/ksonnet-lib/ksonnet.beta.4 becomes ksonnet.beta.4
|
// example: github.com/ksonnet/ksonnet-lib/ksonnet.beta.4 becomes ksonnet.beta.4
|
||||||
func (gs *Git) LegacyName() string {
|
func (gs *Git) LegacyName() string {
|
||||||
return filepath.Base(gs.Repo + gs.Subdir)
|
return filepath.Base(strings.TrimSuffix(gs.Repo, ".git") + gs.Subdir)
|
||||||
}
|
}
|
||||||
|
|
||||||
var gitProtoFmts = map[string]string{
|
var gitProtoFmts = map[string]string{
|
||||||
GitSchemeSSH: GitSchemeSSH + "%s/%s/%s.git",
|
GitSchemeSSH: GitSchemeSSH + "%s/%s/%s.git",
|
||||||
GitSchemeHTTPS: GitSchemeHTTPS + "%s/%s/%s",
|
GitSchemeHTTPS: GitSchemeHTTPS + "%s/%s/%s.git",
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remote returns a remote string that can be passed to git
|
// Remote returns a remote string that can be passed to git
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ func TestParseGit(t *testing.T) {
|
||||||
Subdir: "/ksonnet.beta.3",
|
Subdir: "/ksonnet.beta.3",
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
wantRemote: "https://github.com/ksonnet/ksonnet-lib",
|
wantRemote: "https://github.com/ksonnet/ksonnet-lib.git",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ssh.ssh",
|
name: "ssh.ssh",
|
||||||
|
|
@ -82,7 +82,7 @@ func TestParseGit(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
wantRemote: "https://example.com/foo/bar",
|
wantRemote: "https://example.com/foo/bar.git",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ValidGitNoScheme",
|
name: "ValidGitNoScheme",
|
||||||
|
|
@ -99,7 +99,7 @@ func TestParseGit(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
wantRemote: "https://example.com/foo/bar",
|
wantRemote: "https://example.com/foo/bar.git",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ValidGitPath",
|
name: "ValidGitPath",
|
||||||
|
|
@ -116,7 +116,7 @@ func TestParseGit(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
wantRemote: "https://example.com/foo/bar",
|
wantRemote: "https://example.com/foo/bar.git",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ValidGitVersion",
|
name: "ValidGitVersion",
|
||||||
|
|
@ -133,7 +133,7 @@ func TestParseGit(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
wantRemote: "https://example.com/foo/bar",
|
wantRemote: "https://example.com/foo/bar.git",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ValidGitPathVersion",
|
name: "ValidGitPathVersion",
|
||||||
|
|
@ -150,7 +150,7 @@ func TestParseGit(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
wantRemote: "https://example.com/foo/bar",
|
wantRemote: "https://example.com/foo/bar.git",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ValidGitSubdomain",
|
name: "ValidGitSubdomain",
|
||||||
|
|
@ -167,7 +167,7 @@ func TestParseGit(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
wantRemote: "https://git.example.com/foo/bar",
|
wantRemote: "https://git.example.com/foo/bar.git",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ValidGitSubgroups",
|
name: "ValidGitSubgroups",
|
||||||
|
|
@ -184,7 +184,7 @@ func TestParseGit(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
wantRemote: "https://example.com/group/subgroup/repository",
|
wantRemote: "https://example.com/group/subgroup/repository.git",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ValidGitSubgroupSubDir",
|
name: "ValidGitSubgroupSubDir",
|
||||||
|
|
@ -201,7 +201,7 @@ func TestParseGit(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
wantRemote: "https://example.com/group/subgroup/repository",
|
wantRemote: "https://example.com/group/subgroup/repository.git",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ const jsonJF = `{
|
||||||
{
|
{
|
||||||
"source": {
|
"source": {
|
||||||
"git": {
|
"git": {
|
||||||
"remote": "https://github.com/grafana/jsonnet-libs",
|
"remote": "https://github.com/grafana/jsonnet-libs.git",
|
||||||
"subdir": "grafana-builder"
|
"subdir": "grafana-builder"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -41,7 +41,7 @@ const jsonJF = `{
|
||||||
"name": "prometheus",
|
"name": "prometheus",
|
||||||
"source": {
|
"source": {
|
||||||
"git": {
|
"git": {
|
||||||
"remote": "https://github.com/prometheus/prometheus",
|
"remote": "https://github.com/prometheus/prometheus.git",
|
||||||
"subdir": "documentation/prometheus-mixin"
|
"subdir": "documentation/prometheus-mixin"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue