TestImportCacheIntegration tests the cache with the full import flow
(t *testing.T)
| 10 | |
| 11 | // TestImportCacheIntegration tests the cache with the full import flow |
| 12 | func 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 := `--- |
| 25 | imports: |
| 26 | - testowner/testrepo/workflows/shared.md@main |
| 27 | --- |
| 28 | |
| 29 | # Test Workflow |
| 30 | |
| 31 | Use 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(`--- |
| 41 | tools: |
| 42 | edit: |
| 43 | --- |
| 44 | |
| 45 | # Shared Configuration |
| 46 | |
| 47 | This 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) |
nothing calls this directly
no test coverage detected