From 7d978f0501f7fcda01b7e010dbbe4a5d807cdbc1 Mon Sep 17 00:00:00 2001 From: nekottyo Date: Mon, 21 Dec 2020 03:20:52 +0900 Subject: [PATCH] Fix excluded chart when chart-dirs is multi-level Signed-off-by: nekottyo --- pkg/chart/chart.go | 7 +++++++ pkg/chart/chart_test.go | 21 +++++++++++++++++++ .../foo/bar/Chart.yaml | 0 .../foo/baz/Chart.yaml | 0 .../foo/excluded/Chart.yaml | 0 pkg/chart/test_charts/excluded/Chart.yaml | 0 6 files changed, 28 insertions(+) create mode 100644 pkg/chart/test_chart_at_multi_level/foo/bar/Chart.yaml create mode 100644 pkg/chart/test_chart_at_multi_level/foo/baz/Chart.yaml create mode 100644 pkg/chart/test_chart_at_multi_level/foo/excluded/Chart.yaml create mode 100644 pkg/chart/test_charts/excluded/Chart.yaml diff --git a/pkg/chart/chart.go b/pkg/chart/chart.go index 96b1b7da..43ac2051 100644 --- a/pkg/chart/chart.go +++ b/pkg/chart/chart.go @@ -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) diff --git a/pkg/chart/chart_test.go b/pkg/chart/chart_test.go index 829ccf80..6828d833 100644 --- a/pkg/chart/chart_test.go +++ b/pkg/chart/chart_test.go @@ -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 @@ -152,6 +156,23 @@ 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) + // fmt.Println() + actual, err := ct.ComputeChangedChartDirectories() + // fmt.Printf("actual, %v", actual) + 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{ diff --git a/pkg/chart/test_chart_at_multi_level/foo/bar/Chart.yaml b/pkg/chart/test_chart_at_multi_level/foo/bar/Chart.yaml new file mode 100644 index 00000000..e69de29b diff --git a/pkg/chart/test_chart_at_multi_level/foo/baz/Chart.yaml b/pkg/chart/test_chart_at_multi_level/foo/baz/Chart.yaml new file mode 100644 index 00000000..e69de29b diff --git a/pkg/chart/test_chart_at_multi_level/foo/excluded/Chart.yaml b/pkg/chart/test_chart_at_multi_level/foo/excluded/Chart.yaml new file mode 100644 index 00000000..e69de29b diff --git a/pkg/chart/test_charts/excluded/Chart.yaml b/pkg/chart/test_charts/excluded/Chart.yaml new file mode 100644 index 00000000..e69de29b