Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
red8888 opened this issue Sep 13, 2021 · 2 comments
Open

Comments

@red8888
Copy link

red8888 commented Sep 13, 2021

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
@d3adb5
Copy link

d3adb5 commented Jul 23, 2022

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>

@cristiadu
Copy link

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

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

d3adb5 pushed a commit to d3adb5/helm-unittest-tests that referenced this issue Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants