|
| 1 | +<?php |
| 2 | +namespace InfluxDB\Integration; |
| 3 | + |
| 4 | +use InfluxDB\Adapter\Http\Options; |
| 5 | +use InfluxDB\Adapter\Http\Writer; |
| 6 | +use InfluxDB\Adapter\Http\Reader; |
| 7 | +use InfluxDB\Client; |
| 8 | +use InfluxDB\Query\CreateDatabase; |
| 9 | +use InfluxDB\Query\DeleteDatabase; |
| 10 | +use InfluxDB\Query\GetDatabases; |
| 11 | +use GuzzleHttp\Client as GuzzleHttpClient; |
| 12 | +use InfluxDB\Manager; |
| 13 | +use InfluxDB\Integration\Framework\TestCase; |
| 14 | + |
| 15 | +class ManagerTest extends TestCase |
| 16 | +{ |
| 17 | + public function testCreateANewDatabase() |
| 18 | + { |
| 19 | + $options = new Options(); |
| 20 | + $guzzleHttp = new GuzzleHttpClient(); |
| 21 | + $writer = new Writer($guzzleHttp, $options); |
| 22 | + $reader = new Reader($guzzleHttp, $options); |
| 23 | + $client = new Client($reader, $writer); |
| 24 | + $manager = new Manager($client); |
| 25 | + |
| 26 | + $manager->addQuery(new CreateDatabase()); |
| 27 | + $manager->addQuery(new DeleteDatabase()); |
| 28 | + $manager->addQuery(new GetDatabases()); |
| 29 | + |
| 30 | + $manager->createDatabase("one"); |
| 31 | + $manager->createDatabase("two"); |
| 32 | + $manager->createDatabase("walter"); |
| 33 | + |
| 34 | + $databases = $manager->getDatabases(); |
| 35 | + |
| 36 | + $this->assertCount(3, $databases["results"][0]["series"][0]["values"]); |
| 37 | + } |
| 38 | + |
| 39 | + public function testDropExistingDatabase() |
| 40 | + { |
| 41 | + $options = new Options(); |
| 42 | + $guzzleHttp = new GuzzleHttpClient(); |
| 43 | + $writer = new Writer($guzzleHttp, $options); |
| 44 | + $reader = new Reader($guzzleHttp, $options); |
| 45 | + $client = new Client($reader, $writer); |
| 46 | + $manager = new Manager($client); |
| 47 | + |
| 48 | + $manager->addQuery(new CreateDatabase()); |
| 49 | + $manager->addQuery(new DeleteDatabase()); |
| 50 | + $manager->addQuery(new GetDatabases()); |
| 51 | + |
| 52 | + $manager->createDatabase("walter"); |
| 53 | + $this->assertDatabasesCount(1); |
| 54 | + |
| 55 | + $manager->deleteDatabase("walter"); |
| 56 | + $this->assertDatabasesCount(0); |
| 57 | + } |
| 58 | + |
| 59 | + public function testListActiveDatabases() |
| 60 | + { |
| 61 | + $options = new Options(); |
| 62 | + $guzzleHttp = new GuzzleHttpClient(); |
| 63 | + $writer = new Writer($guzzleHttp, $options); |
| 64 | + $reader = new Reader($guzzleHttp, $options); |
| 65 | + $client = new Client($reader, $writer); |
| 66 | + $manager = new Manager($client); |
| 67 | + |
| 68 | + $manager->addQuery(new CreateDatabase()); |
| 69 | + $manager->addQuery(new DeleteDatabase()); |
| 70 | + $manager->addQuery(new GetDatabases()); |
| 71 | + |
| 72 | + $manager->createDatabase("one"); |
| 73 | + $manager->createDatabase("two"); |
| 74 | + |
| 75 | + $databases = $manager->getDatabases(); |
| 76 | + |
| 77 | + $this->assertCount(2, $databases["results"][0]["series"][0]["values"]); |
| 78 | + } |
| 79 | +} |
0 commit comments