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

Question about "contains" assertion #113

Open
jeratora opened this issue May 14, 2021 · 3 comments
Open

Question about "contains" assertion #113

jeratora opened this issue May 14, 2021 · 3 comments
Assignees

Comments

@jeratora
Copy link

jeratora commented May 14, 2021

Hi.

I'm trying to test the existence of an item of an array without using any positional value using the latest version of the plugin.

Yaml to be tested is :

spec:
  scopes:
    - phony-service.phony:graphql

Please note that phony-service.phony:graphql is not a key/value pair but a whole string.

The following assertion fails:

    asserts:
    - contains:
        path: spec.scopes
        content:
          phony-service.phony:graphql
        count: 1
        any: true

with that odd error:

                - asserts[0] `contains` fail
                        Template:       anything/templates/apiresource.yaml
                        DocumentIndex:  0
                        Path:   spec.scopes
                        Expected to contain:
                                - phony-service.phony:graphql
                        Actual:
                                - phony-service.phony:graphql

Whereas the "positional" assertation works:

    asserts:
    - equal:
        path: spec.scopes[0]
        value: "phony-service.phony:graphql"

Any idea about what I could have missed ? I have tried to put the item content between quotes. Same error.

Thanks in advance for any help.

@jeratora
Copy link
Author

jeratora commented May 14, 2021

Some additional info about that issue

If the yaml to be tested is:

spec:
  scopes:
    - phony-service.phony:graphql
    - name: something

Then the error is:

                - asserts[0] `contains` fail
                        Template:       anything/templates/apiresource.yaml
                        DocumentIndex:  0
                        Path:   spec.scopes
                        Expected to contain:
                                - phony-service.phony:graphql
                        Actual:
                                - phony-service.phony:graphql
                                - name: something

Shouldn't any: true prevent this ?

Edit: if I remove any or set it to false, it does work. Shouldn't it be the contrary ?

@jeratora
Copy link
Author

Ok, the plot thickens....

It seems the issue is really related to the fact this item is not a key/value pair. Because a normal key/value pair item does not raise the issue.

@quintush
Copy link
Owner

Hello @jeratora,

The plot is indeed that the contains, only expects key/value pairs.
You can also see it in the contains unittests

I will look if it is possible to expand the contains to also look at only values.

Greetings,
@quintush

@quintush quintush self-assigned this Oct 1, 2022
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

2 participants