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

issue#308 allow multiple documents to be selected in document selector #328

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mszygenda
Copy link

@mszygenda mszygenda commented May 1, 2024

This PR addresses following issue:
#308

Use-case:

I want to assert whether or not all manifests of type "Deployment":

  • eg. define default resources section.
  • eg. follow naming convention
  • eg. set right namespace

I want this assertion to work for current and future deployments I might have in my chart.
I have to use document selector because I keep different types of k8s manifests in a single YAML file (eg. foo-application.yaml contains definition of Deployment as well as the Service)

USAGE:

suite: Document Selector is matching many documents
templates:
  - "templates/application-*.yaml"
tests:
  - it: deployment names should end with -deployment suffix
    documentSelector:
      path: kind
      value: Deployment
      matchMany: true
    asserts:
      - matchRegex:
          path: metadata.name
          pattern: -deployment$

It has one limitation though - every template that you select for your test-suite has to have at least one matching manifest. The test will fail otherwise.

Happy to hear any feedback you might have. The code might need some styling fixes etc. but functionally it seems to be doing what it's supposed to do.

@@ -70,7 +70,8 @@ func (a *Assertion) Assert(
singleTemplateResult[template] = rendered

// Update the DocumentIndex if the found idx is not -1
indexError := a.determineDocumentIndex(singleTemplateResult)
selectedDocs, indexError := a.selectDocuments(rendered)
Copy link
Author

@mszygenda mszygenda May 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, actually - we should check if selection generates more than 1 result across all template file - to keep full backward compatibility. I guess it needs improving.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed it.

@mszygenda mszygenda marked this pull request as draft May 1, 2024 17:46
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

Successfully merging this pull request may close these issues.

None yet

1 participant