MCPcopy Create free account
hub / github.com/github/gh-aw / TestImportCacheMultipleFiles

Function TestImportCacheMultipleFiles

pkg/parser/import_cache_integration_test.go:89–160  ·  view source on GitHub ↗

TestImportCacheMultipleFiles tests caching multiple files from different repos

(t *testing.T)

Source from the content-addressed store, hash-verified

87
88// TestImportCacheMultipleFiles tests caching multiple files from different repos
89func TestImportCacheMultipleFiles(t *testing.T) {
90 tempDir, err := os.MkdirTemp("", "import-cache-multi-*")
91 if err != nil {
92 t.Fatalf("Failed to create temp dir: %v", err)
93 }
94 defer os.RemoveAll(tempDir)
95
96 cache := NewImportCache(tempDir)
97
98 // Cache multiple files
99 files := []struct {
100 owner string
101 repo string
102 path string
103 ref string
104 sha string
105 content string
106 }{
107 {"owner1", "repo1", "workflows/a.md", "main", "sha1", "Content A"},
108 {"owner1", "repo1", "workflows/b.md", "v1.0", "sha2", "Content B"},
109 {"owner2", "repo2", "config/c.md", "main", "sha3", "Content C"},
110 }
111
112 for _, f := range files {
113 _, err := cache.Set(f.owner, f.repo, f.path, f.sha, []byte(f.content))
114 if err != nil {
115 t.Fatalf("Failed to cache file %s/%s/%s@%s: %v", f.owner, f.repo, f.path, f.sha, err)
116 }
117 }
118
119 // Verify all files are retrievable
120 for _, f := range files {
121 path, found := cache.Get(f.owner, f.repo, f.path, f.sha)
122 if !found {
123 t.Errorf("Failed to retrieve cached file %s/%s/%s@%s", f.owner, f.repo, f.path, f.sha)
124 continue
125 }
126
127 content, err := os.ReadFile(path)
128 if err != nil {
129 t.Errorf("Failed to read cached file: %v", err)
130 continue
131 }
132
133 if string(content) != f.content {
134 t.Errorf("Content mismatch for %s/%s/%s@%s. Expected %q, got %q",
135 f.owner, f.repo, f.path, f.sha, f.content, string(content))
136 }
137 }
138
139 // Verify from new cache instance using filesystem lookup
140 cache2 := NewImportCache(tempDir)
141
142 for _, f := range files {
143 path, found := cache2.Get(f.owner, f.repo, f.path, f.sha)
144 if !found {
145 t.Errorf("Failed to retrieve cached file from new instance %s/%s/%s@%s", f.owner, f.repo, f.path, f.sha)
146 continue

Callers

nothing calls this directly

Calls 4

SetMethod · 0.95
GetMethod · 0.95
NewImportCacheFunction · 0.85
ErrorfMethod · 0.45

Tested by

no test coverage detected