-
Notifications
You must be signed in to change notification settings - Fork 594
Expand file tree
/
Copy pathtestcollector.py
More file actions
110 lines (79 loc) · 3.52 KB
/
testcollector.py
File metadata and controls
110 lines (79 loc) · 3.52 KB
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
#!/usr/bin/python
# coding=utf-8
##########################################################################
from test import patch
from test import unittest
import configobj
from diamond.collector import Collector
class BaseCollectorTest(unittest.TestCase):
def test_SetCustomHostname(self):
config = configobj.ConfigObj()
config['server'] = {}
config['server']['collectors_config_path'] = ''
config['collectors'] = {}
config['collectors']['default'] = {
'hostname': 'custom.localhost',
}
c = Collector(config, [])
self.assertEquals('custom.localhost', c.get_hostname())
def test_SetHostnameViaShellCmd(self):
config = configobj.ConfigObj()
config['server'] = {}
config['server']['collectors_config_path'] = ''
config['collectors'] = {}
config['collectors']['default'] = {
'hostname': 'echo custom.localhost',
'hostname_method': 'shell',
}
c = Collector(config, [])
self.assertEquals('custom.localhost', c.get_hostname())
@patch('diamond.collector.get_hostname')
def test_get_metric_path_no_prefix(self, get_hostname_mock):
config = configobj.ConfigObj()
config['collectors'] = {}
config['collectors']['default'] = {}
config['collectors']['default']['path_prefix'] = ''
config['collectors']['default']['path'] = 'bar'
get_hostname_mock.return_value = None
result = Collector(config, []).get_metric_path('foo')
self.assertEqual('bar.foo', result)
@patch('diamond.collector.get_hostname')
def test_get_metric_path_no_prefix_no_path(self, get_hostname_mock):
config = configobj.ConfigObj()
config['collectors'] = {}
config['collectors']['default'] = {}
config['collectors']['default']['path_prefix'] = ''
config['collectors']['default']['path'] = ''
get_hostname_mock.return_value = None
result = Collector(config, []).get_metric_path('foo')
self.assertEqual('foo', result)
@patch('diamond.collector.get_hostname')
def test_get_metric_path_no_path(self, get_hostname_mock):
config = configobj.ConfigObj()
config['collectors'] = {}
config['collectors']['default'] = {}
config['collectors']['default']['path_prefix'] = 'bar'
config['collectors']['default']['path'] = ''
get_hostname_mock.return_value = None
result = Collector(config, []).get_metric_path('foo')
self.assertEqual('bar.foo', result)
@patch('diamond.collector.get_hostname')
def test_get_metric_path_dot_path(self, get_hostname_mock):
config = configobj.ConfigObj()
config['collectors'] = {}
config['collectors']['default'] = {}
config['collectors']['default']['path_prefix'] = 'bar'
config['collectors']['default']['path'] = '.'
get_hostname_mock.return_value = None
result = Collector(config, []).get_metric_path('foo')
self.assertEqual('bar.foo', result)
@patch('diamond.collector.get_hostname')
def test_get_metric_path(self, get_hostname_mock):
config = configobj.ConfigObj()
config['collectors'] = {}
config['collectors']['default'] = {}
config['collectors']['default']['path_prefix'] = 'poof'
config['collectors']['default']['path'] = 'xyz'
get_hostname_mock.return_value = 'bar'
result = Collector(config, []).get_metric_path('foo')
self.assertEqual('poof.bar.xyz.foo', result)