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

Function TestImportCacheIntegration

pkg/parser/import_cache_integration_test.go:12–86  ·  view source on GitHub ↗

TestImportCacheIntegration tests the cache with the full import flow

(t *testing.T)

Source from the content-addressed store, hash-verified

10
11// TestImportCacheIntegration tests the cache with the full import flow
12func TestImportCacheIntegration(t *testing.T) {
13 // Create temp directories for testing
14 tempDir, err := os.MkdirTemp("", "import-cache-integration-*")
15 if err != nil {
16 t.Fatalf("Failed to create temp dir: %v", err)
17 }
18 defer os.RemoveAll(tempDir)
19
20 // Create a cache
21 cache := NewImportCache(tempDir)
22
23 // Simulate a workflow file that imports from another repo
24 workflowContent := `---
25imports:
26 - testowner/testrepo/workflows/shared.md@main
27---
28
29# Test Workflow
30
31Use shared configuration.
32`
33
34 workflowPath := filepath.Join(tempDir, "test-workflow.md")
35 if err := os.WriteFile(workflowPath, []byte(workflowContent), 0644); err != nil {
36 t.Fatalf("Failed to write workflow file: %v", err)
37 }
38
39 // Simulate a remote file being cached
40 sharedContent := []byte(`---
41tools:
42 edit:
43---
44
45# Shared Configuration
46
47This is shared configuration.
48`)
49
50 // Cache the "remote" file
51 sha := "abc123"
52 cachedPath, err := cache.Set("testowner", "testrepo", "workflows/shared.md", sha, sharedContent)
53 if err != nil {
54 t.Fatalf("Failed to cache file: %v", err)
55 }
56
57 // Verify cache can retrieve the file
58 retrievedPath, found := cache.Get("testowner", "testrepo", "workflows/shared.md", sha)
59 if !found {
60 t.Error("Failed to retrieve cached file")
61 }
62 if retrievedPath != cachedPath {
63 t.Errorf("Retrieved path mismatch. Expected %s, got %s", cachedPath, retrievedPath)
64 }
65
66 // Verify the cached file contains correct content
67 content, err := os.ReadFile(retrievedPath)
68 if err != nil {
69 t.Fatalf("Failed to read cached file: %v", err)

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected