-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #338 from SimonErm/bugfix/alternative-package-id
Bugfix/alternative package-id
- Loading branch information
Showing
2 changed files
with
25 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -241,9 +241,12 @@ func (c CargoRunner) WorkspaceMembers(srcDir string, destLayer libcnb.Layer) ([] | |
|
||
// parseWorkspaceMember parses a workspace member which can be in a couple of different formats | ||
// | ||
// pre-1.77: `package-name package-version (url)`, like `function 0.1.0 (path+file:///Users/dmikusa/Downloads/fn-rs)` | ||
// 1.77+: `url#package-name@package-version` like `path+file:///Users/dmikusa/Downloads/fn-rs#[email protected]` | ||
// pre-1.77: `package-name package-version (url)`, like `function 0.1.0 (path+file:///Users/dmikusa/Downloads/fn-rs)` | ||
// 1.77+: | ||
// - `url#package-name@package-version` like `path+file:///Users/dmikusa/Downloads/fn-rs#[email protected]` | ||
// - `url#version` for local packages where the workspace member name is equal to the directory name like `path+file:///Users/jondoe/.../services/example-transform#0.1.0` | ||
// | ||
// The final directory is assumed to be the package name with the local package format. | ||
// returns the package name, version, URL, and optional error in that order | ||
func ParseWorkspaceMember(workspaceMember string) (string, string, string, error) { | ||
if strings.HasPrefix(workspaceMember, "path+file://") { | ||
|
@@ -253,11 +256,15 @@ func ParseWorkspaceMember(workspaceMember string) (string, string, string, error | |
} | ||
|
||
otherHalf := strings.SplitN(half[1], "@", 2) | ||
if len(otherHalf) != 2 { | ||
return "", "", "", fmt.Errorf("unable to parse workspace member [%s], missing `@`", workspaceMember) | ||
if len(otherHalf) == 2 { | ||
return strings.TrimSpace(otherHalf[0]), strings.TrimSpace(otherHalf[1]), strings.TrimSpace(half[0]), nil | ||
} else { | ||
splitIndex := strings.LastIndex(half[0], "/") | ||
path := half[0][:splitIndex] | ||
pkgName := half[0][splitIndex+1:] | ||
return strings.TrimSpace(pkgName), strings.TrimSpace(half[1]), strings.TrimSpace(path), nil | ||
} | ||
|
||
return strings.TrimSpace(otherHalf[0]), strings.TrimSpace(otherHalf[1]), strings.TrimSpace(half[0]), nil | ||
} else { | ||
// This is OK because the workspace member format is `package-name package-version (url)` and | ||
// none of name, version or URL may contain a space & be valid | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -471,6 +471,7 @@ func testRunners(t *testing.T, context spec.G, it spec.S) { | |
"path+file:///workspace/todo#[email protected]", | ||
"path+file:///workspace/routes#[email protected]", | ||
"path+file:///workspace/jokes#[email protected]", | ||
"path+file:///workspace/other-format/other-format#1.0.0", | ||
}) | ||
|
||
executor.On("Execute", mock.MatchedBy(func(ex effect.Execution) bool { | ||
|
@@ -490,7 +491,7 @@ func testRunners(t *testing.T, context spec.G, it spec.S) { | |
urls, err := runner.WorkspaceMembers(workingDir, destLayer) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
Expect(urls).To(HaveLen(4)) | ||
Expect(urls).To(HaveLen(5)) | ||
|
||
url, err := url.Parse("path+file:///workspace/basics") | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
@@ -507,6 +508,10 @@ func testRunners(t *testing.T, context spec.G, it spec.S) { | |
url, err = url.Parse("path+file:///workspace/jokes") | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(urls[3]).To(Equal(*url)) | ||
|
||
url, err = url.Parse("path+file:///workspace/other-format") | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(urls[4]).To(Equal(*url)) | ||
}) | ||
}) | ||
|
||
|
@@ -830,16 +835,17 @@ func testRunners(t *testing.T, context spec.G, it spec.S) { | |
Expect(version).To(Equal("2.0.0")) | ||
Expect(url).To(Equal("path+file:///workspace/basics")) | ||
}) | ||
|
||
it("parses alternative package-id", func() { | ||
pkgName, version, url, err := runner.ParseWorkspaceMember("path+file:///workspace/basics/basics#2.0.0") | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(pkgName).To(Equal("basics")) | ||
Expect(version).To(Equal("2.0.0")) | ||
Expect(url).To(Equal("path+file:///workspace/basics")) | ||
}) | ||
it("fails to parse because there is no hash sign", func() { | ||
_, _, _, err := runner.ParseWorkspaceMember("path+file:///workspace/basics") | ||
Expect(err).To(MatchError("unable to parse workspace member [path+file:///workspace/basics], missing `#`")) | ||
}) | ||
|
||
it("fails to parse because there is no at sign", func() { | ||
_, _, _, err := runner.ParseWorkspaceMember("path+file:///workspace/basics#foo") | ||
Expect(err).To(MatchError("unable to parse workspace member [path+file:///workspace/basics#foo], missing `@`")) | ||
}) | ||
}) | ||
}) | ||
} | ||
|