-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: change what latest chart actually means (#128)
- Loading branch information
1 parent
d70ad70
commit 00ab459
Showing
2 changed files
with
177 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package local | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"helm.sh/helm/v3/pkg/chart" | ||
"helm.sh/helm/v3/pkg/getter" | ||
"helm.sh/helm/v3/pkg/repo" | ||
) | ||
|
||
func TestLocate(t *testing.T) { | ||
origNewChartRepo := defaultNewChartRepo | ||
origLoadIndexFile := defaultLoadIndexFile | ||
t.Cleanup(func() { | ||
defaultNewChartRepo = origNewChartRepo | ||
defaultLoadIndexFile = origLoadIndexFile | ||
}) | ||
|
||
defaultNewChartRepo = mockNewChartRepo | ||
|
||
tests := []struct { | ||
name string | ||
entries map[string]repo.ChartVersions | ||
exp string | ||
}{ | ||
{ | ||
name: "one release entry", | ||
entries: map[string]repo.ChartVersions{ | ||
"airbyte": []*repo.ChartVersion{{ | ||
Metadata: &chart.Metadata{Version: "1.2.3"}, | ||
URLs: []string{"example.test"}, | ||
}}, | ||
}, | ||
exp: airbyteRepoURL + "/example.test", | ||
}, | ||
{ | ||
name: "one non-release entry", | ||
entries: map[string]repo.ChartVersions{ | ||
"airbyte": []*repo.ChartVersion{{ | ||
Metadata: &chart.Metadata{Version: "1.2.3-alpha-df72e2940ca"}, | ||
URLs: []string{"example.test"}, | ||
}}, | ||
}, | ||
exp: airbyteChartName, | ||
}, | ||
{ | ||
name: "no entries", | ||
entries: map[string]repo.ChartVersions{}, | ||
exp: airbyteChartName, | ||
}, | ||
{ | ||
name: "one release entry with no URLs", | ||
entries: map[string]repo.ChartVersions{ | ||
"airbyte": []*repo.ChartVersion{{ | ||
Metadata: &chart.Metadata{Version: "1.2.3"}, | ||
URLs: []string{}, | ||
}}, | ||
}, | ||
exp: airbyteChartName, | ||
}, | ||
{ | ||
name: "one release entry with two URLs", | ||
entries: map[string]repo.ChartVersions{ | ||
"airbyte": []*repo.ChartVersion{{ | ||
Metadata: &chart.Metadata{Version: "1.2.3"}, | ||
URLs: []string{"one.test", "two.test"}, | ||
}}, | ||
}, | ||
exp: airbyteChartName, | ||
}, | ||
{ | ||
name: "one non-release entry followed by one release entry", | ||
entries: map[string]repo.ChartVersions{ | ||
"airbyte": []*repo.ChartVersion{ | ||
{ | ||
Metadata: &chart.Metadata{Version: "1.2.3-test"}, | ||
URLs: []string{"bad.test"}, | ||
}, | ||
{ | ||
Metadata: &chart.Metadata{Version: "0.9.8"}, | ||
URLs: []string{"good.test"}, | ||
}, | ||
}, | ||
}, | ||
exp: airbyteRepoURL + "/good.test", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
defaultLoadIndexFile = mockLoadIndexFile(repo.IndexFile{Entries: tt.entries}) | ||
act := locateLatestAirbyteChart(airbyteChartName, "") | ||
if d := cmp.Diff(tt.exp, act); d != "" { | ||
t.Errorf("mismatch (-want +got):\n%s", d) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func mockNewChartRepo(cfg *repo.Entry, getters getter.Providers) (chartRepo, error) { | ||
return mockChartRepo{}, nil | ||
} | ||
|
||
func mockLoadIndexFile(idxFile repo.IndexFile) loadIndexFile { | ||
return func(path string) (*repo.IndexFile, error) { | ||
return &idxFile, nil | ||
} | ||
} | ||
|
||
type mockChartRepo struct { | ||
downloadFile func() (string, error) | ||
} | ||
|
||
func (m mockChartRepo) DownloadIndexFile() (string, error) { | ||
if m.downloadFile != nil { | ||
return m.downloadFile() | ||
} | ||
return "", nil | ||
} |