mirror of
https://github.com/helm/helm.git
synced 2026-05-28 04:35:48 -04:00
Porting fix from commit f5986db184
This port fixes the bug #6820 for helm3 which was fixed in helm2 with the pull request 4850 https://github.com/helm/helm/pull/4850 Signed-off-by: Lam Le <lam281990@gmail.com>
This commit is contained in:
parent
2f4ef705a9
commit
afda6b4940
2 changed files with 26 additions and 3 deletions
|
|
@ -169,6 +169,15 @@ func (i IndexFile) Get(name, version string) (*ChartVersion, error) {
|
|||
}
|
||||
}
|
||||
|
||||
// when customer input exact version, check whether have exact match one first
|
||||
if len(version) != 0 {
|
||||
for _, ver := range vs {
|
||||
if version == ver.Version {
|
||||
return ver, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, ver := range vs {
|
||||
test, err := semver.NewVersion(ver.Version)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import (
|
|||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"helm.sh/helm/v3/pkg/cli"
|
||||
|
|
@ -40,14 +41,17 @@ func TestIndexFile(t *testing.T) {
|
|||
i.Add(&chart.Metadata{Name: "cutter", Version: "0.1.1"}, "cutter-0.1.1.tgz", "http://example.com/charts", "sha256:1234567890abc")
|
||||
i.Add(&chart.Metadata{Name: "cutter", Version: "0.1.0"}, "cutter-0.1.0.tgz", "http://example.com/charts", "sha256:1234567890abc")
|
||||
i.Add(&chart.Metadata{Name: "cutter", Version: "0.2.0"}, "cutter-0.2.0.tgz", "http://example.com/charts", "sha256:1234567890abc")
|
||||
i.Add(&chart.Metadata{Name: "setter", Version: "0.1.9+alpha"}, "setter-0.1.9+alpha.tgz", "http://example.com/charts", "sha256:1234567890abc")
|
||||
i.Add(&chart.Metadata{Name: "setter", Version: "0.1.9+beta"}, "setter-0.1.9+beta.tgz", "http://example.com/charts", "sha256:1234567890abc")
|
||||
|
||||
i.SortEntries()
|
||||
|
||||
if i.APIVersion != APIVersionV1 {
|
||||
t.Error("Expected API version v1")
|
||||
}
|
||||
|
||||
if len(i.Entries) != 2 {
|
||||
t.Errorf("Expected 2 charts. Got %d", len(i.Entries))
|
||||
if len(i.Entries) != 3 {
|
||||
t.Errorf("Expected 3 charts. Got %d", len(i.Entries))
|
||||
}
|
||||
|
||||
if i.Entries["clipper"][0].Name != "clipper" {
|
||||
|
|
@ -55,13 +59,23 @@ func TestIndexFile(t *testing.T) {
|
|||
}
|
||||
|
||||
if len(i.Entries["cutter"]) != 3 {
|
||||
t.Error("Expected two cutters.")
|
||||
t.Error("Expected three cutters.")
|
||||
}
|
||||
|
||||
// Test that the sort worked. 0.2 should be at the first index for Cutter.
|
||||
if v := i.Entries["cutter"][0].Version; v != "0.2.0" {
|
||||
t.Errorf("Unexpected first version: %s", v)
|
||||
}
|
||||
|
||||
cv, err := i.Get("setter", "0.1.9")
|
||||
if err == nil && !strings.Contains(cv.Metadata.Version, "0.1.9") {
|
||||
t.Errorf("Unexpected version: %s", cv.Metadata.Version)
|
||||
}
|
||||
|
||||
cv, err = i.Get("setter", "0.1.9+alpha")
|
||||
if err != nil || cv.Metadata.Version != "0.1.9+alpha" {
|
||||
t.Errorf("Expected version: 0.1.9+alpha")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadIndex(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue