From f0e7a0bb80cb3f3bd61edd4270ba147a89e01634 Mon Sep 17 00:00:00 2001 From: "devsy-app[bot]" <277138668+devsy-app[bot]@users.noreply.github.com> Date: Fri, 14 Aug 2026 11:48:09 +0000 Subject: [PATCH] test(download): cover parseGithubURL branches Add table-driven tests for parseGithubURL covering latest/tagged releases and rejection cases. pkg/download previously had zero coverage for this branching path parser. --- pkg/download/download_test.go | 87 +++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/pkg/download/download_test.go b/pkg/download/download_test.go index 2bbfb5833c..e168e48f69 100644 --- a/pkg/download/download_test.go +++ b/pkg/download/download_test.go @@ -6,6 +6,13 @@ import ( const testBaseURL = "https://example.com/file.tgz" +const ( + testGithubOrg = "devsy-org" + testGithubRepo = "devsy" + testGithubFile = "devsy-linux-amd64" + testGithubTag = "v1.2.3" +) + func TestSanitizeURL(t *testing.T) { tests := []struct { name string @@ -38,3 +45,83 @@ func TestSanitizeURL(t *testing.T) { }) } } + +func TestParseGithubURLValid(t *testing.T) { + tests := []struct { + name string + path string + want githubReleaseRef + }{ + { + name: "latest release", + path: "/" + testGithubOrg + "/" + testGithubRepo + "/releases/latest/download/" + testGithubFile, + want: githubReleaseRef{ + org: testGithubOrg, + repo: testGithubRepo, + file: testGithubFile, + }, + }, + { + name: "tagged release", + path: "/" + testGithubOrg + "/" + testGithubRepo + "/releases/download/" + testGithubTag + "/" + testGithubFile, + want: githubReleaseRef{ + org: testGithubOrg, + repo: testGithubRepo, + release: testGithubTag, + file: testGithubFile, + }, + }, + { + name: "latest without leading slash", + path: testGithubOrg + "/" + testGithubRepo + "/releases/latest/download/" + testGithubFile, + want: githubReleaseRef{ + org: testGithubOrg, + repo: testGithubRepo, + file: testGithubFile, + }, + }, + { + name: "tagged without leading slash", + path: testGithubOrg + "/" + testGithubRepo + "/releases/download/" + testGithubTag + "/" + testGithubFile, + want: githubReleaseRef{ + org: testGithubOrg, + repo: testGithubRepo, + release: testGithubTag, + file: testGithubFile, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, ok := parseGithubURL(tt.path) + if !ok { + t.Fatalf("parseGithubURL(%q) ok = false, want true", tt.path) + } + if got != tt.want { + t.Errorf("parseGithubURL(%q) = %+v, want %+v", tt.path, got, tt.want) + } + }) + } +} + +func TestParseGithubURLInvalid(t *testing.T) { + tests := []struct { + name string + path string + }{ + {name: "too few segments", path: "/devsy-org/devsy/releases/latest/download"}, + {name: "too many segments", path: "/devsy-org/devsy/releases/latest/download/dir/file"}, + {name: "missing releases segment", path: "/devsy-org/devsy/archive/v1.2.3/file"}, + {name: "unknown middle segment", path: "/devsy-org/devsy/releases/foo/download/file"}, + {name: "latest without download", path: "/devsy-org/devsy/releases/latest/file"}, + {name: "empty path", path: ""}, + {name: "root slash", path: "/"}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if _, ok := parseGithubURL(tt.path); ok { + t.Errorf("parseGithubURL(%q) ok = true, want false", tt.path) + } + }) + } +}