Fix failing tests

Signed-off-by: Evans Mungai <mbuevans@gmail.com>
pull/31504/head
Evans Mungai 11 months ago
parent d514effb97
commit f3a04ae56b
No known key found for this signature in database
GPG Key ID: BBEB812143DD14E1

@ -84,7 +84,7 @@ func (i *LocalInstaller) Install() error {
return i.installFromDirectory() return i.installFromDirectory()
} }
// installFromDirectory creates a symlink to the plugin directory // installFromDirectory copies the plugin directory
func (i *LocalInstaller) installFromDirectory() error { func (i *LocalInstaller) installFromDirectory() error {
stat, err := os.Stat(i.Source) stat, err := os.Stat(i.Source)
if err != nil { if err != nil {
@ -97,8 +97,8 @@ func (i *LocalInstaller) installFromDirectory() error {
if !isPlugin(i.Source) { if !isPlugin(i.Source) {
return ErrMissingMetadata return ErrMissingMetadata
} }
slog.Debug("symlinking", "source", i.Source, "path", i.Path()) slog.Debug("copying", "source", i.Source, "path", i.Path())
return os.Symlink(i.Source, i.Path()) return fs.CopyDir(i.Source, i.Path(), copyDirOptions)
} }
// installFromArchive extracts and installs a plugin from a tarball // installFromArchive extracts and installs a plugin from a tarball

@ -24,6 +24,7 @@ import (
"log/slog" "log/slog"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"helm.sh/helm/v4/internal/plugin" "helm.sh/helm/v4/internal/plugin"
"helm.sh/helm/v4/internal/plugin/cache" "helm.sh/helm/v4/internal/plugin/cache"
@ -221,6 +222,11 @@ func extractTar(r io.Reader, targetDir string) error {
return err return err
} }
// Skip .git directories and their contents
if strings.HasPrefix(header.Name, ".git/") || header.Name == ".git" {
continue
}
path, err := cleanJoin(targetDir, header.Name) path, err := cleanJoin(targetDir, header.Name)
if err != nil { if err != nil {
return err return err

@ -888,6 +888,9 @@ func TestOCIInstaller_IgnoresGitDir(t *testing.T) {
MediaType: "application/vnd.oci.image.layer.v1.tar", MediaType: "application/vnd.oci.image.layer.v1.tar",
Digest: digest.Digest(layerDigest), Digest: digest.Digest(layerDigest),
Size: int64(len(pluginData)), Size: int64(len(pluginData)),
Annotations: map[string]string{
ocispec.AnnotationTitle: pluginName + "-1.0.0.tgz",
},
}, },
}, },
} }
@ -928,7 +931,7 @@ func TestOCIInstaller_IgnoresGitDir(t *testing.T) {
} }
source := fmt.Sprintf("oci://%s/%s:1.0.0", registryURL.Host, pluginName) source := fmt.Sprintf("oci://%s/%s:1.0.0", registryURL.Host, pluginName)
i, err := NewForSource(source, "") i, err := NewOCIInstaller(source, getter.WithPlainHTTP(true))
if err != nil { if err != nil {
t.Fatalf("unexpected error: %s", err) t.Fatalf("unexpected error: %s", err)
} }

@ -92,7 +92,8 @@ func (i *VCSInstaller) Install() error {
} }
slog.Debug("copying files", "source", i.Repo.LocalPath(), "destination", i.Path()) slog.Debug("copying files", "source", i.Repo.LocalPath(), "destination", i.Path())
return fs.CopyDir(i.Repo.LocalPath(), i.Path(), copyDirOptions) // VCS plugins need .git for updates, so don't filter it out
return fs.CopyDir(i.Repo.LocalPath(), i.Path(), fs.CopyDirOptions{})
} }
// Update updates a remote repository // Update updates a remote repository

@ -23,7 +23,6 @@ import (
"testing" "testing"
"github.com/Masterminds/vcs" "github.com/Masterminds/vcs"
"github.com/stretchr/testify/assert"
"helm.sh/helm/v4/internal/test/ensure" "helm.sh/helm/v4/internal/test/ensure"
"helm.sh/helm/v4/pkg/helmpath" "helm.sh/helm/v4/pkg/helmpath"
@ -188,56 +187,3 @@ func TestVCSInstallerUpdate(t *testing.T) {
} }
} }
func TestVCSInstaller_IgnoresGitDir(t *testing.T) {
ensure.HelmHome(t)
if err := os.MkdirAll(helmpath.DataPath("plugins"), 0755); err != nil {
t.Fatalf("Could not create %s: %s", helmpath.DataPath("plugins"), err)
}
// Create a test plugin directory with .git
testRepoPath := t.TempDir()
if err := os.WriteFile(filepath.Join(testRepoPath, "plugin.yaml"), []byte("name: test-plugin\nversion: 1.0.0"), 0644); err != nil {
t.Fatal(err)
}
gitDir := filepath.Join(testRepoPath, ".git")
if err := os.MkdirAll(gitDir, 0755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(gitDir, "config"), []byte("git config"), 0644); err != nil {
t.Fatal(err)
}
source := "https://github.com/test/test-plugin"
repo := &testRepo{
local: testRepoPath,
tags: []string{"1.0.0"},
}
i, err := NewForSource(source, "1.0.0")
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
vcsInstaller, ok := i.(*VCSInstaller)
if !ok {
t.Fatal("expected a VCSInstaller")
}
vcsInstaller.Repo = repo
if err := Install(i); err != nil {
t.Fatal(err)
}
// Verify .git was not copied
installedGitDir := filepath.Join(i.Path(), ".git")
_, err = os.Stat(installedGitDir)
assert.True(t, os.IsNotExist(err), "expected .git directory to not exist, got %v", err)
// Verify plugin.yaml was copied
if _, err := os.Stat(filepath.Join(i.Path(), "plugin.yaml")); err != nil {
t.Fatal("plugin.yaml should have been copied")
}
}

Loading…
Cancel
Save