Skip to content

Commit

Permalink
Fix excluded chart when chart-dirs is multi-level
Browse files Browse the repository at this point in the history
Signed-off-by: nekottyo <[email protected]>
  • Loading branch information
nekottyo committed Dec 20, 2020
1 parent ac827da commit c86965c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/chart/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,14 @@ func (t *Testing) ComputeChangedChartDirectories() ([]string, error) {
dir := filepath.Dir(file)
// Make sure directory is really a chart directory
chartDir, err := t.chartUtils.LookupChartDir(cfg.ChartDirs, dir)
chartDirElement := strings.Split(chartDir, "/")
if err == nil {
if len(chartDirElement) > 1 {
chartDirName := chartDirElement[len(chartDirElement)-1]
if util.StringSliceContains(cfg.ExcludedCharts, chartDirName) {
continue
}
}
// Only add it if not already in the list
if !util.StringSliceContains(changedChartDirs, chartDir) {
changedChartDirs = append(changedChartDirs, chartDir)
Expand Down
19 changes: 19 additions & 0 deletions pkg/chart/chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ func (g fakeGit) ListChangedFilesInDirs(commit string, dirs ...string) ([]string
"test_charts/foo/Chart.yaml",
"test_charts/bar/Chart.yaml",
"test_charts/bar/bar_sub/templates/bar_sub.yaml",
"test_charts/excluded/Chart.yaml",
"test_chart_at_root/templates/foo.yaml",
"test_chart_at_multi_level/foo/bar/Chart.yaml",
"test_chart_at_multi_level/foo/baz/Chart.yaml",
"test_chart_at_multi_level/foo/excluded/Chart.yaml",
"some_non_chart_dir/some_non_chart_file",
"some_non_chart_file",
}, nil
Expand Down Expand Up @@ -152,6 +156,21 @@ func TestComputeChangedChartDirectories(t *testing.T) {
assert.Nil(t, err)
}

func TestComputeChangedChartDirectoriesWithMultiLevelChart(t *testing.T) {
cfg := config.Configuration{
ExcludedCharts: []string{"excluded"},
ChartDirs: []string{"test_chart_at_multi_level/foo"},
}
ct := newTestingMock(cfg)
actual, err := ct.ComputeChangedChartDirectories()
expected := []string{"test_chart_at_multi_level/foo/bar", "test_chart_at_multi_level/foo/baz"}
for _, chart := range actual {
assert.Contains(t, expected, chart)
}
assert.Len(t, actual, 2)
assert.Nil(t, err)
}

func TestReadAllChartDirectories(t *testing.T) {
actual, err := ct.ReadAllChartDirectories()
expected := []string{
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.

0 comments on commit c86965c

Please sign in to comment.