b21ef5c0bb
- Add --changes PATH and --changes-from REF flags to glint check and glint graph
for rules:changes: evaluation. --changes marks files explicitly; --changes-from
runs git diff --name-only <REF> automatically. Both flags can be combined.
- Implement doublestar glob matching (*, ** across path segments) in EvalJob and
EvalWorkflow; extended {paths, compare_to} map form supported.
- Without --changes/--changes-from the condition stays permissive (existing behaviour).
- Context summary line now shows changed-file count when file data is provided.
- Achieve 100% statement coverage: comprehensive tests added across all packages;
removed provably dead code; added testability seams (exit, userHomeDirFn,
execCommandOutput variables) to cover previously unreachable paths.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
74 lines
1.9 KiB
Go
74 lines
1.9 KiB
Go
package fetcher
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestCachePath(t *testing.T) {
|
|
p1 := cachePath("/tmp/cache", "key1")
|
|
p2 := cachePath("/tmp/cache", "key2")
|
|
if p1 == p2 {
|
|
t.Error("different keys should produce different paths")
|
|
}
|
|
if filepath.Dir(p1) != "/tmp/cache" {
|
|
t.Errorf("expected /tmp/cache dir, got %q", filepath.Dir(p1))
|
|
}
|
|
}
|
|
|
|
func TestCacheReadMiss(t *testing.T) {
|
|
// empty dir → miss
|
|
data, ok := cacheRead("", "key")
|
|
if ok || data != nil {
|
|
t.Error("empty cacheDir should always miss")
|
|
}
|
|
|
|
// nonexistent entry → miss
|
|
data, ok = cacheRead(t.TempDir(), "nonexistent-key")
|
|
if ok || data != nil {
|
|
t.Error("missing cache entry should miss")
|
|
}
|
|
}
|
|
|
|
func TestCacheWriteAndRead(t *testing.T) {
|
|
dir := t.TempDir()
|
|
key := "https://example.com/template.yml"
|
|
content := []byte("stages: [build]")
|
|
|
|
cacheWrite(dir, key, content)
|
|
|
|
got, ok := cacheRead(dir, key)
|
|
if !ok {
|
|
t.Fatal("expected cache hit after write")
|
|
}
|
|
if string(got) != string(content) {
|
|
t.Errorf("cached content mismatch: got %q want %q", got, content)
|
|
}
|
|
}
|
|
|
|
func TestCacheWrite_EmptyDir(t *testing.T) {
|
|
// Should silently do nothing when dir is empty string.
|
|
cacheWrite("", "key", []byte("data"))
|
|
}
|
|
|
|
// TestCacheWrite_DirIsFile covers the os.MkdirAll error path (cache.go:29-31)
|
|
// when the cache dir path is occupied by a regular file.
|
|
func TestCacheWrite_DirIsFile(t *testing.T) {
|
|
f := filepath.Join(t.TempDir(), "file")
|
|
if err := os.WriteFile(f, []byte("occupied"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// MkdirAll(f) fails because f is a file, not a directory.
|
|
cacheWrite(f, "key", []byte("data"))
|
|
// No panic, no error returned — the function silently returns.
|
|
}
|
|
|
|
func TestCacheWrite_MkdirAll(t *testing.T) {
|
|
dir := filepath.Join(t.TempDir(), "sub", "dir")
|
|
cacheWrite(dir, "k", []byte("v"))
|
|
if _, err := os.Stat(dir); err != nil {
|
|
t.Errorf("directory not created: %v", err)
|
|
}
|
|
}
|