-
Notifications
You must be signed in to change notification settings - Fork 656
/
test_config.py
152 lines (100 loc) · 4.69 KB
/
test_config.py
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# Copyright (c) 2015-2016 Cisco Systems, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
import os
import pytest
from molecule import config
from molecule import provisioner
from molecule import scenario
from molecule.dependency import ansible_galaxy
from molecule.driver import docker
from molecule.lint import ansible_lint
from molecule.verifier import testinfra
@pytest.fixture
def config_data():
return {}
@pytest.fixture
def config_instance(platforms_data, molecule_file, config_data):
configs = [platforms_data, config_data]
return config.Config(molecule_file, configs=configs)
def test_molecule_file_private_member(platforms_data, config_data):
configs = [platforms_data, config_data]
c = config.Config('/foo/bar/default/molecule.yml', configs=configs)
x = '/foo/bar/default/molecule.yml'
assert x == c.molecule_file
def test_args_member(config_instance):
assert {} == config_instance.args
def test_command_args_member(config_instance):
assert {} == config_instance.command_args
def test_ephemeral_directory_property(config_instance):
x = os.path.join(
config.molecule_ephemeral_directory(
config_instance.scenario.directory))
assert x == config_instance.ephemeral_directory
def test_dependency_property(config_instance):
assert isinstance(config_instance.dependency, ansible_galaxy.AnsibleGalaxy)
def test_driver_property(config_instance):
assert isinstance(config_instance.driver, docker.Docker)
def test_lint_property(config_instance):
assert isinstance(config_instance.lint, ansible_lint.AnsibleLint)
def test_platforms_property(config_instance):
x = [{
'groups': ['foo', 'bar'],
'name': 'instance-1'
}, {
'groups': ['baz', 'foo'],
'name': 'instance-2'
}]
assert x == config_instance.platforms
def test_provisioner_property(config_instance):
assert isinstance(config_instance.provisioner, provisioner.Ansible)
def test_scenario_property(config_instance):
assert isinstance(config_instance.scenario, scenario.Scenario)
def test_verifier_property(config_instance):
assert isinstance(config_instance.verifier, testinfra.Testinfra)
@pytest.fixture()
def project_config_data():
return {'driver': {'name': 'project-override'}}
@pytest.fixture()
def local_config_data():
return {'driver': {'name': 'local-override', 'options': {'foo': 'bar'}}}
def test_combine_default_and_project_dicts(project_config_data, molecule_file,
config_data):
configs = [project_config_data, config_data]
c = config.Config(molecule_file, configs=configs)
assert 'project-override' == c.config['driver']['name']
assert {} == c.config['driver']['options']
def test_combine_default_local_and_project_dicts(
project_config_data, local_config_data, molecule_file, config_data):
configs = [project_config_data, local_config_data]
c = config.Config(molecule_file, configs=configs)
assert 'local-override' == c.config['driver']['name']
return {'foo': 'bar'} == c.config['driver']['options']
def test_merge_dicts(config_instance):
# example taken from python-anyconfig/anyconfig/__init__.py
a = {'b': [{'c': 0}, {'c': 2}], 'd': {'e': 'aaa', 'f': 3}}
b = {'a': 1, 'b': [{'c': 3}], 'd': {'e': 'bbb'}}
x = {'a': 1, 'b': [{'c': 3}], 'd': {'e': "bbb", 'f': 3}}
assert x == config_instance.merge_dicts(a, b)
def test_molecule_directory():
assert '/foo/molecule' == config.molecule_directory('/foo')
def test_molecule_ephemeral_directory():
assert '/foo/.molecule' == config.molecule_ephemeral_directory('/foo')
def test_molecule_file():
assert '/foo/molecule.yml' == config.molecule_file('/foo')