Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/backend/drivers/github_releases/util.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import test from "node:test"
import assert from "node:assert/strict"
import { ClientGithubReleases } from "./util"

function clientWith(ghProxy?: string): ClientGithubReleases {
return new ClientGithubReleases({
repo_structure: "example/repo",
...(ghProxy !== undefined ? { gh_proxy: ghProxy } : {}),
})
}

function proxyOf(additionGhProxy: string | undefined, url: string): string {
const client = clientWith(additionGhProxy)
// proxy() 为私有方法,测试中通过索引访问
return (client as unknown as { proxy: (u: string) => string }).proxy(url)
}

test("gh_proxy 已配置时为 http(s) 下载链接加代理前缀", () => {
const url = "https://github.com/example/repo/releases/download/v1.0.0/app.zip"
assert.equal(
proxyOf("https://mirror.example.com", url),
"https://mirror.example.com" + url,
)
})

test("gh_proxy 未配置时保持原链接不变", () => {
const url = "https://github.com/example/repo/releases/download/v1.0.0/app.zip"
assert.equal(proxyOf(undefined, url), url)
assert.equal(proxyOf("", url), url)
})

test("gh_proxy 已配置但链接非 http 开头时不加前缀(对齐上游 Go 版语义)", () => {
assert.equal(
proxyOf("https://mirror.example.com", "/relative/path"),
"/relative/path",
)
})
4 changes: 2 additions & 2 deletions src/backend/drivers/github_releases/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ export class ClientGithubReleases {

private proxy(url: string): string {
const p = this.addition.gh_proxy || ""
if (!p || url.startsWith("http")) return url
return p + url
if (p && url.startsWith("http")) return p + url
return url
}

/** 解析挂载点对应的 org/repo */
Expand Down