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

overlay/match on array item incorrectly errors (and with wrong expectation) #94

Closed
jtigger opened this issue Feb 14, 2020 · 4 comments
Closed
Labels
helping with an issue Debugging happening to identify the problem

Comments

@jtigger
Copy link
Contributor

jtigger commented Feb 14, 2020

This input:

test.yml[1]

  1 ---
  2 clients:
  3 - client1:
  4     secret: blah1
  5 - client2:
  6     secret: blah2
  7
  8 #@ load("@ytt:overlay", "overlay")
  9 #@overlay/match by=overlay.all
 10 ---
 11 clients:
 12 #@overlay/match by=overlay.all,expects="1+"
 13 - client1:
 14     secret: foo

... yields this error message ...

ytt: Error: Overlaying (in following order: test.yml): Document on
line test.yml:10: Map item (key 'clients') on line test.yml:11: Array
item on line test.yml:13: Map item (key 'client1') on line
test.yml:13: Expected number of matched nodes to be 1, but was 0

Instead, I expect this output:

---
clients:
- client1:
    secret: foo
- client1:
    secret: foo

[1] https://get-ytt.io/#gist:https://gist.github.com/jtigger/a3dbb1bb167452e288692e32127a4bf5

@jtigger jtigger changed the title overlay/match on array item incorrectly errors (and with wrong expectation) [bug] overlay/match on array item incorrectly errors (and with wrong expectation) Feb 14, 2020
@cppforlife
Copy link
Contributor

error message is correct. default behaviour is merge, hence it's telling you that second array item doesnt have client1 key already (ie it's not annotated with missing_ok=True if that's indeed what you wanted to do). alternatively to get your expected result you should add overlay/replace to array item:

---
clients:
- client1:
    secret: blah1
- client2:
    secret: blah2

#@ load("@ytt:overlay", "overlay")
#@overlay/match by=overlay.all
---
clients:
#@overlay/match by=overlay.all,expects="1+"
#@overlay/replace
- client1:
    secret: foo

@cppforlife cppforlife changed the title [bug] overlay/match on array item incorrectly errors (and with wrong expectation) overlay/match on array item incorrectly errors (and with wrong expectation) Feb 14, 2020
@cppforlife cppforlife added the helping with an issue Debugging happening to identify the problem label Feb 14, 2020
@jtigger
Copy link
Contributor Author

jtigger commented Feb 15, 2020

@cppforlife: when ,expects="1+" is removed, the message reads:

Document on line test.yml:10: Map item (key 'clients') on line
test.yml:11: Array item on line test.yml:13: Expected number of
matched nodes to be 1, but was 2

@cppforlife
Copy link
Contributor

note the difference error messages

Document on line demo.yml:10:
  Map item (key 'clients') on line demo.yml:11:
    Array item on line demo.yml:13:
      Map item (key 'client1') on line demo.yml:14:
        Expected number of matched nodes to be 1, but was 0

vs

Document on line demo.yml:10:
  Map item (key 'clients') on line demo.yml:11:
    Array item on line demo.yml:13:
      Expected number of matched nodes to be 1, but was 2

@cppforlife
Copy link
Contributor

cppforlife commented Feb 18, 2020

some error message improvements to indicate left vs right nodes

Document on line demo.yml:10 [matched demo.yml:1]
  Map item key 'clients' on line demo.yml:11 [matched demo.yml:2]
    Map item key 'client1' on line demo.yml:12 [did not match]
      Expected number of matched left map items to be 1, but was 0

vs

left=demo.yml right=overlay.yml
left=:1 right=:10 [matched]  Document
left=:2 right=:11 [matched]    Map item key 'clients'
left=?  right=:12 [error]        Map item key 'client1'
                                   Expected number of matched left map items to be 1, but was 0

vs

left=demo.yml:1 right=demo.yml:10 [matched]  Document
left=demo.yml:2 right=demo.yml:11 [matched]    Map item key 'clients'
left=?          right=demo.yml:12 [error]        Map item key 'client1'
                                                   Expected number of matched left map items to be 1, but was 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
helping with an issue Debugging happening to identify the problem
Projects
None yet
Development

No branches or pull requests

2 participants