|
|
@ -22,12 +22,12 @@ import (
|
|
|
|
"net/http/httptest"
|
|
|
|
"net/http/httptest"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"path/filepath"
|
|
|
|
"reflect"
|
|
|
|
|
|
|
|
"runtime"
|
|
|
|
"runtime"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"sigs.k8s.io/yaml"
|
|
|
|
"sigs.k8s.io/yaml"
|
|
|
|
|
|
|
|
|
|
|
|
"helm.sh/helm/v4/pkg/chart"
|
|
|
|
"helm.sh/helm/v4/pkg/chart"
|
|
|
@ -40,37 +40,22 @@ const (
|
|
|
|
testURL = "http://example-charts.com"
|
|
|
|
testURL = "http://example-charts.com"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func TestLoadChartRepository(t *testing.T) {
|
|
|
|
// loadFromDir a directory of charts archives (including sub-directories),
|
|
|
|
r, err := NewChartRepository(&Entry{
|
|
|
|
// appending to the repositores ChartPath
|
|
|
|
Name: testRepository,
|
|
|
|
func loadFromDir(t *testing.T, r *ChartRepository, dir string) {
|
|
|
|
URL: testURL,
|
|
|
|
dirInfo, err := os.Stat(dir)
|
|
|
|
}, getter.All(&cli.EnvSettings{}))
|
|
|
|
require.Nil(t, err)
|
|
|
|
if err != nil {
|
|
|
|
require.True(t, dirInfo.IsDir())
|
|
|
|
t.Errorf("Problem creating chart repository from %s: %v", testRepository, err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := r.Load(); err != nil {
|
|
|
|
globArchives := func(pattern string) []string {
|
|
|
|
t.Errorf("Problem loading chart repository from %s: %v", testRepository, err)
|
|
|
|
archives, err := filepath.Glob(filepath.Join(dir, pattern))
|
|
|
|
}
|
|
|
|
require.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
|
|
paths := []string{
|
|
|
|
|
|
|
|
filepath.Join(testRepository, "frobnitz-1.2.3.tgz"),
|
|
|
|
|
|
|
|
filepath.Join(testRepository, "sprocket-1.1.0.tgz"),
|
|
|
|
|
|
|
|
filepath.Join(testRepository, "sprocket-1.2.0.tgz"),
|
|
|
|
|
|
|
|
filepath.Join(testRepository, "universe/zarthal-1.0.0.tgz"),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if r.Config.Name != testRepository {
|
|
|
|
return archives
|
|
|
|
t.Errorf("Expected %s as Name but got %s", testRepository, r.Config.Name)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(r.ChartPaths, paths) {
|
|
|
|
r.ChartPaths = append(r.ChartPaths, globArchives("*.tgz")...)
|
|
|
|
t.Errorf("Expected %#v but got %#v\n", paths, r.ChartPaths)
|
|
|
|
r.ChartPaths = append(r.ChartPaths, globArchives("**/*.tgz")...)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if r.Config.URL != testURL {
|
|
|
|
|
|
|
|
t.Errorf("Expected url for chart repository to be %s but got %s", testURL, r.Config.URL)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestIndex(t *testing.T) {
|
|
|
|
func TestIndex(t *testing.T) {
|
|
|
@ -82,9 +67,7 @@ func TestIndex(t *testing.T) {
|
|
|
|
t.Errorf("Problem creating chart repository from %s: %v", testRepository, err)
|
|
|
|
t.Errorf("Problem creating chart repository from %s: %v", testRepository, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if err := r.Load(); err != nil {
|
|
|
|
loadFromDir(t, r, testRepository)
|
|
|
|
t.Errorf("Problem loading chart repository from %s: %v", testRepository, err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err = r.Index()
|
|
|
|
err = r.Index()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|