Revision bbfed756 test/ganeti.utils.text_unittest.py
b/test/ganeti.utils.text_unittest.py | ||
---|---|---|
106 | 106 |
None) |
107 | 107 |
|
108 | 108 |
|
109 |
class TestDnsNameGlobPattern(unittest.TestCase): |
|
110 |
def setUp(self): |
|
111 |
self.names = [ |
|
112 |
"node1.example.com", |
|
113 |
"node2-0.example.com", |
|
114 |
"node2-1.example.com", |
|
115 |
"node1.example.net", |
|
116 |
"web1.example.com", |
|
117 |
"web2.example.com", |
|
118 |
"sub.site.example.com", |
|
119 |
] |
|
120 |
|
|
121 |
def _Test(self, pattern): |
|
122 |
re_pat = utils.DnsNameGlobPattern(pattern) |
|
123 |
|
|
124 |
return filter(re.compile(re_pat).match, self.names) |
|
125 |
|
|
126 |
def test(self): |
|
127 |
for pattern in ["xyz", "node", " ", "example.net", "x*.example.*", |
|
128 |
"x*.example.com"]: |
|
129 |
self.assertEqual(self._Test(pattern), []) |
|
130 |
|
|
131 |
for pattern in ["*", "???*"]: |
|
132 |
self.assertEqual(self._Test(pattern), self.names) |
|
133 |
|
|
134 |
self.assertEqual(self._Test("node1.*.net"), ["node1.example.net"]) |
|
135 |
self.assertEqual(self._Test("*.example.net"), ["node1.example.net"]) |
|
136 |
self.assertEqual(self._Test("web1.example.com"), ["web1.example.com"]) |
|
137 |
|
|
138 |
for pattern in ["*.*.*.*", "???", "*.site"]: |
|
139 |
self.assertEqual(self._Test(pattern), ["sub.site.example.com"]) |
|
140 |
|
|
141 |
self.assertEqual(self._Test("node1"), [ |
|
142 |
"node1.example.com", |
|
143 |
"node1.example.net", |
|
144 |
]) |
|
145 |
self.assertEqual(self._Test("node?*.example.*"), [ |
|
146 |
"node1.example.com", |
|
147 |
"node2-0.example.com", |
|
148 |
"node2-1.example.com", |
|
149 |
"node1.example.net", |
|
150 |
]) |
|
151 |
self.assertEqual(self._Test("*-?"), [ |
|
152 |
"node2-0.example.com", |
|
153 |
"node2-1.example.com", |
|
154 |
]) |
|
155 |
self.assertEqual(self._Test("node2-?.example.com"), [ |
|
156 |
"node2-0.example.com", |
|
157 |
"node2-1.example.com", |
|
158 |
]) |
|
159 |
|
|
160 |
|
|
109 | 161 |
class TestFormatUnit(unittest.TestCase): |
110 | 162 |
"""Test case for the FormatUnit function""" |
111 | 163 |
|
Also available in: Unified diff