chore: remove unnecessary code, and using testdata instead of inline

Signed-off-by: Ardika Bagus <me@ardikabs.com>
This commit is contained in:
Ardika Bagus
2023-10-04 20:44:10 +07:00
parent 5505af439a
commit b7b85b10fc
5 changed files with 46 additions and 71 deletions

View File

@@ -9,7 +9,6 @@ import (
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
@@ -770,11 +769,10 @@ releaseName: podinfo2
podinfo2ChartContents, err := th.GetFSys().ReadFile(filepath.Join(podinfo2ChartsDir, "Chart.yaml"))
assert.NoError(t, err)
assert.Contains(t, string(podinfo2ChartContents), "version: 6.1.8")
}
// Addressed: https://github.com/kubernetes-sigs/kustomize/issues/5163
func TestHelmChartInflationGeneratorWithLocalChartWithVersion(t *testing.T) {
func TestHelmChartInflationGeneratorWithLocalChartWithVersion5163(t *testing.T) {
th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t).
PrepBuiltin("HelmChartInflationGenerator")
defer th.Reset()
@@ -782,46 +780,27 @@ func TestHelmChartInflationGeneratorWithLocalChartWithVersion(t *testing.T) {
t.Skip("skipping: " + err.Error())
}
err := th.GetFSys().MkdirAll(filepath.Join(th.GetRoot(), "charts/dummy/templates"))
require.NoError(t, err)
copyTestChartsIntoHarness(t, th)
th.WriteF(filepath.Join(th.GetRoot(), "charts/dummy/Chart.yaml"), `
apiVersion: v1
appVersion: 1.0.0
description: Dummy
name: dummy
version: 1.0.0
`)
th.WriteF(filepath.Join(th.GetRoot(), "charts/dummy/values.yaml"), `
foo: bar
`)
th.WriteF(filepath.Join(th.GetRoot(), "charts/dummy/templates/cm.yaml"), `
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Values.foo }}
`)
dummyInlineHelmChart := th.LoadAndRunGenerator(`
rm := th.LoadAndRunGenerator(`
apiVersion: builtin
kind: HelmChartInflationGenerator
metadata:
name: dummy
name: dummy
name: issue5163
name: issue5163
version: 1.0.0
releaseName: dummy
releaseName: issue5163
chartHome: ./charts
`)
dummyConfigmap, err := dummyInlineHelmChart.Resources()[0].GetFieldValue("metadata.name")
cm, err := rm.Resources()[0].GetFieldValue("metadata.name")
assert.NoError(t, err)
assert.Equal(t, "bar", dummyConfigmap)
assert.Equal(t, "bar", cm)
dummyChartsDir := filepath.Join(th.GetRoot(), "charts/dummy")
assert.True(t, th.GetFSys().Exists(dummyChartsDir))
chartDir := filepath.Join(th.GetRoot(), "charts/issue5163")
assert.True(t, th.GetFSys().Exists(chartDir))
dummyChartsContent, err := th.GetFSys().ReadFile(filepath.Join(dummyChartsDir, "Chart.yaml"))
chartYamlContent, err := th.GetFSys().ReadFile(filepath.Join(chartDir, "Chart.yaml"))
assert.NoError(t, err)
assert.Contains(t, string(dummyChartsContent), "version: 1.0.0")
assert.Contains(t, string(chartYamlContent), "version: 1.0.0")
}

View File

@@ -0,0 +1,24 @@
apiVersion: v2
name: issue5163
description: A Helm chart for Kubernetes
# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.0.0
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "stable"

View File

@@ -0,0 +1,4 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Values.foo }}

View File

@@ -0,0 +1 @@
foo: bar