teemtee / fmf

Flexible Metadata Format
GNU General Public License v2.0
22 stars 28 forks source link

Handle missing attribute for merge/minus operation #254

Open lukaszachy opened 2 months ago

lukaszachy commented 2 months ago

Operations ~, -~ and - should do nothing if the key is not present. Otherwise they are difficult to use with shared adjust snippets as keys might not always be present.

lukaszachy commented 2 months ago

Added to the milestone as I intend to use this with 'adjust-tests' feature of tmt and it is very easy to hit KeyError when some test doesn't have both require/recommend set...

LecrisUT commented 2 months ago

Can you comment with an example fmf file for this?

lukaszachy commented 2 months ago

For example conflicting mariadb vs mysql server but test can do both... Recommend package can be skipped, but if for some reason you change the order -> failure during prepare.

/1:
  test: echo
  require:
   - mysql
/2:
  test: echo
  recommend:
   - mariadb
   - mysql

So if I was to use this from other plan (and I don't have possiblity to "fix" test metadata (eg. not my repo):

discover:
 how: fmf
 adjust-tests:
 - require-: [mysql]
 - recommend-: [mysql]

And now I can be sure that mysql isn't require by any test..

lukaszachy commented 2 months ago

@happz has good points that this might hide typo in the key names, making it harder to spot (e.g. why there still is 'foo' in require why I clearly have 'requre-:[foo]' in data...)

psss commented 2 months ago

So, a bit cleaner (perhaps) approach discussed on the chat would be to use require: [] at the top of the test repository to make sure that the key is always defined. But as @lukaszachy mentioned above, there might be a scenario when user does not have write access to the test repository. And for that use case the unconditional removal could be really useful.