mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-09-03 06:35:00 +08:00
- Support CRLF line endings and skip hidden dot directories in nocopy invariant tests. - Handle environment variable overrides and skip case-sensitive token priority tests on Windows. - Use static OS and architecture values in Claude header fingerprint assertions for deterministic test results. Closes: #5295
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package management
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestSetLatestReleaseRequestHeaders(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
githubToken string
|
|
wantAuthorization string
|
|
}{
|
|
{
|
|
name: "sets GitHub authorization",
|
|
githubToken: "release-token",
|
|
wantAuthorization: "Bearer release-token",
|
|
},
|
|
{
|
|
name: "omits authorization without token",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Setenv("GITHUB_TOKEN", tt.githubToken)
|
|
if tt.githubToken == "" {
|
|
t.Setenv("github_token", "")
|
|
}
|
|
t.Setenv("GITSTORE_GIT_TOKEN", "")
|
|
t.Setenv("GITSTORE_GIT_URL", "")
|
|
|
|
req := httptest.NewRequest(http.MethodGet, latestReleaseURL, nil)
|
|
setLatestReleaseRequestHeaders(req)
|
|
|
|
if got := req.Header.Get("Authorization"); got != tt.wantAuthorization {
|
|
t.Fatalf("Authorization = %q, want %q", got, tt.wantAuthorization)
|
|
}
|
|
if got := req.Header.Get("Accept"); got != "application/vnd.github+json" {
|
|
t.Fatalf("Accept = %q, want GitHub JSON media type", got)
|
|
}
|
|
if got := req.Header.Get("User-Agent"); got != latestReleaseUserAgent {
|
|
t.Fatalf("User-Agent = %q, want %q", got, latestReleaseUserAgent)
|
|
}
|
|
})
|
|
}
|
|
}
|