cfc2d91b0d830dd716aa4f2135ecb66e0d1322cb
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / DnsSrvDiscovererTest.php
1 <?php
2
3 class DnsSrvDiscovererTest extends PHPUnit_Framework_TestCase {
4 /**
5 * @covers DnsSrvDiscoverer
6 * @dataProvider provideRecords
7 */
8 public function testPickServer( $params, $expected ) {
9 $discoverer = new DnsSrvDiscoverer( 'etcd-tcp.example.net' );
10 $record = $discoverer->pickServer( $params );
11
12 $this->assertEquals( $expected, $record );
13 }
14
15 public static function provideRecords() {
16 return [
17 [
18 [ // record list
19 [
20 'target' => 'conf03.example.net',
21 'port' => 'SRV',
22 'pri' => 0,
23 'weight' => 1,
24 ],
25 [
26 'target' => 'conf02.example.net',
27 'port' => 'SRV',
28 'pri' => 1,
29 'weight' => 1,
30 ],
31 [
32 'target' => 'conf01.example.net',
33 'port' => 'SRV',
34 'pri' => 2,
35 'weight' => 1,
36 ],
37 ], // selected record
38 [
39 'target' => 'conf03.example.net',
40 'port' => 'SRV',
41 'pri' => 0,
42 'weight' => 1,
43 ]
44 ],
45 [
46 [ // record list
47 [
48 'target' => 'conf03or2.example.net',
49 'port' => 'SRV',
50 'pri' => 0,
51 'weight' => 1,
52 ],
53 [
54 'target' => 'conf03or2.example.net',
55 'port' => 'SRV',
56 'pri' => 0,
57 'weight' => 1,
58 ],
59 [
60 'target' => 'conf01.example.net',
61 'port' => 'SRV',
62 'pri' => 2,
63 'weight' => 1,
64 ],
65 [
66 'target' => 'conf04.example.net',
67 'port' => 'SRV',
68 'pri' => 2,
69 'weight' => 1,
70 ],
71 [
72 'target' => 'conf05.example.net',
73 'port' => 'SRV',
74 'pri' => 3,
75 'weight' => 1,
76 ],
77 ], // selected record
78 [
79 'target' => 'conf03or2.example.net',
80 'port' => 'SRV',
81 'pri' => 0,
82 'weight' => 1,
83 ]
84 ],
85 ];
86 }
87
88 public function testRemoveServer() {
89 $dsd = new DnsSrvDiscoverer( 'localhost' );
90
91 $servers = [
92 [
93 'target' => 'conf01.example.net',
94 'port' => 35,
95 'pri' => 2,
96 'weight' => 1,
97 ],
98 [
99 'target' => 'conf04.example.net',
100 'port' => 74,
101 'pri' => 2,
102 'weight' => 1,
103 ],
104 [
105 'target' => 'conf05.example.net',
106 'port' => 77,
107 'pri' => 3,
108 'weight' => 1,
109 ],
110 ];
111 $server = $servers[1];
112
113 $expected = [
114 [
115 'target' => 'conf01.example.net',
116 'port' => 35,
117 'pri' => 2,
118 'weight' => 1,
119 ],
120 [
121 'target' => 'conf05.example.net',
122 'port' => 77,
123 'pri' => 3,
124 'weight' => 1,
125 ],
126 ];
127
128 $this->assertEquals(
129 $expected,
130 $dsd->removeServer( $server, $servers ),
131 "Correct server removed"
132 );
133 $this->assertEquals(
134 $expected,
135 $dsd->removeServer( $server, $servers ),
136 "Nothing to remove"
137 );
138 }
139 }