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

[bug] - contains fails when expected and actual content is the same #174

Closed
froy001 opened this issue Sep 7, 2022 · 4 comments · Fixed by #181
Closed

[bug] - contains fails when expected and actual content is the same #174

froy001 opened this issue Sep 7, 2022 · 4 comments · Fixed by #181
Assignees

Comments

@froy001
Copy link

froy001 commented Sep 7, 2022

The template:

 volumes:
        - name: config-volume
          configMap:
            name: davf-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[3].secret.items
          content:
            key: foo-key-2 
            path: foo-key.txt 
          count: 1
          any: true

The failure:

- asserts[1] `contains` fail
     Template:	charts-integration-test/charts/app-02/templates/deployment.yaml
      DocumentIndex:	0
      Path:	spec.template.spec.volumes[3].secret.items
      Expected to contain:
	  - key: foo-key-2
	    path: foo-key.txt
       Actual:
	  - key: foo-key-2
	    path: foo-key.txt

Obviously this should pass.

@quintush
Copy link
Owner

Hello @froy001,

I would agree, however I have seen this behavior earlier.
I will try to reproduce this issue.

Greetings,
@quintush

@quintush quintush self-assigned this Sep 25, 2022
@cristiadu
Copy link

Had a similar issue, but in my case I do have other elements in the array.

			Template:	my-chart/templates/network/gateway.yaml
			DocumentIndex:	0
			Path:	spec.servers
			Expected to contain:
				- hosts:
				  - my.host
				  port:
				    name: http
				    number: 80
				    protocol: HTTP
				  tls:
				    httpsRedirect: true
			Actual:
				- hosts:
				  - my.host
				  port:
				    name: http
				    number: 80
				    protocol: HTTP
				  tls:
				    httpsRedirect: true
				- hosts:
				  - my.host2
				  port:
				    name: https
				    number: 443
				    protocol: HTTPS
				  tls:
				    credentialName: service1-RELEASE-NAME
				    mode: SIMPLE

@cristiadu
Copy link

PS: I could use equals on spec.servers[0] with the whole YAML structure, so that can be a workaround if you know for sure the array index to match.

@froy001
Copy link
Author

froy001 commented Oct 18, 2022

@cristiadu Following up on your suggestion:

The template:

volumes:
        - name: config-volume
          configMap:
            name: app-02
        - name: all-vault
          projected:
            sources:
              - secret:
                  name: common-vault

The test (expecting 'false' logic to not render a volume):

  - it: should not render the rookout volume when rookout.enabled is not given
    templates:
      - charts/app-01/templates/deployment.yaml
      - charts/app-02/templates/deployment.yaml
    asserts:
      - isNull:
          path: spec.template.spec.volumes[2]

test result:

	- should not render the rookout volume when rookout.enabled is not given

		- asserts[0] `isNull` fail
			Template:	charts-integration-test/charts/app-01/templates/deployment.yaml
			DocumentIndex:	0
			Error:
				[2] :
				- configMap:
				    name: foobar-ns-app-01
				  name: config-volume
				- name: all-vault
				  projected:
				    sources:
				    - secret:
				        name: common-vault
			Template:	charts-integration-test/charts/app-02/templates/deployment.yaml
			DocumentIndex:	0
			Error:
				[2] :
				- configMap:
				    name: foobar-ns-app-02
				  name: config-volume
				- name: all-vault
				  projected:
				    sources:
				    - secret:
				        name: common-vault

 PASS  test integration Ingress	tests/ingress_test.yaml
 PASS  test integration service	tests/service_test.yaml

Charts:      1 failed, 0 passed, 1 total
Test Suites: 1 failed, 3 passed, 4 total
Tests:       1 failed, 97 passed, 98 total
Snapshot:    0 passed, 0 total
Time:        3.860298409s

@quintush it seems that the processing of yaml arrays has a fundumental flaw in logic. I wish I speaked go so I could inteligently look into it.

I think it has to do with go's OOB error when trying to evaluate an the 3rd item in a 2 item array. I think that in this context, OOB error should be treated as Null since when checking what the 3rd item in a 2 item array is equal to... well it equals to nothing we can comprehend or Null.

Thanks for the effort.

@quintush quintush linked a pull request Nov 7, 2022 that will close this issue
@quintush quintush closed this as completed Nov 7, 2022
d3adb5 pushed a commit to d3adb5/helm-unittest-tests that referenced this issue Apr 30, 2024
fix: schema definition types (resolves quintush#170)
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 a pull request may close this issue.

3 participants