(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func TestImportCache(t *testing.T) { |
| 15 | const ( |
| 16 | owner = "testowner" |
| 17 | repo = "testrepo" |
| 18 | path = "workflows/test.md" |
| 19 | sha = "abc123" |
| 20 | ) |
| 21 | testContent := []byte("# Test Workflow\n\nTest content") |
| 22 | |
| 23 | t.Run("Set creates file and returns path", func(t *testing.T) { |
| 24 | cache := NewImportCache(t.TempDir()) |
| 25 | cachedPath, err := cache.Set(owner, repo, path, sha, testContent) |
| 26 | require.NoError(t, err, "Set should succeed for valid inputs") |
| 27 | require.FileExists(t, cachedPath, "cache file should be created at expected path") |
| 28 | }) |
| 29 | |
| 30 | t.Run("Get returns cached path after Set", func(t *testing.T) { |
| 31 | cache := NewImportCache(t.TempDir()) |
| 32 | cachedPath, err := cache.Set(owner, repo, path, sha, testContent) |
| 33 | require.NoError(t, err, "Set should succeed for valid inputs") |
| 34 | retrievedPath, found := cache.Get(owner, repo, path, sha) |
| 35 | assert.True(t, found, "cache entry should be found after Set") |
| 36 | assert.Equal(t, cachedPath, retrievedPath, "retrieved path should match path returned by Set") |
| 37 | }) |
| 38 | |
| 39 | t.Run("Cached file content matches original", func(t *testing.T) { |
| 40 | cache := NewImportCache(t.TempDir()) |
| 41 | cachedPath, err := cache.Set(owner, repo, path, sha, testContent) |
| 42 | require.NoError(t, err, "Set should succeed") |
| 43 | content, err := os.ReadFile(cachedPath) |
| 44 | require.NoError(t, err, "reading cached file should succeed") |
| 45 | assert.Equal(t, string(testContent), string(content), "cached content should match original") |
| 46 | }) |
| 47 | |
| 48 | t.Run("New cache instance finds existing entry", func(t *testing.T) { |
| 49 | tempDir := t.TempDir() |
| 50 | cache := NewImportCache(tempDir) |
| 51 | cachedPath, err := cache.Set(owner, repo, path, sha, testContent) |
| 52 | require.NoError(t, err, "Set should succeed for valid inputs") |
| 53 | cache2 := NewImportCache(tempDir) |
| 54 | retrievedPath2, found := cache2.Get(owner, repo, path, sha) |
| 55 | assert.True(t, found, "cache entry should be found from new cache instance") |
| 56 | assert.Equal(t, cachedPath, retrievedPath2, "path from new instance should match original") |
| 57 | }) |
| 58 | } |
| 59 | |
| 60 | func TestImportCacheDirectory(t *testing.T) { |
| 61 | tempDir := t.TempDir() |
nothing calls this directly
no test coverage detected