Skip to content

Commit

Permalink
Fix collection of know keys for test, plan and story T001 linter (tee…
Browse files Browse the repository at this point in the history
…mtee#3084)

The original code did not handle fields with dashes
(`restart-max-count`) and internal fields (`serial-number`).
Extend the test coverage a bit to check that internal keys are
reported as invalid.

Co-authored-by: Petr Šplíchal <[email protected]>
  • Loading branch information
2 people authored and The-Mule committed Oct 14, 2024
1 parent 8702370 commit c2f23f2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions tests/lint/test/data/bad-attribute.fmf
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
test: /bin/true
requires: "typo, should be require"

# Internal keys should be reported as well
serial_number: 123
1 change: 1 addition & 0 deletions tests/lint/test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ rlJournalStart
done
rlRun -s "tmt test lint bad-attribute" 1
rlAssertGrep "fail T001 unknown key \"requires\" is used" $rlRun_LOG
rlAssertGrep "fail T001 unknown key \"serial_number\" is used" $rlRun_LOG
rlRun -s "tmt test lint coverage" 1
rlAssertGrep "fail T006 the 'coverage' field has been obsoleted by 'link'" $rlRun_LOG
rlPhaseEnd
Expand Down
15 changes: 14 additions & 1 deletion tmt/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
SpecBasedContainer,
WorkdirArgumentType,
container_field,
container_fields,
dict_to_yaml,
field,
git_clone,
Expand Down Expand Up @@ -896,7 +897,19 @@ def _export(

def _lint_keys(self, additional_keys: list[str]) -> list[str]:
""" Return list of invalid keys used, empty when all good """
known_keys = additional_keys + self._keys()

known_keys: list[str] = []

for field_ in container_fields(self):
_, key, _, _, metadata = container_field(self, field_.name)

if metadata.internal:
continue

known_keys.append(key)

known_keys.extend(additional_keys)

return [key for key in self.node.get() if key not in known_keys]

def lint_validate(self) -> LinterReturn:
Expand Down

0 comments on commit c2f23f2

Please sign in to comment.