Merge "Use delete_and_move_reason in content language on move over redirect"
[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
16 public static function provideRecords() {
17 return [
18 [
19 [ // record list
20 [
21 'target' => 'conf03.example.net',
22 'port' => 'SRV',
23 'pri' => 0,
24 'weight' => 1,
25 ],
26 [
27 'target' => 'conf02.example.net',
28 'port' => 'SRV',
29 'pri' => 1,
30 'weight' => 1,
31 ],
32 [
33 'target' => 'conf01.example.net',
34 'port' => 'SRV',
35 'pri' => 2,
36 'weight' => 1,
37 ],
38 ], // selected record
39 [
40 'target' => 'conf03.example.net',
41 'port' => 'SRV',
42 'pri' => 0,
43 'weight' => 1,
44 ]
45 ],
46 [
47 [ // record list
48 [
49 'target' => 'conf03or2.example.net',
50 'port' => 'SRV',
51 'pri' => 0,
52 'weight' => 1,
53 ],
54 [
55 'target' => 'conf03or2.example.net',
56 'port' => 'SRV',
57 'pri' => 0,
58 'weight' => 1,
59 ],
60 [
61 'target' => 'conf01.example.net',
62 'port' => 'SRV',
63 'pri' => 2,
64 'weight' => 1,
65 ],
66 [
67 'target' => 'conf04.example.net',
68 'port' => 'SRV',
69 'pri' => 2,
70 'weight' => 1,
71 ],
72 [
73 'target' => 'conf05.example.net',
74 'port' => 'SRV',
75 'pri' => 3,
76 'weight' => 1,
77 ],
78 ], // selected record
79 [
80 'target' => 'conf03or2.example.net',
81 'port' => 'SRV',
82 'pri' => 0,
83 'weight' => 1,
84 ]
85 ],
86 ];
87 }
88
89 public function testRemoveServer() {
90 $dsd = new DnsSrvDiscoverer( 'localhost' );
91
92 $servers = [
93 [
94 'target' => 'conf01.example.net',
95 'port' => 35,
96 'pri' => 2,
97 'weight' => 1,
98 ],
99 [
100 'target' => 'conf04.example.net',
101 'port' => 74,
102 'pri' => 2,
103 'weight' => 1,
104 ],
105 [
106 'target' => 'conf05.example.net',
107 'port' => 77,
108 'pri' => 3,
109 'weight' => 1,
110 ],
111 ];
112 $server = $servers[1];
113
114 $expected = [
115 [
116 'target' => 'conf01.example.net',
117 'port' => 35,
118 'pri' => 2,
119 'weight' => 1,
120 ],
121 [
122 'target' => 'conf05.example.net',
123 'port' => 77,
124 'pri' => 3,
125 'weight' => 1,
126 ],
127 ];
128
129 $this->assertEquals(
130 $expected,
131 $dsd->removeServer( $server, $servers ),
132 "Correct server removed"
133 );
134 $this->assertEquals(
135 $expected,
136 $dsd->removeServer( $server, $servers ),
137 "Nothing to remove"
138 );
139 }
140 }