From a8774f13bf475a844f8219a18233424c3bfe3c01 Mon Sep 17 00:00:00 2001 From: dbw7 Date: Wed, 13 Mar 2024 12:05:10 -0400 Subject: [PATCH] Update helm_test.go --- pkg/helm/helm_test.go | 82 +++++++++++++++++++++++++++++++------------ 1 file changed, 60 insertions(+), 22 deletions(-) diff --git a/pkg/helm/helm_test.go b/pkg/helm/helm_test.go index 146f1ea8..f938afbb 100644 --- a/pkg/helm/helm_test.go +++ b/pkg/helm/helm_test.go @@ -291,30 +291,51 @@ func TestTemplateCommand(t *testing.T) { } func TestParseChartContents_InvalidPayload(t *testing.T) { - contents := "---abc" + contents := `--- +# Source +invalid-resource +` resources, err := parseChartContents(contents) require.Error(t, err) - assert.ErrorContains(t, err, "invalid resource") + assert.ErrorContains(t, err, "yaml: unmarshal errors:\n line 2: cannot unmarshal !!str `invalid...` into map[string]interface {}") assert.Nil(t, resources) } func TestParseChartContents(t *testing.T) { contents := ` -apiVersion: helm.cattle.io/v1 -kind: HelmChart +# Source: cert-manager/templates/cainjector-serviceaccount.yaml +apiVersion: v1 +kind: ServiceAccount +automountServiceAccountToken: true metadata: - name: metallb - namespace: metallb-system -spec: - repo: https://suse-edge.github.io/charts - chart: metallb + name: cert-manager-cainjector + namespace: default + labels: + app: cainjector + app.kubernetes.io/name: cainjector + app.kubernetes.io/instance: cert-manager + app.kubernetes.io/component: "cainjector" + app.kubernetes.io/version: "v1.14.4" + app.kubernetes.io/managed-by: Helm + helm.sh/chart: cert-manager-v1.14.4 --- +# Source: cert-manager/templates/serviceaccount.yaml apiVersion: v1 -kind: Namespace +kind: ServiceAccount +automountServiceAccountToken: true metadata: - name: metallb-system + name: cert-manager + namespace: default + labels: + app: cert-manager + app.kubernetes.io/name: cert-manager + app.kubernetes.io/instance: cert-manager + app.kubernetes.io/component: "controller" + app.kubernetes.io/version: "v1.14.4" + app.kubernetes.io/managed-by: Helm + helm.sh/chart: cert-manager-v1.14.4 ` resources, err := parseChartContents(contents) @@ -323,23 +344,40 @@ metadata: require.Len(t, resources, 2) assert.Equal(t, map[string]any{ - "apiVersion": "helm.cattle.io/v1", - "kind": "HelmChart", + "apiVersion": "v1", + "kind": "ServiceAccount", + "automountServiceAccountToken": true, "metadata": map[string]any{ - "name": "metallb", - "namespace": "metallb-system", - }, - "spec": map[string]any{ - "repo": "https://suse-edge.github.io/charts", - "chart": "metallb", + "name": "cert-manager-cainjector", + "namespace": "default", + "labels": map[string]any{ + "app": "cainjector", + "app.kubernetes.io/name": "cainjector", + "app.kubernetes.io/instance": "cert-manager", + "app.kubernetes.io/component": "cainjector", + "app.kubernetes.io/version": "v1.14.4", + "app.kubernetes.io/managed-by": "Helm", + "helm.sh/chart": "cert-manager-v1.14.4", + }, }, }, resources[0]) assert.Equal(t, map[string]any{ - "apiVersion": "v1", - "kind": "Namespace", + "apiVersion": "v1", + "kind": "ServiceAccount", + "automountServiceAccountToken": true, "metadata": map[string]any{ - "name": "metallb-system", + "name": "cert-manager", + "namespace": "default", + "labels": map[string]any{ + "app": "cert-manager", + "app.kubernetes.io/name": "cert-manager", + "app.kubernetes.io/instance": "cert-manager", + "app.kubernetes.io/component": "controller", + "app.kubernetes.io/version": "v1.14.4", + "app.kubernetes.io/managed-by": "Helm", + "helm.sh/chart": "cert-manager-v1.14.4", + }, }, }, resources[1]) }