MCPcopy
hub / github.com/helmfile/helmfile / TestIsSharedCachePath

Function TestIsSharedCachePath

pkg/state/oci_chart_lock_test.go:495–593  ·  view source on GitHub ↗

TestIsSharedCachePath tests the isSharedCachePath function to ensure it correctly identifies paths within the shared cache directory.

(t *testing.T)

Source from the content-addressed store, hash-verified

493// TestIsSharedCachePath tests the isSharedCachePath function to ensure it correctly
494// identifies paths within the shared cache directory.
495func TestIsSharedCachePath(t *testing.T) {
496 t.Run("path in shared cache is detected", func(t *testing.T) {
497 // Create a HelmState with test logger
498 logger := createTestLogger(t)
499 st := &HelmState{
500 logger: logger,
501 fs: filesystem.DefaultFileSystem(),
502 }
503
504 // Get the shared cache directory
505 sharedCacheDir := remote.CacheDir()
506
507 // Test path inside shared cache
508 chartPath := filepath.Join(sharedCacheDir, "envoyproxy", "gateway-helm", "1.6.2", "gateway-helm")
509 require.True(t, st.isSharedCachePath(chartPath), "path in shared cache should return true")
510 })
511
512 t.Run("path outside shared cache is not detected", func(t *testing.T) {
513 logger := createTestLogger(t)
514 st := &HelmState{
515 logger: logger,
516 fs: filesystem.DefaultFileSystem(),
517 }
518
519 // Test path outside shared cache (temp directory)
520 tempDir, err := os.MkdirTemp("", "helmfile-test-*")
521 require.NoError(t, err)
522 defer os.RemoveAll(tempDir)
523
524 chartPath := filepath.Join(tempDir, "mychart")
525 require.False(t, st.isSharedCachePath(chartPath), "path outside shared cache should return false")
526 })
527
528 t.Run("relative path handling", func(t *testing.T) {
529 logger := createTestLogger(t)
530 st := &HelmState{
531 logger: logger,
532 fs: filesystem.DefaultFileSystem(),
533 }
534
535 // Test relative path
536 require.False(t, st.isSharedCachePath("./relative/path"), "relative path should return false")
537 })
538
539 t.Run("shared cache path as prefix only", func(t *testing.T) {
540 logger := createTestLogger(t)
541 st := &HelmState{
542 logger: logger,
543 fs: filesystem.DefaultFileSystem(),
544 }
545
546 // Test path that has shared cache dir as a prefix but not as the actual parent
547 // e.g., /home/user/.cache/helmfile-other/path should not match
548 sharedCacheDir := remote.CacheDir()
549 nonSubpath := sharedCacheDir + "-other/chart"
550 require.False(t, st.isSharedCachePath(nonSubpath), "path with shared cache as prefix but not subdirectory should return false")
551 })
552

Callers

nothing calls this directly

Calls 4

isSharedCachePathMethod · 0.95
DefaultFileSystemFunction · 0.92
CacheDirFunction · 0.92
createTestLoggerFunction · 0.85

Tested by

no test coverage detected