-
Notifications
You must be signed in to change notification settings - Fork 635
/
Copy pathtest_envvars.py
91 lines (86 loc) · 2.86 KB
/
test_envvars.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
import elasticsearch
import curator
import os
import json
import string, random, tempfile
import click
from click import testing as clicktest
from mock import patch, Mock
from . import CuratorTestCase
from . import testvars as testvars
import logging
logger = logging.getLogger(__name__)
host, port = os.environ.get('TEST_ES_SERVER', 'localhost:9200').split(':')
port = int(port) if port else 9200
def random_envvar(size):
return ''.join(
random.SystemRandom().choice(
string.ascii_uppercase + string.digits
) for _ in range(size)
)
class TestEnvVars(CuratorTestCase):
def test_present(self):
evar = random_envvar(8)
os.environ[evar] = "1234"
dollar = '${' + evar + '}'
self.write_config(
self.args['configfile'],
testvars.client_config_envvars.format(dollar, port, 30)
)
cfg = curator.get_yaml(self.args['configfile'])
self.assertEqual(
cfg['client']['hosts'],
os.environ.get(evar)
)
del os.environ[evar]
def test_not_present(self):
evar = random_envvar(8)
dollar = '${' + evar + '}'
self.write_config(
self.args['configfile'],
testvars.client_config_envvars.format(dollar, port, 30)
)
cfg = curator.get_yaml(self.args['configfile'])
self.assertIsNone(cfg['client']['hosts'])
def test_not_present_with_default(self):
evar = random_envvar(8)
default = random_envvar(8)
dollar = '${' + evar + ':' + default + '}'
self.write_config(
self.args['configfile'],
testvars.client_config_envvars.format(dollar, port, 30)
)
cfg = curator.get_yaml(self.args['configfile'])
self.assertEqual(
cfg['client']['hosts'],
default
)
def test_do_something_with_int_value(self):
self.create_indices(10)
evar = random_envvar(8)
os.environ[evar] = "1234"
dollar = '${' + evar + '}'
self.write_config(
self.args['configfile'],
testvars.client_config_envvars.format(host, port, dollar)
)
cfg = curator.get_yaml(self.args['configfile'])
self.assertEqual(
cfg['client']['timeout'],
os.environ.get(evar)
)
self.write_config(self.args['actionfile'],
testvars.delete_proto.format(
'age', 'name', 'older', '\'%Y.%m.%d\'', 'days', 5, ' ', ' ', ' '
)
)
test = clicktest.CliRunner()
_ = test.invoke(
curator.cli,
[
'--config', self.args['configfile'],
self.args['actionfile']
],
)
self.assertEquals(5, len(curator.get_indices(self.client)))
del os.environ[evar]