helm-unittest icon indicating copy to clipboard operation
helm-unittest copied to clipboard

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

Open red8888 opened this issue 4 years ago • 2 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

red8888 avatar Sep 13 '21 16:09 red8888

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>

d3adb5 avatar Jul 23 '22 17:07 d3adb5

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

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

cristiadu avatar Oct 11 '22 17:10 cristiadu