-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Harry Bragg
authored
Jul 29, 2019
1 parent
64c6dbd
commit 94fe0c0
Showing
2 changed files
with
91 additions
and
3 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
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,82 @@ | ||
<?php | ||
/** | ||
* This file is part of graze/dog-statsd | ||
* | ||
* Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license https://github.com/graze/dog-statsd/blob/master/LICENSE.md | ||
* @link https://github.com/graze/dog-statsd | ||
*/ | ||
|
||
namespace Graze\DogStatsD\Test\Unit; | ||
|
||
use Graze\DogStatsD\Test\TestCase; | ||
|
||
class EnvConfigurationTest extends TestCase | ||
{ | ||
public function tearDown() | ||
{ | ||
putenv('DD_AGENT_HOST='); | ||
putenv('DD_DOGSTATSD_PORT='); | ||
putenv('DD_ENTITY_ID='); | ||
} | ||
|
||
public function testHost() | ||
{ | ||
putenv('DD_AGENT_HOST=127.0.0.1'); | ||
$this->client->configure(); | ||
|
||
$this->assertEquals('127.0.0.1', $this->client->getHost()); | ||
} | ||
|
||
public function testPort() | ||
{ | ||
putenv('DD_DOGSTATSD_PORT=12434'); | ||
$this->client->configure(); | ||
|
||
$this->assertEquals(12434, $this->client->getPort()); | ||
} | ||
|
||
/** | ||
* @expectedException \Graze\DogStatsD\Exception\ConfigurationException | ||
* @expectedExceptionMessage Option: Port is invalid or is out of range | ||
*/ | ||
public function testLargePortWillThrowAnException() | ||
{ | ||
putenv('DD_DOGSTATSD_PORT=65536'); | ||
$this->client->configure(); | ||
} | ||
|
||
/** | ||
* @expectedException \Graze\DogStatsD\Exception\ConfigurationException | ||
* @expectedExceptionMessage Option: Port is invalid or is out of range | ||
*/ | ||
public function testStringPortWillThrowAnException() | ||
{ | ||
putenv('DD_DOGSTATSD_PORT=not-integer'); | ||
$this->client->configure(); | ||
} | ||
|
||
public function testTags() | ||
{ | ||
putenv('DD_ENTITY_ID=f87dsf7dsf9s7d9f8'); | ||
$this->client->configure(); | ||
|
||
$this->client->gauge('test_metric', 456); | ||
$this->assertEquals('test_metric:456|g|#dd.internal.entity_id:f87dsf7dsf9s7d9f8', $this->client->getLastMessage()); | ||
} | ||
|
||
public function testTagsAppended() | ||
{ | ||
putenv('DD_ENTITY_ID=f87dsf7dsf9s7d9f8'); | ||
$this->client->configure([ | ||
'tags' => ['key' => 'value'], | ||
]); | ||
|
||
$this->client->gauge('test_metric', 456); | ||
$this->assertEquals('test_metric:456|g|#key:value,dd.internal.entity_id:f87dsf7dsf9s7d9f8', $this->client->getLastMessage()); | ||
} | ||
} |