-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: cover node id detection with tests
- Loading branch information
1 parent
0199761
commit f70ee06
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/* | ||
Copyright (c) 2024, Manticore Software LTD (https://manticoresearch.com) | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License version 3 or any later | ||
version. You should have received a copy of the GPL license along with this | ||
program; if you did not, you can find it at http://www.gnu.org/ | ||
*/ | ||
|
||
use Manticoresearch\Buddy\Base\Plugin\Sharding\Node; | ||
|
||
final class NodeTest extends \PHPUnit\Framework\TestCase { | ||
const TEST_MAP = [ | ||
'localhost:9312' => 'localhost:9312', | ||
'dfsdfsdf' => null, | ||
'hello:world' => null, | ||
'domain.local:9312' => 'domain.local:9312', | ||
'127.0.0.1:9312' => '127.0.0.1:9312', | ||
'127.0.0.1:9306:mysql' => '127.0.0.1:9306', | ||
'127.0.0.1:9308:http' => '127.0.0.1:9308', | ||
'127.0.0.1:9212:mysql' => '127.0.0.1:9212', | ||
'127.0.0.1:9224:mysql' => '127.0.0.1:9224', | ||
]; | ||
|
||
/** | ||
* Validate we can parse valid lines from config to get Node ID | ||
* @return void | ||
*/ | ||
public function testNodeIdParsing(): void { | ||
echo "\nTesting the parsing of node id from line\n"; | ||
$map = static::TEST_MAP; | ||
// Edge case when we should detect hostname | ||
$hostname = gethostname(); | ||
$host = gethostbyname($hostname ?: ''); | ||
$map['0.0.0.0:9552'] = "$host:9552"; | ||
$map['9333'] = "$host:9333"; | ||
foreach ($map as $line => $expected) { | ||
// PHP has a bug and converts string into ints when can | ||
$nodeId = Node::parseNodeId((string)$line); | ||
$this->assertEquals($expected, $nodeId); | ||
} | ||
} | ||
} |