Passed
Push — master ( dfe4f2...9c85cc )
by Matěj
02:22
created

test_ansible.strings_equal_except_whitespaces()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
import pytest
2
3
import os
4
import re
5
import textwrap
6
import ssg.ansible
7
8
9
def strings_equal_except_whitespaces(left, right):
10
    return re.sub(r'\s', '', left) == re.sub(r'\s', '', right)
11
12
13
def test_add_minimum_version():
14
    good_snippet = """
15
    # a comment
16
     - hosts: all
17
       vars:
18
       tasks:
19
    """
20
    good_snippet = textwrap.dedent(good_snippet)
21
22
    bad_snippet = """
23
    # a comment
24
     - hosts: all
25
       pre_tasks:
26
         - name: something_else
27
           assert:
28
             that: "2 > 3"
29
             msg: "two is less than three!"
30
       vars:
31
       tasks:
32
    """
33
    bad_snippet = textwrap.dedent(bad_snippet)
34
35
    unknown_snippet = """
36
    I don't think this is YAML
37
    """
38
39
    processed_snippet = """
40
    # a comment
41
     - hosts: all
42
       pre_tasks:
43
         - name: Verify Ansible meets SCAP-Security-Guide version requirements.
44
           assert:
45
             that: "ansible_version.full is version_compare('2.3', '>=')"
46
             msg: >
47
               "You must update Ansible to at least version 2.3 to use this role."
48
49
       vars:
50
       tasks:
51
    """
52
    processed_snippet = textwrap.dedent(processed_snippet)
53
54
    output = ssg.ansible.add_minimum_version(good_snippet)
55
    assert strings_equal_except_whitespaces(output, processed_snippet)
56
57
    with pytest.raises(ValueError):
58
        ssg.ansible.add_minimum_version(bad_snippet)
59
60
    assert ssg.ansible.add_minimum_version(unknown_snippet) == unknown_snippet
61
62
    assert ssg.ansible.add_minimum_version(processed_snippet) == processed_snippet
63