mirror of
https://github.com/helm/helm.git
synced 2026-05-28 04:35:48 -04:00
Merge commit from fork
Updating link handling
This commit is contained in:
commit
ff032beb48
2 changed files with 108 additions and 0 deletions
|
|
@ -852,6 +852,20 @@ func writeLock(chartpath string, lock *chart.Lock, legacyLockfile bool) error {
|
|||
lockfileName = "requirements.lock"
|
||||
}
|
||||
dest := filepath.Join(chartpath, lockfileName)
|
||||
|
||||
info, err := os.Lstat(dest)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return fmt.Errorf("error getting info for %q: %w", dest, err)
|
||||
} else if err == nil {
|
||||
if info.Mode()&os.ModeSymlink != 0 {
|
||||
link, err := os.Readlink(dest)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading symlink for %q: %w", dest, err)
|
||||
}
|
||||
return fmt.Errorf("the %s file is a symlink to %q", lockfileName, link)
|
||||
}
|
||||
}
|
||||
|
||||
return os.WriteFile(dest, data, 0644)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,12 +21,15 @@ import (
|
|||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"helm.sh/helm/v3/pkg/chart"
|
||||
"helm.sh/helm/v3/pkg/chart/loader"
|
||||
"helm.sh/helm/v3/pkg/chartutil"
|
||||
"helm.sh/helm/v3/pkg/getter"
|
||||
"helm.sh/helm/v3/pkg/repo/repotest"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
func TestVersionEquals(t *testing.T) {
|
||||
|
|
@ -598,3 +601,94 @@ func TestKey(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteLock(t *testing.T) {
|
||||
fixedTime, err := time.Parse(time.RFC3339, "2025-07-04T00:00:00Z")
|
||||
assert.NoError(t, err)
|
||||
lock := &chart.Lock{
|
||||
Generated: fixedTime,
|
||||
Digest: "sha256:12345",
|
||||
Dependencies: []*chart.Dependency{
|
||||
{
|
||||
Name: "fantastic-chart",
|
||||
Version: "1.2.3",
|
||||
Repository: "https://example.com/charts",
|
||||
},
|
||||
},
|
||||
}
|
||||
expectedContent, err := yaml.Marshal(lock)
|
||||
assert.NoError(t, err)
|
||||
|
||||
t.Run("v2 lock file", func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
err := writeLock(dir, lock, false)
|
||||
assert.NoError(t, err)
|
||||
|
||||
lockfilePath := filepath.Join(dir, "Chart.lock")
|
||||
_, err = os.Stat(lockfilePath)
|
||||
assert.NoError(t, err, "Chart.lock should exist")
|
||||
|
||||
content, err := os.ReadFile(lockfilePath)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expectedContent, content)
|
||||
|
||||
// Check that requirements.lock does not exist
|
||||
_, err = os.Stat(filepath.Join(dir, "requirements.lock"))
|
||||
assert.Error(t, err)
|
||||
assert.True(t, os.IsNotExist(err))
|
||||
})
|
||||
|
||||
t.Run("v1 lock file", func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
err := writeLock(dir, lock, true)
|
||||
assert.NoError(t, err)
|
||||
|
||||
lockfilePath := filepath.Join(dir, "requirements.lock")
|
||||
_, err = os.Stat(lockfilePath)
|
||||
assert.NoError(t, err, "requirements.lock should exist")
|
||||
|
||||
content, err := os.ReadFile(lockfilePath)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expectedContent, content)
|
||||
|
||||
// Check that Chart.lock does not exist
|
||||
_, err = os.Stat(filepath.Join(dir, "Chart.lock"))
|
||||
assert.Error(t, err)
|
||||
assert.True(t, os.IsNotExist(err))
|
||||
})
|
||||
|
||||
t.Run("overwrite existing lock file", func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
lockfilePath := filepath.Join(dir, "Chart.lock")
|
||||
assert.NoError(t, os.WriteFile(lockfilePath, []byte("old content"), 0644))
|
||||
|
||||
err = writeLock(dir, lock, false)
|
||||
assert.NoError(t, err)
|
||||
|
||||
content, err := os.ReadFile(lockfilePath)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expectedContent, content)
|
||||
})
|
||||
|
||||
t.Run("lock file is a symlink", func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
dummyFile := filepath.Join(dir, "dummy.txt")
|
||||
assert.NoError(t, os.WriteFile(dummyFile, []byte("dummy"), 0644))
|
||||
|
||||
lockfilePath := filepath.Join(dir, "Chart.lock")
|
||||
assert.NoError(t, os.Symlink(dummyFile, lockfilePath))
|
||||
|
||||
err = writeLock(dir, lock, false)
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "the Chart.lock file is a symlink to")
|
||||
})
|
||||
|
||||
t.Run("chart path is not a directory", func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
filePath := filepath.Join(dir, "not-a-dir")
|
||||
assert.NoError(t, os.WriteFile(filePath, []byte("file"), 0644))
|
||||
|
||||
err = writeLock(filePath, lock, false)
|
||||
assert.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue