|
|
|
@ -17,14 +17,19 @@ limitations under the License.
|
|
|
|
|
package repo
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bufio"
|
|
|
|
|
"bytes"
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"net/http"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"sort"
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"helm.sh/helm/v3/pkg/cli"
|
|
|
|
|
"helm.sh/helm/v3/pkg/getter"
|
|
|
|
|
"helm.sh/helm/v3/pkg/helmpath"
|
|
|
|
|
|
|
|
|
|
"helm.sh/helm/v3/pkg/chart"
|
|
|
|
|
)
|
|
|
|
@ -178,6 +183,18 @@ func TestDownloadIndexFile(t *testing.T) {
|
|
|
|
|
t.Fatalf("Index %q failed to parse: %s", testfile, err)
|
|
|
|
|
}
|
|
|
|
|
verifyLocalIndex(t, i)
|
|
|
|
|
|
|
|
|
|
// Check that charts file is also created
|
|
|
|
|
idx = filepath.Join(r.CachePath, helmpath.CacheChartsFile(r.Config.Name))
|
|
|
|
|
if _, err := os.Stat(idx); err != nil {
|
|
|
|
|
t.Fatalf("error finding created charts file: %#v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
b, err = ioutil.ReadFile(idx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("error reading charts file: %#v", err)
|
|
|
|
|
}
|
|
|
|
|
verifyLocalChartsFile(t, b, i)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("should not decode the path in the repo url while downloading index", func(t *testing.T) {
|
|
|
|
@ -224,6 +241,18 @@ func TestDownloadIndexFile(t *testing.T) {
|
|
|
|
|
t.Fatalf("Index %q failed to parse: %s", testfile, err)
|
|
|
|
|
}
|
|
|
|
|
verifyLocalIndex(t, i)
|
|
|
|
|
|
|
|
|
|
// Check that charts file is also created
|
|
|
|
|
idx = filepath.Join(r.CachePath, helmpath.CacheChartsFile(r.Config.Name))
|
|
|
|
|
if _, err := os.Stat(idx); err != nil {
|
|
|
|
|
t.Fatalf("error finding created charts file: %#v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
b, err = ioutil.ReadFile(idx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("error reading charts file: %#v", err)
|
|
|
|
|
}
|
|
|
|
|
verifyLocalChartsFile(t, b, i)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -322,6 +351,24 @@ func verifyLocalIndex(t *testing.T, i *IndexFile) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func verifyLocalChartsFile(t *testing.T, chartsContent []byte, indexContent *IndexFile) {
|
|
|
|
|
var expected, real []string
|
|
|
|
|
for chart := range indexContent.Entries {
|
|
|
|
|
expected = append(expected, chart)
|
|
|
|
|
}
|
|
|
|
|
sort.Strings(expected)
|
|
|
|
|
|
|
|
|
|
scanner := bufio.NewScanner(bytes.NewReader(chartsContent))
|
|
|
|
|
for scanner.Scan() {
|
|
|
|
|
real = append(real, scanner.Text())
|
|
|
|
|
}
|
|
|
|
|
sort.Strings(real)
|
|
|
|
|
|
|
|
|
|
if strings.Join(expected, " ") != strings.Join(real, " ") {
|
|
|
|
|
t.Errorf("Cached charts file content unexpected. Expected:\n%s\ngot:\n%s", expected, real)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestIndexDirectory(t *testing.T) {
|
|
|
|
|
dir := "testdata/repository"
|
|
|
|
|
index, err := IndexDirectory(dir, "http://localhost:8080")
|
|
|
|
|