quintush / helm-unittest

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

Support failedTemplate assert for schema validation errors #155

Closed rquinio closed 1 year ago

rquinio commented 2 years ago

Fixes #134

This is only supported for helm v3. FailedTemplateValidator now checks for a global error in validation context, before matching on per template rendering errors.

An alternative would be to use a dedicated "FailedSchemaValidator" with a structured representation of schema errors (i.e. parse using regex the string "values don't meet the specifications of the schema(s) in the following chart(s):\nwith-schema:\n- (root): image is required\n"), let me know what you think.

faithdoub commented 2 years ago

Good Morning @rquinio -- thanks a lot for this fix. I fetched your pull yesterday to test it out. I stared at the failed test for about 10 minutes (same as before) and then found the Failed Template Validate function where the Actual and Template Messages are available and hex encoded them only to find out that I was missing a Line Feed (my Error Message is 4 lines and I was only supplying the 3 lines where there was text). Thanks again to @quintush - would not write a helm chart without this plugin.

Looking back at your message and you have the training \n - my mistake. Easy mistake to make.

rquinio commented 2 years ago

Hi @faithdoub, Indeed I also have a \n at the end in the test:

it: should work
template: dummy.yaml
asserts:
  - failedTemplate:
      errorMessage: "values don't meet the specifications of the schema(s) in the following chart(s):\nwith-schema:\n- (root): image is required\n"

Btw I tried to use multi-line YAML with | but the YAML parser seemed confused, not sure why because I think multiline is supported in some other asserts (?).

faithdoub commented 2 years ago

Hi @rquinio,

I was able to get the multi-line YAML working: (blank line at bottom is required)

asserts:
  - failedTemplate: 
      errorMessage: |
        values don't meet the specifications of the schema(s) in the following chart(s):
        eks-namespace-provisioning:
        - namespace: name is required
eshepelyuk commented 2 years ago

Any news on merging this PR ?

faithdoub commented 2 years ago

No, I check every once in a while to see if there is a new release but there hasn't been one since 11/2021

On Mon, Jun 20, 2022 at 11:10 PM Ievgenii Shepeliuk < @.***> wrote:

Any news on merging this PR ?

— Reply to this email directly, view it on GitHub https://github.com/quintush/helm-unittest/pull/155#issuecomment-1161178392, or unsubscribe https://github.com/notifications/unsubscribe-auth/AN3FTA2EQMO5NBMPSAZEBITVQEXA3ANCNFSM5PFVLIVQ . You are receiving this because you were mentioned.Message ID: @.***>

eshepelyuk commented 2 years ago

No, I check every once in a while to see if there is a new release but there hasn't been one since 11/2021

any other maintained fork to switch to ? @faithdoub ?

mederel commented 1 year ago

Hi @rquinio,

I was able to get the multi-line YAML working: (blank line at bottom is required)

asserts:
  - failedTemplate: 
      errorMessage: |
        values don't meet the specifications of the schema(s) in the following chart(s):
        eks-namespace-provisioning:
        - namespace: name is required

I guess this can be done with the > instead of | which inserts a new line at the end of the text block is there is not one.