This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func sum(x, y int) int { | |
return x + y | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func Test_sum(t *testing.T) { | |
tests := []struct { | |
name string | |
x int | |
y int | |
want int | |
}{ | |
{ | |
name: "one plus two", | |
x: 1, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image: "{{ .Values.containers.image }}:{{ .Values.app.version }}" | |
imagePullPolicy: {{ .Values.containers.pullPolicy }} | |
{{- if .Values.containers.command }} | |
command: | |
{{- range .Values.containers.command }} | |
- {{ . }} | |
{{- end }} | |
{{- end }} | |
{{- if .Values.containers.args }} | |
args: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{/* | |
Return the appropriate apiVersion for ingress. | |
*/}} | |
{{- define "ingress.apiVersion" -}} | |
{{- if and (.Capabilities.APIVersions.Has "networking.k8s.io/v1") (semverCompare ">= 1.19.x" (include "chart.kubeVersion" .)) -}} | |
{{- print "networking.k8s.io/v1" -}} | |
{{- else if .Capabilities.APIVersions.Has "networking.k8s.io/v1beta1" -}} | |
{{- print "networking.k8s.io/v1beta1" -}} | |
{{- else -}} | |
{{- print "extensions/v1beta1" -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: {{ include "helm-basic-example.fullname" . }} | |
namespace: {{ .Release.Namespace }} | |
labels: | |
# These labels are required by helm. You can read more about required labels in the chart best pracices guide: | |
# https://docs.helm.sh/chart_best_practices/#standard-labels | |
helm.sh/chart: {{ include "helm-basic-example.chart" . }} | |
app.kubernetes.io/name: {{ include "helm-basic-example.name" . }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// An example of how to verify the rendered template object of a Helm Chart given various inputs. | |
func TestHelmBasicExampleTemplateRenderedDeployment(t *testing.T) { | |
t.Parallel() | |
// Path to the helm chart we will test | |
helmChartPath, err := filepath.Abs("../examples/helm-basic-example") | |
releaseName := "helm-basic" | |
require.NoError(t, err) | |
// Since we aren't deploying any resources, there is no need to setup kubectl authentication or helm home. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: {{ include "generic.fullname" .}} | |
labels: &labels | |
{{- include "generic.commonLabels" . | nindent 4 }} | |
{{- with .Values.app.labels }} | |
{{- toYaml . | nindent 4 }} | |
{{- end }} | |
annotations: &annotations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{- define "generic.fullname" -}} | |
{{- .Release.Name | trunc 6 -}} | |
{{- end }} | |
{{/* | |
Selector labels | |
*/}} | |
{{- define "generic.selectorLabels" -}} | |
app.kubernetes.io/name: {{ include "generic.fullname" .}} | |
app.kubernetes.io/instance: '{{ include "generic.fullname" . }}-{{ .Values.app.version }}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestDeployTemplateRendersMetadata(t *testing.T) { | |
t.Parallel() | |
var ( | |
// Default Helm values | |
// Work as values.yaml for tests purposes | |
deployDefaultValues = map[string]string{ | |
"app.version": "0.1.0", | |
"app.replicas": "2", | |
"app.component": "api", | |
"app.env": "dev", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Render receive helm parameters and render a k8s object | |
func Render(t *testing.T, helmChartPath, templateFile, release string, values map[string]string, k8sObject interface{}) error { | |
// Passing values to helm chart. | |
options := &helm.Options{ | |
SetValues: values, | |
} | |
templateFile = fmt.Sprintf("templates/%s", templateFile) | |
output, err := helm.RenderTemplateE(t, options, helmChartPath, release, []string{templateFile}) |