<commit_before>/*
Copyright The Helm Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
	"testing"
)

var (
	values                       = []byte{}
	namespace                    = "testNamespace"
	strict                       = false
	archivedChartPath            = "testdata/testcharts/compressedchart-0.1.0.tgz"
	archivedChartPathWithHyphens = "testdata/testcharts/compressedchart-with-hyphens-0.1.0.tgz"
	invalidArchivedChartPath     = "testdata/testcharts/invalidcompressedchart0.1.0.tgz"
	chartDirPath                 = "testdata/testcharts/decompressedchart/"
	chartMissingManifest         = "testdata/testcharts/chart-missing-manifest"
	chartWithPreReleaseVersion   = "testdata/testcharts/pre-release-chart-0.1.0-alpha.tgz"
)

func TestLintChart(t *testing.T) {
	if _, err := lintChart(chartDirPath, values, namespace, strict); err != nil {
		t.Errorf("%s", err)
	}

	if _, err := lintChart(archivedChartPath, values, namespace, strict); err != nil {
		t.Errorf("%s", err)
	}

	if _, err := lintChart(archivedChartPathWithHyphens, values, namespace, strict); err != nil {
		t.Errorf("%s", err)
	}

	if _, err := lintChart(chartWithPreReleaseVersion, values, namespace, strict); err != nil {
		t.Errorf("%s", err)
	}

	if _, err := lintChart(invalidArchivedChartPath, values, namespace, strict); err == nil {
		t.Errorf("Expected a chart parsing error")
	}

	if _, err := lintChart(chartMissingManifest, values, namespace, strict); err == nil {
		t.Errorf("Expected a chart parsing error")
	}
}<commit_msg>fix(helm): refactor lint unit tests to table-driven<commit_after>/*
Copyright The Helm Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
	"testing"
)

func TestLintChart(t *testing.T) {
	tests := []struct {
		name      string
		chartPath string
		err       bool
	}{
		{
			name:      "decompressed-chart",
			chartPath: "testdata/testcharts/decompressedchart/",
		},
		{
			name:      "archived-chart-path",
			chartPath: "testdata/testcharts/compressedchart-0.1.0.tgz",
		},
		{
			name:      "archived-chart-path-with-hyphens",
			chartPath: "testdata/testcharts/compressedchart-with-hyphens-0.1.0.tgz",
		},
		{
			name:      "pre-release-chart",
			chartPath: "testdata/testcharts/pre-release-chart-0.1.0-alpha.tgz",
		},
		{
			name:      "invalid-archived-chart-path",
			chartPath: "testdata/testcharts/invalidcompressedchart0.1.0.tgz",
			err:       true,
		},
		{
			name:      "chart-missing-manifest",
			chartPath: "testdata/testcharts/chart-missing-manifest",
			err:       true,
		},
	}

	values := []byte{}
	namespace := "testNamespace"
	strict := false

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			_, err := lintChart(tt.chartPath, values, namespace, strict)
			switch {
			case err != nil && !tt.err:
				t.Errorf("%s", err)
			case err == nil && tt.err:
				t.Errorf("Expected a chart parsing error")
			}
		})
	}
}
{'fraction_non_alphanumeric': 0.11793422404933196, 'fraction_numerical': 0.008221993833504625, 'mean_word_length': 3.4138321995464853, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3670607', 'n_tokens_mistral': 1327, 'n_tokens_neox': 1210, 'n_words': 341}