Files
helm-gitea/unittests/helm/deployment/basics.yaml
T
volker.raschekandCopilot eeacda2a25 test: align the file names of the helm unit tests with the chart conventions
The chart conventions demand camelCase file names, forbid short names like `svc` and require the unit tests to
mirror the template structure. The unit tests followed none of that consistently. Four casings existed side by
side - camelCase (extraInitContainers.yaml), kebab-case (checksum-annotations.yaml), a snake and kebab mix
(init_directory_structure.sh-rootless.yaml) and all caps (HA.yaml) - so there was no pattern to copy when
adding a suite, which is how the inconsistency kept growing.

Three groups of problems are fixed:

- svc-configuration.yaml used exactly the short name the conventions forbid for files and keys.
- Several file names repeated their own directory, for example deployment/deployment-additional-config.yaml and
  metric-secret/metrics-secret-servicemonitor-disabled.yaml, which names the subject three times. The directory
  already carries that information, so the file name now only carries the scenario. The default scenario of a
  template is named basics.yaml.
- Four suites lived in a directory of a template they do not assert on. They were filed under deployment/
  because the deployment is rendered as a side effect, not because it is the subject:

      deployment/deprecations.yaml                -> deprecation/deployment.yaml
      deployment/inline-config.yaml               -> config/inlineConfig.yaml
      deployment/storage-class-configuration.yaml -> persistentVolumeClaim/storageClass.yaml
      deployment/svc-configuration.yaml           -> service/configuration.yaml

  storage-class-configuration.yaml is the clearest case: a persistentVolumeClaim directory already existed next
  to it. The suite titles of the two suites whose subject changed are adjusted accordingly.

The Makefile passed `--file unittests/helm/values-conflicting-checks.yaml`, but that file does not exist in the
tree. `helm unittest` ignores a missing path without a warning, so the flag has been dead for an unknown amount
of time while still suggesting the checks run. It is removed; the `unittests/helm/**/*.yaml` glob would pick
the file up anyway if it ever returns.

The naming rule is written down in the copilot instructions, together with the constraint that the glob matches
only a single directory level, so a suite can never be placed directly in unittests/helm/.

All 49 suites and 267 tests still pass.

Co-authored-by: Copilot <copilot@github.com>
2026-10-03 22:19:39 +02:00

376 lines
11 KiB
YAML

suite: Test deployment basics
release:
name: gitea-unittests
namespace: testing
templates:
- templates/deployment.yaml
- templates/secret_admin.yaml
- templates/secret_config.yaml
- templates/secret_gpg.yaml
- templates/secret_init.yaml
- templates/secret_inlineConfig.yaml
- templates/secret_metrics.yaml
tests:
- it: "Render a Deployment"
template: templates/deployment.yaml
asserts:
- hasDocuments:
count: 1
- containsDocument:
kind: Deployment
apiVersion: apps/v1
name: gitea-unittests
- it: "Skip rendering when the Deployment is disabled"
template: templates/deployment.yaml
set:
deployment.enabled: false
asserts:
- hasDocuments:
count: 0
- it: "Render the configured Deployment labels"
template: templates/deployment.yaml
set:
deployment.labels:
hello: world
asserts:
- isSubset:
path: metadata.labels
content:
hello: world
- isSubset:
path: spec.template.metadata.labels
content:
hello: world
- isNotSubset:
path: spec.selector.matchLabels
content:
hello: world
- it: "Omit the Deployment labels from the selector matchLabels"
template: templates/deployment.yaml
set:
deployment.labels:
custom-label: custom-value
another-label: another-value
asserts:
- equal:
path: spec.selector.matchLabels
value:
app.kubernetes.io/name: gitea
app.kubernetes.io/instance: gitea-unittests
- it: "Render the Deployment labels even when none are configured"
template: templates/deployment.yaml
asserts:
- isSubset:
path: metadata.labels
content:
app: gitea
app.kubernetes.io/name: gitea
app.kubernetes.io/instance: gitea-unittests
app.kubernetes.io/managed-by: Helm
- it: "Omit the Deployment annotations when none are configured"
template: templates/deployment.yaml
asserts:
- notExists:
path: metadata.annotations
- it: "Render the configured Deployment annotations"
template: templates/deployment.yaml
set:
deployment.annotations:
hello: world
asserts:
- equal:
path: metadata.annotations
value:
hello: world
- it: "Omit the nodeSelector when none is configured"
asserts:
- notExists:
path: spec.template.spec.nodeSelector
template: templates/deployment.yaml
- it: "Render the configured nodeSelector"
set:
deployment.nodeSelector:
foo: bar
bar: foo
asserts:
- isSubset:
path: spec.template.spec.nodeSelector
content:
foo: bar
bar: foo
template: templates/deployment.yaml
- it: "Omit the affinity when none is configured"
template: templates/deployment.yaml
asserts:
- notExists:
path: spec.template.spec.affinity
- it: "Render the configured affinity"
template: templates/deployment.yaml
set:
deployment.affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/os
operator: In
values:
- linux
asserts:
- equal:
path: spec.template.spec.affinity
value:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/os
operator: In
values:
- linux
- it: "Omit the dnsConfig when none is configured"
template: templates/deployment.yaml
asserts:
- notExists:
path: spec.template.spec.dnsConfig
- it: "Render the configured dnsConfig"
template: templates/deployment.yaml
set:
deployment.dnsConfig:
nameservers:
- 192.0.2.1
options:
- name: ndots
value: "2"
asserts:
- equal:
path: spec.template.spec.dnsConfig
value:
nameservers:
- 192.0.2.1
options:
- name: ndots
value: "2"
- it: "Omit the priorityClassName when none is configured"
template: templates/deployment.yaml
asserts:
- notExists:
path: spec.template.spec.priorityClassName
- it: "Render the configured priorityClassName"
template: templates/deployment.yaml
set:
deployment.priorityClassName: high-priority
asserts:
- equal:
path: spec.template.spec.priorityClassName
value: high-priority
- it: "Omit the schedulerName when none is configured"
template: templates/deployment.yaml
asserts:
- notExists:
path: spec.template.spec.schedulerName
- it: "Render the configured schedulerName"
template: templates/deployment.yaml
set:
deployment.schedulerName: stork
asserts:
- equal:
path: spec.template.spec.schedulerName
value: stork
- it: "Default the strategy to a rolling update"
template: templates/deployment.yaml
asserts:
- equal:
path: spec.strategy
value:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 100%
- it: "Omit rollingUpdate for other strategy types"
template: templates/deployment.yaml
set:
deployment.strategy.type: Recreate
asserts:
- equal:
path: spec.strategy
value:
type: Recreate
- it: "Omit the tolerations when none are configured"
template: templates/deployment.yaml
asserts:
- notExists:
path: spec.template.spec.tolerations
- it: "Render the configured tolerations"
template: templates/deployment.yaml
set:
deployment.tolerations:
- key: database/type
operator: Equal
value: postgres
effect: NoSchedule
asserts:
- equal:
path: spec.template.spec.tolerations
value:
- key: database/type
operator: Equal
value: postgres
effect: NoSchedule
- it: "Omit the topologySpreadConstraints when none are configured"
template: templates/deployment.yaml
asserts:
- notExists:
path: spec.template.spec.topologySpreadConstraints
- it: "Render the configured topologySpreadConstraints"
template: templates/deployment.yaml
set:
deployment.topologySpreadConstraints:
- topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
maxSkew: 1
labelSelector:
matchLabels:
app.kubernetes.io/instance: gitea-unittests
asserts:
- equal:
path: spec.template.spec.topologySpreadConstraints
value:
- topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
maxSkew: 1
labelSelector:
matchLabels:
app.kubernetes.io/instance: gitea-unittests
- it: "Inject TMP_EXISTING_ENVS_FILE into the 'init-app-ini' init container"
template: templates/deployment.yaml
asserts:
- contains:
path: spec.template.spec.initContainers[1].env
content:
name: TMP_EXISTING_ENVS_FILE
value: /tmp/existing-envs
- it: "Inject ENV_TO_INI_MOUNT_POINT into the 'init-app-ini' init container"
template: templates/deployment.yaml
asserts:
- contains:
path: spec.template.spec.initContainers[1].env
content:
name: ENV_TO_INI_MOUNT_POINT
value: /env-to-ini-mounts
- it: "Inject deployment.gitea.env into all init containers and the gitea container"
template: templates/deployment.yaml
set:
deployment.gitea.env:
- name: VARIABLE
value: my-value
asserts:
- contains:
path: spec.template.spec.initContainers[0].env
content:
name: VARIABLE
value: my-value
- contains:
path: spec.template.spec.initContainers[1].env
content:
name: VARIABLE
value: my-value
- contains:
path: spec.template.spec.initContainers[2].env
content:
name: VARIABLE
value: my-value
- contains:
path: spec.template.spec.containers[0].env
content:
name: VARIABLE
value: my-value
- it: "Render GOMAXPROCS when the CPU resources are defined"
template: templates/deployment.yaml
set:
deployment.gitea.resources:
limits:
cpu: 200ms
memory: 200Mi
requests:
cpu: 100ms
memory: 100Mi
asserts:
- contains:
path: spec.template.spec.containers[0].env
content:
name: GOMAXPROCS
valueFrom:
resourceFieldRef:
divisor: "1"
resource: limits.cpu
- equal:
path: spec.template.spec.containers[0].resources
value:
limits:
cpu: 200ms
memory: 200Mi
requests:
cpu: 100ms
memory: 100Mi
- it: "Default the container resources to an empty map and omit GOMAXPROCS"
template: templates/deployment.yaml
asserts:
- equal:
path: spec.template.spec.containers[0].resources
value: {}
- notContains:
path: spec.template.spec.containers[0].env
content:
name: GOMAXPROCS
valueFrom:
resourceFieldRef:
divisor: "1"
resource: limits.cpu
- it: "Omit the pod level resources when none are configured"
template: templates/deployment.yaml
asserts:
- notExists:
path: spec.template.spec.resources
- it: "Render the configured pod level resources"
template: templates/deployment.yaml
set:
deployment.resources:
limits:
cpu: 500m
memory: 512Mi
requests:
cpu: 250m
memory: 256Mi
asserts:
- equal:
path: spec.template.spec.resources
value:
limits:
cpu: 500m
memory: 512Mi
requests:
cpu: 250m
memory: 256Mi
- it: "Render the configured volumeMount path of the init containers"
template: templates/deployment.yaml
set:
initContainersScriptsVolumeMountPath: "/custom/init/path"
asserts:
- equal:
path: spec.template.spec.initContainers[*].volumeMounts[?(@.name=="init")].mountPath
value: "/custom/init/path"
- equal:
path: spec.template.spec.initContainers[*].volumeMounts[?(@.name=="config")].mountPath
value: "/custom/init/path"
- it: "Render the default volumeMount path of the init containers"
template: templates/deployment.yaml
asserts:
- equal:
path: spec.template.spec.initContainers[*].volumeMounts[?(@.name=="init")].mountPath
value: "/usr/sbinx"
- equal:
path: spec.template.spec.initContainers[*].volumeMounts[?(@.name=="config")].mountPath
value: "/usr/sbinx"