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

How do I search for items in a list? #133

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

How do I search for items in a list? #133

red8888 opened this issue Sep 13, 2021 · 4 comments

Comments

@red8888
Copy link

red8888 commented Sep 13, 2021

How do I search for a value in a yaml list?

For example say I have this:

containers:
  - name: mycontainer
    image: sdfsdfsd
    command:
      - "-argone sdfsdf"
      - "-argtwo sdfsdf"
      - "-argthree sdfsdf"

I just want to see if argthree exists (without having to know the specific index number)

      - matchRegex:
          path: spec.template.spec.containers[0].command
          pattern: .*argthress.*

That returns an error expect 'spec.template.spec.containers[0].command' to be a string

If I need to know the specific index it makes it very rigid. Thanks!

@red8888 red8888 closed this as completed Sep 13, 2021
@red8888
Copy link
Author

red8888 commented Sep 13, 2021

Sorry I see it in the docs

@red8888
Copy link
Author

red8888 commented Sep 13, 2021

Im reopening because I found contains but not sure how to use it.

This is a more specific example:

containers:
  - name: mycontainer
    image: sdfsdfsd
    command:
      - "/argone"
      - "--argtwo=sdfsdf"

I can't figure out how to properly describe this in a test.

This is not valid:

- contains:
    path: spec.template.spec.containers[0].command
    content:
    	"/argone"
    	"--argtwo=sdfsdf"

And this adds "-" to the items

- contains:
    path: spec.template.spec.containers[0].command
    content:
    	- "/argone"
    	- "--argtwo=sdfsdf"

Which doesn't match

Expected to contain:
        - - /argone
          - --argtwo=sdfsdf
Actual:
        - /argone
        - --argtwo=sdfsdf

@red8888 red8888 reopened this Sep 13, 2021
@red8888
Copy link
Author

red8888 commented Sep 14, 2021

I also tried this:

      - contains:
          path: spec.template.spec.containers
          content:
            command:
              - "/argone"

The output is confusing because it looks like it should pass:

                        Expected to contain:
                                - command:
                                  - /argone
                        Actual:
                                - command:
                                  - /argone
                                  - -otherarg=ksdflksjdfkl
                                  image: sdfsdfdsf
                                  name: sdfsdf
                                  ..... rest of spec

@froy001
Copy link

froy001 commented Sep 7, 2022

@red8888 did you figure this out?

I am trying to test the following and assert only on the first item:

volumes:
        - name: config-volume
          configMap:
            name: foobar-ns-app-02
        - name: all-vault
          projected:
            sources:
              - secret:
                  name: common-vault
        - configMap:
            name: foo-configMap-2
          name: foo-configmap-volume-2
        - name: foo-secret-volume-2
          secret:
            items:
            - key: foo-key-2
              path: foo-key.txt
            secretName: 'dev-foo-secret-2'

The test:

- contains:
    path: spec.template.spec.volumes
    content:
      name: config-volume
      configMap:
        name: foobar-ns-app-02
    count: 1
    any: true

I get this failure:

- asserts[2] `contains` fail
			Template:	charts-integration-test/charts/app-02/templates/deployment.yaml
			DocumentIndex:	0
			Path:	spec.template.spec.volumes
			Expected to contain:
				- configMap:
				    name: foobar-ns-app-02
				  name: config-volume
			Actual:
				- configMap:
				    name: foobar-ns-app-02
				  name: config-volume
				- name: all-vault
				  projected:
				    sources:
				    - secret:
				        name: common-vault
				- configMap:
				    name: foo-configMap-2
				  name: foo-configmap-volume-2
				- name: foo-secret-volume-2
				  secret:
				    items:
				    - key: foo-key-2
				      path: foo-key.txt
				    secretName: dev-foo-secret-2

And I don't know why this doesn't limit the test to only one item from the array.

Naturally please assume all indentations are correct because they are :)

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