mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 05:19:39 +02:00
refactor(helm): helm binary to sdk refactor [r8s-229] (#463)
Co-authored-by: stevensbkang <skan070@gmail.com>
This commit is contained in:
parent
0d25f3f430
commit
b5961d79f8
56 changed files with 2222 additions and 819 deletions
102
pkg/libhelm/sdk/show_test.go
Normal file
102
pkg/libhelm/sdk/show_test.go
Normal file
|
@ -0,0 +1,102 @@
|
|||
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_Show(t *testing.T) {
|
||||
test.EnsureIntegrationTest(t)
|
||||
is := assert.New(t)
|
||||
|
||||
// Create a new SDK package manager
|
||||
hspm := NewHelmSDKPackageManager()
|
||||
|
||||
// install the ingress-nginx chart to test the show command
|
||||
installOpts := options.InstallOptions{
|
||||
Name: "ingress-nginx",
|
||||
Chart: "ingress-nginx",
|
||||
Repo: "https://kubernetes.github.io/ingress-nginx",
|
||||
}
|
||||
release, err := hspm.Install(installOpts)
|
||||
if release != nil || err != nil {
|
||||
defer hspm.Uninstall(options.UninstallOptions{
|
||||
Name: "ingress-nginx",
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("show requires chart, repo and output format", func(t *testing.T) {
|
||||
showOpts := options.ShowOptions{
|
||||
Chart: "",
|
||||
Repo: "",
|
||||
OutputFormat: "",
|
||||
}
|
||||
_, err := hspm.Show(showOpts)
|
||||
is.Error(err, "should return error when required options are missing")
|
||||
is.Contains(err.Error(), "chart, repo and output format are required", "error message should indicate required options")
|
||||
})
|
||||
|
||||
t.Run("show chart values", func(t *testing.T) {
|
||||
showOpts := options.ShowOptions{
|
||||
Chart: "ingress-nginx",
|
||||
Repo: "https://kubernetes.github.io/ingress-nginx",
|
||||
OutputFormat: options.ShowValues,
|
||||
}
|
||||
values, err := hspm.Show(showOpts)
|
||||
|
||||
is.NoError(err, "should not return error when not in k8s environment")
|
||||
is.NotEmpty(values, "should return non-empty values")
|
||||
})
|
||||
|
||||
t.Run("show chart readme", func(t *testing.T) {
|
||||
showOpts := options.ShowOptions{
|
||||
Chart: "ingress-nginx",
|
||||
Repo: "https://kubernetes.github.io/ingress-nginx",
|
||||
OutputFormat: options.ShowReadme,
|
||||
}
|
||||
readme, err := hspm.Show(showOpts)
|
||||
|
||||
is.NoError(err, "should not return error when not in k8s environment")
|
||||
is.NotEmpty(readme, "should return non-empty readme")
|
||||
})
|
||||
|
||||
t.Run("show chart definition", func(t *testing.T) {
|
||||
showOpts := options.ShowOptions{
|
||||
Chart: "ingress-nginx",
|
||||
Repo: "https://kubernetes.github.io/ingress-nginx",
|
||||
OutputFormat: options.ShowChart,
|
||||
}
|
||||
chart, err := hspm.Show(showOpts)
|
||||
|
||||
is.NoError(err, "should not return error when not in k8s environment")
|
||||
is.NotNil(chart, "should return non-nil chart definition")
|
||||
})
|
||||
|
||||
t.Run("show all chart info", func(t *testing.T) {
|
||||
showOpts := options.ShowOptions{
|
||||
Chart: "ingress-nginx",
|
||||
Repo: "https://kubernetes.github.io/ingress-nginx",
|
||||
OutputFormat: options.ShowAll,
|
||||
}
|
||||
info, err := hspm.Show(showOpts)
|
||||
|
||||
is.NoError(err, "should not return error when not in k8s environment")
|
||||
is.NotEmpty(info, "should return non-empty chart info")
|
||||
})
|
||||
|
||||
t.Run("show with invalid output format", func(t *testing.T) {
|
||||
// Show with invalid output format
|
||||
showOpts := options.ShowOptions{
|
||||
Chart: "ingress-nginx",
|
||||
Repo: "https://kubernetes.github.io/ingress-nginx",
|
||||
OutputFormat: "invalid",
|
||||
}
|
||||
_, err := hspm.Show(showOpts)
|
||||
|
||||
is.Error(err, "should return error with invalid output format")
|
||||
is.Contains(err.Error(), "unsupported output format", "error message should indicate invalid output format")
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue