Files
wehub-resource-sync a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

55 lines
1.5 KiB
Go

package parity
import (
"os"
"path/filepath"
"strings"
"testing"
)
func TestBenchRepos(t *testing.T) {
repos := BenchRepos()
if len(repos) == 0 {
t.Fatal("benchmark corpus is empty")
}
seen := map[string]bool{}
for _, r := range repos {
if r.Language == "" || r.URL == "" {
t.Errorf("malformed bench repo: %+v", r)
}
if !strings.HasPrefix(r.URL, "https://") {
t.Errorf("bench repo URL is not https: %q", r.URL)
}
if seen[r.Language] {
t.Errorf("duplicate language in corpus: %q", r.Language)
}
seen[r.Language] = true
if repoDirName(r) == "" || strings.ContainsAny(repoDirName(r), "/\\") {
t.Errorf("unsafe cache dir name %q for %+v", repoDirName(r), r)
}
}
// BenchRepos returns a copy — mutating it must not affect the source list.
repos[0].URL = "mutated"
if BenchRepos()[0].URL == "mutated" {
t.Error("BenchRepos leaked a reference to the frozen corpus")
}
}
func TestEnsureRepoCacheHit(t *testing.T) {
cacheDir := t.TempDir()
repo := BenchRepo{Language: "go", URL: "https://github.com/example/widget"}
// Simulate a prior checkout — EnsureRepo must reuse it without cloning.
dir := filepath.Join(cacheDir, repoDirName(repo))
if err := os.MkdirAll(filepath.Join(dir, ".git"), 0o755); err != nil {
t.Fatal(err)
}
got, err := EnsureRepo(cacheDir, repo)
if err != nil {
t.Fatalf("EnsureRepo cache hit errored (did it try to clone?): %v", err)
}
if got != dir {
t.Errorf("EnsureRepo = %q, want cached %q", got, dir)
}
}