-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update tests, unexport highest patch function
- Loading branch information
1 parent
843b5d5
commit aed3a22
Showing
2 changed files
with
70 additions
and
29 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
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 |
---|---|---|
|
@@ -64,6 +64,36 @@ func testImage(t *testing.T, context spec.G, it spec.S) { | |
] | ||
}`) | ||
|
||
case "/v1/buildpacks/no-new-patch": | ||
w.WriteHeader(http.StatusOK) | ||
fmt.Fprintln(w, `{ | ||
"latest": { | ||
"version": "0.1.0" | ||
}, | ||
"versions": [ | ||
{ | ||
"version": "0.1.0", | ||
"_link": "https://registry.buildpacks.io//api/v1/buildpacks/no-new-patch/0.1.0" | ||
}, | ||
{ | ||
"version": "0.0.3-rc", | ||
"_link": "https://registry.buildpacks.io//api/v1/buildpacks/no-new-patch/0.0.3-beta.1" | ||
}, | ||
{ | ||
"version": "random-version", | ||
"_link": "https://registry.buildpacks.io//api/v1/buildpacks/no-new-patch/0.0.3-random-version" | ||
}, | ||
{ | ||
"version": "0.0.2-rc", | ||
"_link": "https://registry.buildpacks.io//api/v1/buildpacks/no-new-patch/0.0.2-rc" | ||
}, | ||
{ | ||
"version": "0.0.1", | ||
"_link": "https://registry.buildpacks.io//api/v1/buildpacks/no-new-patch/0.0.1" | ||
} | ||
] | ||
}`) | ||
|
||
case "/v1/buildpacks/paketo-buildpacks/go": | ||
w.WriteHeader(http.StatusOK) | ||
fmt.Fprintln(w, `{ | ||
|
@@ -146,6 +176,18 @@ func testImage(t *testing.T, context spec.G, it spec.S) { | |
Version: "0.0.3", | ||
})) | ||
}) | ||
|
||
context("there are newer patches available, but they are pre-releases or not semantically versioned", func() { | ||
it("returns the highest semantically versioned regular patch", func() { | ||
image, err := internal.FindLatestImageOnCNBRegistry("urn:cnb:registry:[email protected]", server.URL, "0.0.1") | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(image).To(Equal(internal.Image{ | ||
Name: "urn:cnb:registry:no-new-patch", | ||
Path: "no-new-patch", | ||
Version: "0.0.1", | ||
})) | ||
}) | ||
}) | ||
}) | ||
|
||
context("failure cases", func() { | ||
|
@@ -206,6 +248,18 @@ func testImage(t *testing.T, context spec.G, it spec.S) { | |
] | ||
}`) | ||
|
||
case "/v2/some-org/no-new-patch/tags/list": | ||
w.WriteHeader(http.StatusOK) | ||
fmt.Fprintln(w, `{ | ||
"tags": [ | ||
"0.0.1", | ||
"0.0.2-bad-version", | ||
"0.0.3-rc", | ||
"0.1.0", | ||
"latest" | ||
] | ||
}`) | ||
|
||
case "/v2/some-org/some-other-repo/tags/list": | ||
w.WriteHeader(http.StatusOK) | ||
fmt.Fprintln(w, `{ | ||
|
@@ -270,6 +324,18 @@ func testImage(t *testing.T, context spec.G, it spec.S) { | |
Version: "0.0.10", | ||
})) | ||
}) | ||
|
||
context("there are newer patches available, but they are pre-releases or not semantically versioned", func() { | ||
it("returns the highest semantically versioned regular patch", func() { | ||
image, err := internal.FindLatestImage(fmt.Sprintf("%s/some-org/no-new-patch:0.0.1", strings.TrimPrefix(server.URL, "http://")), "0.0.1") | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(image).To(Equal(internal.Image{ | ||
Name: fmt.Sprintf("%s/some-org/no-new-patch", strings.TrimPrefix(server.URL, "http://")), | ||
Path: "some-org/no-new-patch", | ||
Version: "0.0.1", | ||
})) | ||
}) | ||
}) | ||
}) | ||
|
||
context("failure cases", func() { | ||
|
@@ -506,29 +572,4 @@ func testImage(t *testing.T, context spec.G, it spec.S) { | |
}) | ||
}) | ||
}) | ||
|
||
context("GetHighestPatch", func() { | ||
it("returns the highest patch version in a minor version line given a patch", func() { | ||
version, err := internal.GetHighestPatch("1.2.3", []string{"0.0.1", "0.0.2", "1.2.3", "1.2.4", "1.3.0", "2.3.4"}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(version).To(Equal("1.2.4")) | ||
}) | ||
|
||
context("the patch version provided is already the highest patch available", func() { | ||
it("returns the given patch version", func() { | ||
version, err := internal.GetHighestPatch("1.2.4", []string{"0.0.1", "0.0.2", "1.2.3", "1.2.4", "1.3.0", "2.3.4"}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(version).To(Equal("1.2.4")) | ||
}) | ||
}) | ||
|
||
context("failure cases", func() { | ||
context("the patch version given is not a semantic version", func() { | ||
it("returns an error", func() { | ||
_, err := internal.GetHighestPatch("bad-version", []string{"0.0.1", "0.0.2", "1.2.3", "1.2.4", "1.3.0", "2.3.4"}) | ||
Expect(err).To(MatchError(ContainSubstring("version constraint ~bad-version is not a valid semantic version constraint"))) | ||
}) | ||
}) | ||
}) | ||
}) | ||
} |