helm-unittest
helm-unittest copied to clipboard
How do I search for items in a list?
How do I search for a value in a yaml list?
For example say I have this:
containers:
- name: mycontainer
image: sdfsdfsd
command:
- "-argone sdfsdf"
- "-argtwo sdfsdf"
- "-argthree sdfsdf"
I just want to see if argthree
exists (without having to know the specific index number)
- matchRegex:
path: spec.template.spec.containers[0].command
pattern: .*argthress.*
That returns an error expect 'spec.template.spec.containers[0].command' to be a string
If I need to know the specific index it makes it very rigid. Thanks!
Sorry I see it in the docs
Im reopening because I found contains but not sure how to use it.
This is a more specific example:
containers:
- name: mycontainer
image: sdfsdfsd
command:
- "/argone"
- "--argtwo=sdfsdf"
I can't figure out how to properly describe this in a test.
This is not valid:
- contains:
path: spec.template.spec.containers[0].command
content:
"/argone"
"--argtwo=sdfsdf"
And this adds "-" to the items
- contains:
path: spec.template.spec.containers[0].command
content:
- "/argone"
- "--argtwo=sdfsdf"
Which doesn't match
Expected to contain:
- - /argone
- --argtwo=sdfsdf
Actual:
- /argone
- --argtwo=sdfsdf
I also tried this:
- contains:
path: spec.template.spec.containers
content:
command:
- "/argone"
The output is confusing because it looks like it should pass:
Expected to contain:
- command:
- /argone
Actual:
- command:
- /argone
- -otherarg=ksdflksjdfkl
image: sdfsdfdsf
name: sdfsdf
..... rest of spec
@red8888 did you figure this out?
I am trying to test the following and assert only on the first item:
volumes:
- name: config-volume
configMap:
name: foobar-ns-app-02
- name: all-vault
projected:
sources:
- secret:
name: common-vault
- configMap:
name: foo-configMap-2
name: foo-configmap-volume-2
- name: foo-secret-volume-2
secret:
items:
- key: foo-key-2
path: foo-key.txt
secretName: 'dev-foo-secret-2'
The test:
- contains:
path: spec.template.spec.volumes
content:
name: config-volume
configMap:
name: foobar-ns-app-02
count: 1
any: true
I get this failure:
- asserts[2] `contains` fail
Template: charts-integration-test/charts/app-02/templates/deployment.yaml
DocumentIndex: 0
Path: spec.template.spec.volumes
Expected to contain:
- configMap:
name: foobar-ns-app-02
name: config-volume
Actual:
- configMap:
name: foobar-ns-app-02
name: config-volume
- name: all-vault
projected:
sources:
- secret:
name: common-vault
- configMap:
name: foo-configMap-2
name: foo-configmap-volume-2
- name: foo-secret-volume-2
secret:
items:
- key: foo-key-2
path: foo-key.txt
secretName: dev-foo-secret-2
And I don't know why this doesn't limit the test to only one item from the array.
Naturally please assume all indentations are correct because they are :)