summaryrefslogtreecommitdiffstats
path: root/test/TestMetaMainHasInfo.py
blob: 757a4df5eb43f2fd5590b5fa768527d6fbe7f927 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# pylint: disable=preferred-module  # FIXME: remove once migrated per GH-725
import unittest

from ansiblelint.rules import RulesCollection
from ansiblelint.rules.MetaMainHasInfoRule import MetaMainHasInfoRule
from ansiblelint.testing import RunFromText

NO_GALAXY_INFO = '''
author: the author
description: this meta/main.yml has no galaxy_info
'''

MISSING_INFO = '''
galaxy_info:
  # author: the author
  description: Testing if meta contains values
  company: Not applicable

  license: MIT

  # min_ansible_version: 2.5

  platforms:
  - name: Fedora
    versions:
    - 25
  - missing_name: No name
    versions:
    - 25
'''

BAD_TYPES = '''
galaxy_info:
  author: 007
  description: ['Testing meta']
  company: Not applicable

  license: MIT

  min_ansible_version: 2.5

  platforms: Fedora
'''

PLATFORMS_LIST_OF_STR = '''
galaxy_info:
  author: '007'
  description: 'Testing meta'
  company: Not applicable

  license: MIT

  min_ansible_version: 2.5

  platforms: ['Fedora', 'EL']
'''


class TestMetaMainHasInfo(unittest.TestCase):
    collection = RulesCollection()
    collection.register(MetaMainHasInfoRule())

    def setUp(self):
        self.runner = RunFromText(self.collection)

    def test_no_galaxy_info(self):
        results = self.runner.run_role_meta_main(NO_GALAXY_INFO)
        assert len(results) == 1
        self.assertIn("No 'galaxy_info' found",
                      str(results))

    def test_missing_info(self):
        results = self.runner.run_role_meta_main(MISSING_INFO)
        assert len(results) == 3
        self.assertIn("Role info should contain author",
                      str(results))
        self.assertIn("Role info should contain min_ansible_version",
                      str(results))
        self.assertIn("Platform should contain name",
                      str(results))

    def test_bad_types(self):
        results = self.runner.run_role_meta_main(BAD_TYPES)
        assert len(results) == 3
        self.assertIn("author should be a string", str(results))
        self.assertIn("description should be a string", str(results))
        self.assertIn("Platforms should be a list of dictionaries",
                      str(results))

    def test_platform_list_of_str(self):
        results = self.runner.run_role_meta_main(PLATFORMS_LIST_OF_STR)
        assert len(results) == 1
        self.assertIn("Platforms should be a list of dictionaries",
                      str(results))