quintush / helm-unittest

BDD styled unit test framework for Kubernetes Helm charts as a Helm plugin.
MIT License
345 stars 69 forks source link

FR: `isSubset` assertion to handle multiple keys #162

Closed iben12 closed 1 year ago

iben12 commented 2 years ago

It would be a nice feature if isSubset could handle multiple keys, not just one.

What I mean? Take this manifest:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello
  labels:
    one: 1
    two: 2
    three: 3
...

For this I would like to assert that a subset of the labels are present, but do not care about the rest:

isSubset:
  path: metadata.labels
  content:
    one: 1
    three: 3
# this fails

I think this is in line what subset means. The current implementation of isSubset is rather hasElement.

If I want to achieve the above now, I can either assert isSubset one-by-one for relevant labels, or equal to all labels including all irrelevant keys.

What do you think?

iben12 commented 2 years ago

Maybe something like this could achieve that: https://github.com/iben12/helm-unittest/commit/b5ccd70a31a737606efbeb847fd2320dcf8d3940

Should I open a PR?

cristiadu commented 1 year ago

FYI: isSubset needs to be documented here: https://github.com/quintush/helm-unittest/blob/master/DOCUMENT.md

Currently not even the current implementation is documented.