1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-20 22:09:41 +02:00

refactor(helm): helm binary to sdk refactor [r8s-229] (#463)

Co-authored-by: stevensbkang <skan070@gmail.com>
This commit is contained in:
Ali 2025-03-13 12:20:16 +13:00 committed by GitHub
parent 0d25f3f430
commit b5961d79f8
56 changed files with 2222 additions and 819 deletions

View file

@ -0,0 +1,65 @@
package sdk
import (
"testing"
"github.com/portainer/portainer/pkg/libhelm/options"
"github.com/portainer/portainer/pkg/libhelm/test"
"github.com/stretchr/testify/assert"
)
func Test_Uninstall(t *testing.T) {
test.EnsureIntegrationTest(t)
is := assert.New(t)
// Create a new SDK package manager
hspm := NewHelmSDKPackageManager()
t.Run("uninstall requires a release name", func(t *testing.T) {
// Try to uninstall without a release name
uninstallOpts := options.UninstallOptions{
Name: "",
}
err := hspm.Uninstall(uninstallOpts)
is.Error(err, "should return error when release name is empty")
is.Contains(err.Error(), "release name is required", "error message should indicate release name is required")
})
t.Run("uninstall a non-existent release", func(t *testing.T) {
// Try to uninstall a release that doesn't exist
uninstallOpts := options.UninstallOptions{
Name: "non-existent-release",
}
err := hspm.Uninstall(uninstallOpts)
// The function should not fail by design, even when not running in a k8s environment
// However, it should return an error for a non-existent release
is.Error(err, "should return error when release doesn't exist")
is.Contains(err.Error(), "not found", "error message should indicate release not found")
})
// This test is commented out as it requires a real release to be installed first
t.Run("successfully uninstall an existing release", func(t *testing.T) {
// First install a release
installOpts := options.InstallOptions{
Name: "test-uninstall",
Chart: "nginx",
Repo: "https://kubernetes.github.io/ingress-nginx",
}
// Install the release
_, err := hspm.Install(installOpts)
if err != nil {
t.Logf("Error installing release: %v", err)
t.Skip("Skipping uninstall test because install failed")
return
}
// Now uninstall it
uninstallOpts := options.UninstallOptions{
Name: "test-uninstall",
}
err = hspm.Uninstall(uninstallOpts)
is.NoError(err, "should successfully uninstall release")
})
}