mirror of
https://github.com/portainer/portainer.git
synced 2025-07-28 09:49:40 +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
84
pkg/libhelm/sdk/search_repo_test.go
Normal file
84
pkg/libhelm/sdk/search_repo_test.go
Normal file
|
@ -0,0 +1,84 @@
|
|||
package sdk
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/portainer/portainer/pkg/libhelm/options"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type testCase struct {
|
||||
name string
|
||||
url string
|
||||
invalid bool
|
||||
}
|
||||
|
||||
var tests = []testCase{
|
||||
{"not a helm repo", "https://portainer.io", true},
|
||||
{"ingress helm repo", "https://kubernetes.github.io/ingress-nginx", false},
|
||||
{"portainer helm repo", "https://portainer.github.io/k8s/", false},
|
||||
{"elastic helm repo with trailing slash", "https://helm.elastic.co/", false},
|
||||
{"lensesio helm repo without trailing slash", "https://lensesio.github.io/kafka-helm-charts", false},
|
||||
}
|
||||
|
||||
func Test_SearchRepo(t *testing.T) {
|
||||
is := assert.New(t)
|
||||
|
||||
// Create a new SDK package manager
|
||||
hspm := NewHelmSDKPackageManager()
|
||||
|
||||
for _, test := range tests {
|
||||
func(tc testCase) {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
response, err := hspm.SearchRepo(options.SearchRepoOptions{Repo: tc.url})
|
||||
if tc.invalid {
|
||||
is.Errorf(err, "error expected: %s", tc.url)
|
||||
} else {
|
||||
is.NoError(err, "no error expected: %s", tc.url)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
is.NotEmpty(response, "response expected")
|
||||
}
|
||||
})
|
||||
}(test)
|
||||
}
|
||||
|
||||
t.Run("search repo with keyword", func(t *testing.T) {
|
||||
// Search for charts with keyword
|
||||
searchOpts := options.SearchRepoOptions{
|
||||
Repo: "https://kubernetes.github.io/ingress-nginx",
|
||||
}
|
||||
responseBytes, err := hspm.SearchRepo(searchOpts)
|
||||
|
||||
// The function should not fail by design, even when not running in a k8s environment
|
||||
is.NoError(err, "should not return error when not in k8s environment")
|
||||
is.NotNil(responseBytes, "should return non-nil response")
|
||||
is.NotEmpty(responseBytes, "should return non-empty response")
|
||||
|
||||
// Parse the ext response
|
||||
var repoIndex RepoIndex
|
||||
err = json.Unmarshal(responseBytes, &repoIndex)
|
||||
is.NoError(err, "should parse JSON response without error")
|
||||
is.NotEmpty(repoIndex, "should have at least one chart")
|
||||
|
||||
// Verify charts structure apiVersion, entries, generated
|
||||
is.Equal("v1", repoIndex.APIVersion, "apiVersion should be v1")
|
||||
is.NotEmpty(repoIndex.Entries, "entries should not be empty")
|
||||
is.NotEmpty(repoIndex.Generated, "generated should not be empty")
|
||||
|
||||
// there should be at least one chart
|
||||
is.Greater(len(repoIndex.Entries), 0, "should have at least one chart")
|
||||
})
|
||||
|
||||
t.Run("search repo with empty repo URL", func(t *testing.T) {
|
||||
// Search with empty repo URL
|
||||
searchOpts := options.SearchRepoOptions{
|
||||
Repo: "",
|
||||
}
|
||||
_, err := hspm.SearchRepo(searchOpts)
|
||||
is.Error(err, "should return error when repo URL is empty")
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue