4
|
1 |
#!/usr/bin/env python2.5
|
|
2 |
"""
|
|
3 |
Test bind_conf
|
|
4 |
"""
|
|
5 |
|
|
6 |
import bind_conf as bindc
|
|
7 |
import test_conf, addr
|
|
8 |
|
|
9 |
import unittest
|
|
10 |
|
|
11 |
class TestBINDConf (test_conf._TestConfBase) :
|
|
12 |
def test_comment (self) :
|
|
13 |
self.assert_obj(bindc.Comment("test comment 2"), [ "; test comment 2" ])
|
|
14 |
|
|
15 |
def assert_str (self, label, value) :
|
|
16 |
self.assertEqual(str(label), value)
|
|
17 |
|
|
18 |
def test_label (self) :
|
|
19 |
self.assert_str(bindc.Label("foo"), "foo")
|
|
20 |
|
|
21 |
def test_origin (self) :
|
|
22 |
self.assert_str(bindc.Origin(), "@")
|
|
23 |
|
|
24 |
def test_fqdn (self) :
|
|
25 |
self.assert_str(bindc.FQDN("foo.com"), "foo.com.")
|
|
26 |
|
|
27 |
def test_interval (self) :
|
|
28 |
self.assert_str(bindc.Interval(12), "12")
|
|
29 |
self.assert_str(bindc.Interval(12, 1), "12s1m")
|
|
30 |
self.assert_str(bindc.Interval(h=2, d=5), "2h5d")
|
|
31 |
|
|
32 |
def assert_rec (self, obj, lines) :
|
|
33 |
"""
|
|
34 |
Does a whitespace-insensitive compare of the record's formatted output and the given lines
|
|
35 |
"""
|
|
36 |
|
|
37 |
for obj_line, line in zip(obj.fmt_lines(), lines) :
|
|
38 |
obj_line = ' '.join(obj_line.split())
|
|
39 |
self.assertEqual(obj_line, line)
|
|
40 |
|
|
41 |
def test_record (self) :
|
|
42 |
self.assert_rec(bindc.ResourceRecord(None, 'A', addr.IP("1.2.3.4"), cls='TST', ttl=60), [ "60 TST A 1.2.3.4" ])
|
|
43 |
self.assert_rec(bindc.ResourceRecord('foo', 'CNAME', 'blaa'), [ "foo IN CNAME blaa" ])
|
|
44 |
self.assert_rec(bindc.ResourceRecord('bar', 'CNAME', bindc.FQDN('example.com')), [ "bar IN CNAME example.com." ])
|
|
45 |
|
|
46 |
def test_record_types (self) :
|
|
47 |
self.assert_rec(bindc.SOA(None, 'ns1', 'hostmaster', '2009040200', bindc.Interval(1), 2, 3, 4), [
|
|
48 |
"IN SOA ns1 hostmaster ( 2009040200 1 2 3 4 )"
|
|
49 |
])
|
|
50 |
self.assert_rec(bindc.A('foo', addr.IP("1.2.3.4")), [ "foo IN A 1.2.3.4" ])
|
|
51 |
self.assert_rec(bindc.AAAA('foo2', addr.IP("2001::5")), [ "foo2 IN AAAA 2001::5" ])
|
|
52 |
self.assert_rec(bindc.CNAME('foo3', bindc.FQDN("foo.com")), [ "foo3 IN CNAME foo.com." ])
|
|
53 |
self.assert_rec(bindc.TXT('test4', "this is some text"), [ "test4 IN TXT \"this is some text\"" ])
|
|
54 |
self.assert_rec(bindc.MX(None, 10, "foo"), [ "IN MX 10 foo" ])
|
|
55 |
self.assert_rec(bindc.NS(None, "ns2"), [ "IN NS ns2" ])
|
|
56 |
self.assert_rec(bindc.PTR(addr.IP("1.2.3.4"), 'bar'), [ "4.3.2.1.in-addr.arpa. IN PTR bar" ])
|
|
57 |
|
|
58 |
def test_directive (self) :
|
|
59 |
self.assert_obj(bindc.Directive("TEST", "a", None, 2, comments=["hmm..."]), [
|
|
60 |
"; hmm...",
|
|
61 |
"$TEST a 2"
|
|
62 |
])
|
|
63 |
self.assert_obj(bindc.OriginDirective(bindc.FQDN("foo.com")), [ "$ORIGIN foo.com." ])
|
|
64 |
self.assert_obj(bindc.TTLDirective(bindc.Interval(h=2)), [ "$TTL 2h" ])
|
|
65 |
self.assert_obj(bindc.IncludeDirective("db.foo.com"), [ "$INCLUDE db.foo.com" ])
|
|
66 |
self.assert_obj(bindc.GenerateDirective((1, 10), "dyn${0,2}", 'A', "1.2.3.$"), [ "$GENERATE 1-10 dyn${0,2} A 1.2.3.$" ])
|
|
67 |
|
|
68 |
if __name__ == '__main__' :
|
|
69 |
unittest.main()
|
|
70 |
|