Helm unit tests - how to mock k8s entity for the "lookup" function?

12/20/2021

Supposed I have the following condition in the template:

{{- if (lookup "apps/v1" "Deployment" "argocd" "argocd-server") }}

How can I mock this while testing a chart using helm-unittest tool?

-- eugen-fried
helm3
kubernetes
unit-testing

1 Answer

1/11/2022

Haven't used it myself for Helm unit testing but I think that's a good use-case for KUTTL they even have a dedicated documentation for Helm testing

I assume a TestSuite would be rather short e.g. like the following where the commando blocks just bring in all the required resources:

apiVersion: kuttl.dev/v1beta1
kind: TestSuite
commands:
- command: kubectl create namespace argocd
- command: kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
testDirs:
- ./test/integration
startKIND: true
kindNodeCache: true
-- pagid
Source: StackOverflow