Skip to content

Commit

Permalink
simplified use of strings split function and added additional tests f…
Browse files Browse the repository at this point in the history
…or skip-path feature
  • Loading branch information
bitgully committed Oct 9, 2024
1 parent e9477c7 commit 5ec2997
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dependency_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func parseMirror(mirror string) map[string]string {
}

// Split mirror string at commas and extract specified arguments.
for _, arg := range strings.SplitN(mirror, ",", -1) {
for _, arg := range strings.Split(mirror, ",") {
argPair := strings.SplitN(arg, "=", 2)
// If a URI is provided without the key 'mirror=', still treat it as the 'mirror' argument.
// This addresses backwards compatibility and user experience as most mirrors won't need any additional arguments.
Expand Down
33 changes: 32 additions & 1 deletion dependency_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ func testDependencyCache(t *testing.T, context spec.G, it spec.S) {
Expect(io.ReadAll(a)).To(Equal([]byte("test-fixture")))
})

it("respects skip-path argument", func() {
it("respects skip-path argument without mirror= key", func() {
mirrorUrl, err := url.Parse(mirrorServer.URL())
Expect(err).NotTo(HaveOccurred())
mirrorServer.AppendHandlers(ghttp.CombineHandlers(
Expand All @@ -482,6 +482,37 @@ func testDependencyCache(t *testing.T, context spec.G, it spec.S) {

Expect(io.ReadAll(a)).To(Equal([]byte("test-fixture")))
})

it("respects skip-path argument with mirror= key", func() {
mirrorUrl, err := url.Parse(mirrorServer.URL())
Expect(err).NotTo(HaveOccurred())
mirrorServer.AppendHandlers(ghttp.CombineHandlers(
ghttp.VerifyRequest(http.MethodGet, "/test-skip", ""),
ghttp.RespondWith(http.StatusOK, "test-fixture"),
))

dependencyCache.DependencyMirrors["127.0.0.1"] = "mirror=" + mirrorUrl.Scheme + "://" + mirrorUrl.Host + "/test-skip,skip-path=/test-path"
a, err := dependencyCache.Artifact(dependency)
Expect(err).NotTo(HaveOccurred())

Expect(io.ReadAll(a)).To(Equal([]byte("test-fixture")))
})

it("respects skip-path argument when URL encoded", func() {
mirrorUrl, err := url.Parse(mirrorServer.URL())
Expect(err).NotTo(HaveOccurred())
mirrorServer.AppendHandlers(ghttp.CombineHandlers(
ghttp.VerifyRequest(http.MethodGet, "/test-skip", ""),
ghttp.RespondWith(http.StatusOK, "test-fixture"),
))

dependencyCache.DependencyMirrors["127.0.0.1"] = mirrorUrl.Scheme + "://" + mirrorUrl.Host + "/test-skip,skip-path=/test%2Cpath"
dependency.URI = fmt.Sprintf("%s/test,path", server.URL())
a, err := dependencyCache.Artifact(dependency)
Expect(err).NotTo(HaveOccurred())

Expect(io.ReadAll(a)).To(Equal([]byte("test-fixture")))
})
})

it("fails with invalid SHA256", func() {
Expand Down

0 comments on commit 5ec2997

Please sign in to comment.