diff --git a/dependency_cache.go b/dependency_cache.go index 65470e8..9046659 100644 --- a/dependency_cache.go +++ b/dependency_cache.go @@ -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. diff --git a/dependency_cache_test.go b/dependency_cache_test.go index 389e775..9a8a2f0 100644 --- a/dependency_cache_test.go +++ b/dependency_cache_test.go @@ -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( @@ -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() {