(t *testing.T)
| 449 | } |
| 450 | |
| 451 | func TestGitPluginFileContentCache(t *testing.T) { |
| 452 | // Clear the git cache before and after the test to avoid pollution. |
| 453 | if err := gitCache.Clear(); err != nil { |
| 454 | t.Fatal(err) |
| 455 | } |
| 456 | t.Cleanup(func() { _ = gitCache.Clear() }) |
| 457 | |
| 458 | repoURL := setupLocalGitRepo(t, `{"name": "test-plugin"}`) |
| 459 | |
| 460 | plugin := &gitPlugin{ |
| 461 | ref: &flake.Ref{ |
| 462 | Type: flake.TypeGit, |
| 463 | URL: repoURL, |
| 464 | Ref: "main", |
| 465 | }, |
| 466 | name: "test-cache-plugin", |
| 467 | } |
| 468 | |
| 469 | // First call — populates the cache via git clone. |
| 470 | content1, err := plugin.FileContent("plugin.json") |
| 471 | if err != nil { |
| 472 | t.Fatalf("first FileContent call failed: %v", err) |
| 473 | } |
| 474 | if string(content1) != `{"name": "test-plugin"}` { |
| 475 | t.Fatalf("unexpected content: %s", content1) |
| 476 | } |
| 477 | |
| 478 | // Delete the source repo. If the cache is working, FileContent should |
| 479 | // still return the cached value without attempting a clone. |
| 480 | repoPath := repoURL[len("file://"):] |
| 481 | if err := os.RemoveAll(repoPath); err != nil { |
| 482 | t.Fatalf("failed to remove repo: %v", err) |
| 483 | } |
| 484 | |
| 485 | content2, err := plugin.FileContent("plugin.json") |
| 486 | if err != nil { |
| 487 | t.Fatalf("second FileContent call should have used cache but failed: %v", err) |
| 488 | } |
| 489 | if string(content2) != string(content1) { |
| 490 | t.Fatalf("cached content mismatch: got %s, want %s", content2, content1) |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | func TestGitPluginFileContentCacheRespectsEnvVar(t *testing.T) { |
| 495 | if err := gitCache.Clear(); err != nil { |
nothing calls this directly
no test coverage detected