quintush / helm-unittest

BDD styled unit test framework for Kubernetes Helm charts as a Helm plugin.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible to share set values between tests (I guess like a fixture?)

red8888 opened this issue · comments

I want to write sort of the equivalent of an integration test I guess.

I have a couple different "types" of apps I deploy and they all use mostly the same parameters. I want to write a test that describes a complete profile of parameters to deploy a specific classification of app. This could be "public web app with mysql DB", "internal web app with redis DB", etc.

If I could do this then these tests would also be able to serve as documentation- a complete example with ALL the specific params required to deploy app of type X.

Is this possible? Maybe this already is possible but Im not sure how the test "suites" are organized.

Example might look like this:

suite: test deployment
    set:
      <all the required values to deploy this type of app>

templates:
  - deployment.yaml
  - ingress.yaml
  - <bunch of other resources>
tests:
  - it: A public facing web app the uses a mysql DB
    asserts:
      # test Deployment resource
      - isKind:
          of: Deployment
      - matchRegex:
          path: metadata.name
          pattern: -my-chart$
      # also test Ingress resource in same test
      - isKind:
          of: Ingress
      - matchRegex:
          path: metadata.name
          pattern: blahblahblah

While it isn't what you're looking for, YAML anchors and the fact unittest isn't strict about its schema can help you here:

suite: test deployment

fixtures:
  required: &required-values
    <all the required values to deploy this type of app>

templates:
  - deployment.yaml

tests:
  - it: does the things with the stuff
    set: *required-values
    asserts:
      <your assertions here>
  - it: does more things with the stuff if blergh is set to ABC
    set:
      <<: *required-values
      blergh: ABC
    asserts:
      <your assertions here>

Sadly, AFAIK only the tests themselves, not the assertions, can be limited to specific templates:

templates:
  - deployment.yaml
  - ingress.yaml
tests:
  - it: does the things with the stuff
    templates: [ deployment.yaml ]
    asserts:
      <your deployment assertions>
  - it: also does the things with the stuff
    templates: [ ingress.yaml ]
    asserts:
      <your ingress assertions>

Can we have "values file per suite" as a feature request? @quintush

No need to rush, just a suggestion for the future.