From 8f013549fdfa17def5ff59a28d80f459f50743ec Mon Sep 17 00:00:00 2001 From: Ross Williams Date: Tue, 12 Oct 2021 18:33:05 +0000 Subject: [PATCH] pkgng: test invalid annotate strings Ensure that some likely to occur, invalid strings given to the annotate module parameter 1. fail, 2. do not cause an exception, and 3. do not create any actual annotations on packages. --- .../targets/pkgng/tasks/freebsd.yml | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/integration/targets/pkgng/tasks/freebsd.yml b/tests/integration/targets/pkgng/tasks/freebsd.yml index 2c3ef73a63..2b5706c1a5 100644 --- a/tests/integration/targets/pkgng/tasks/freebsd.yml +++ b/tests/integration/targets/pkgng/tasks/freebsd.yml @@ -417,6 +417,37 @@ - pkgng_example9_add_annotation_old.changed - '(pkgng_example9_add_annotation_old_verify.stdout_lines | select("match", "ansibletest_example9_[45]\s*:\s*added") | count) == 2' +## +## pkgng - example - invalid annotation strings +## +- name: Should fail on invalid annotate strings + pkgng: + name: '{{ pkgng_test_pkg_name }}' + annotation: '{{ item }}' + ignore_errors: yes + register: pkgng_example8_invalid_annotation_failure + loop: + - 'naked_string' + - '/invalid_operation' + - ',empty_first_tag=validsecond' + - '=notag' + +- name: Verify invalid annotate strings did not add annotations + command: 'pkg info -q -A {{ pkgng_test_pkg_name }}' + register: pkgng_example8_invalid_annotation_verify + +- name: Ensure invalid annotate strings fail safely + assert: + that: + # Invalid strings should not change anything + - '(pkgng_example8_invalid_annotation_failure.results | selectattr("changed") | count) == 0' + # Invalid strings should always fail + - '(pkgng_example8_invalid_annotation_failure.results | selectattr("failed", "false") | count) == 0' + # Invalid strings should not cause an exception + - '(pkgng_example8_invalid_annotation_failure.results | selectattr("exception", "defined") | count) == 0' + # Verify annotations are unaffected + - '(pkgng_example8_invalid_annotation_verify.stdout_lines | select("search", "(naked_string|invalid_operation|empty_first_tag|validsecond|notag)") | count) == 0' + ## ## pkgng - example - Install single package in jail ##