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
77 lines
2.0 KiB
Go
77 lines
2.0 KiB
Go
package util
|
|
|
|
import (
|
|
"runtime"
|
|
"testing"
|
|
)
|
|
|
|
func TestResolveGitHubToken(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
githubToken string
|
|
lowerToken string
|
|
gitStoreToken string
|
|
gitStoreURL string
|
|
want string
|
|
}{
|
|
{
|
|
name: "GITHUB_TOKEN has highest priority",
|
|
githubToken: " primary-token ",
|
|
lowerToken: "lower-token",
|
|
gitStoreToken: "gitstore-token",
|
|
gitStoreURL: "https://github.com/example/repo.git",
|
|
want: "primary-token",
|
|
},
|
|
{
|
|
name: "lowercase token is second priority",
|
|
githubToken: " ",
|
|
lowerToken: " lower-token ",
|
|
gitStoreToken: "gitstore-token",
|
|
gitStoreURL: "https://github.com/example/repo.git",
|
|
want: "lower-token",
|
|
},
|
|
{
|
|
name: "Git store token is used for GitHub",
|
|
gitStoreToken: " gitstore-token ",
|
|
gitStoreURL: "HTTPS://GITHUB.COM/example/repo.git",
|
|
want: "gitstore-token",
|
|
},
|
|
{
|
|
name: "Git store token is ignored for other hosts",
|
|
gitStoreToken: "gitstore-token",
|
|
gitStoreURL: "https://gitlab.com/example/repo.git",
|
|
},
|
|
{
|
|
name: "Git store token is ignored without URL",
|
|
gitStoreToken: "gitstore-token",
|
|
},
|
|
{
|
|
name: "no token configured",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if runtime.GOOS == "windows" && tt.name == "GITHUB_TOKEN has highest priority" {
|
|
t.Skip("environment variables are case-insensitive on Windows")
|
|
}
|
|
if tt.githubToken != "" {
|
|
t.Setenv("GITHUB_TOKEN", tt.githubToken)
|
|
}
|
|
if tt.lowerToken != "" {
|
|
t.Setenv("github_token", tt.lowerToken)
|
|
}
|
|
if tt.githubToken == "" && tt.lowerToken == "" {
|
|
t.Setenv("GITHUB_TOKEN", "")
|
|
t.Setenv("github_token", "")
|
|
}
|
|
t.Setenv("GITSTORE_GIT_TOKEN", tt.gitStoreToken)
|
|
t.Setenv("GITSTORE_GIT_URL", tt.gitStoreURL)
|
|
|
|
if got := ResolveGitHubToken(); got != tt.want {
|
|
t.Fatalf("ResolveGitHubToken() = %q, want %q", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|