Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix excluded chart when chart-dirs is multi-level #312

Merged
merged 1 commit into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.