-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial logging system tests * Fix capitalization of namespace (#233) * initial pubsub system tests (#230) * initial datastore system tests (#228) * initial datastore system tests * Fix capitalization of namespace (#233) * initial pubsub system tests (#230) * initial storage system tests (#231) * initial storage system tests * Fix capitalization of namespace (#233) * initial pubsub system tests (#230) * initial datastore system tests (#228) * initial datastore system tests * Fix capitalization of namespace (#233) * initial pubsub system tests (#230)
- Loading branch information
Showing
5 changed files
with
596 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,95 @@ | ||
<?php | ||
/** | ||
* Copyright 2016 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Google\Cloud\Tests\System\Logging; | ||
|
||
use Google\Cloud\ExponentialBackoff; | ||
use Google\Cloud\BigQuery\BigQueryClient; | ||
use Google\Cloud\Logging\LoggingClient; | ||
use Google\Cloud\PubSub\PubSubClient; | ||
use Google\Cloud\Storage\StorageClient; | ||
|
||
class LoggingTestCase extends \PHPUnit_Framework_TestCase | ||
{ | ||
const TESTING_PREFIX = 'gcloud_testing_'; | ||
|
||
protected static $bucket; | ||
protected static $dataset; | ||
protected static $deletionQueue = []; | ||
protected static $grpcClient; | ||
protected static $restClient; | ||
protected static $topic; | ||
private static $hasSetUp = false; | ||
|
||
public function clientProvider() | ||
{ | ||
self::setUpBeforeClass(); | ||
|
||
return [ | ||
[self::$restClient], | ||
[self::$grpcClient] | ||
]; | ||
} | ||
|
||
public static function setUpBeforeClass() | ||
{ | ||
if (self::$hasSetUp) { | ||
return; | ||
} | ||
|
||
$keyFilePath = getenv('GOOGLE_CLOUD_PHP_TESTS_KEY_PATH'); | ||
self::$bucket = (new StorageClient([ | ||
'keyFilePath' => $keyFilePath | ||
]))->createBucket(uniqid(self::TESTING_PREFIX)); | ||
self::$dataset = (new BigQueryClient([ | ||
'keyFilePath' => $keyFilePath | ||
]))->createDataset(uniqid(self::TESTING_PREFIX)); | ||
self::$restClient = new LoggingClient([ | ||
'keyFilePath' => $keyFilePath, | ||
'transport' => 'rest' | ||
]); | ||
self::$grpcClient = new LoggingClient([ | ||
'keyFilePath' => $keyFilePath, | ||
'transport' => 'grpc' | ||
]); | ||
self::$topic = (new PubSubClient([ | ||
'keyFilePath' => $keyFilePath, | ||
'transport' => 'rest' | ||
]))->createTopic(uniqid(self::TESTING_PREFIX)); | ||
self::$hasSetUp = true; | ||
} | ||
|
||
public static function tearDownFixtures() | ||
{ | ||
if (!self::$hasSetUp) { | ||
return; | ||
} | ||
|
||
self::$deletionQueue[] = self::$dataset; | ||
self::$deletionQueue[] = self::$bucket; | ||
self::$deletionQueue[] = self::$topic; | ||
$backoff = new ExponentialBackoff(8); | ||
|
||
foreach (self::$deletionQueue as $item) { | ||
$backoff->execute(function () use ($item) { | ||
$item->delete(); | ||
}); | ||
} | ||
} | ||
} | ||
|
||
|
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,100 @@ | ||
<?php | ||
/** | ||
* Copyright 2016 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Google\Cloud\Tests\System\Logging; | ||
|
||
class ManageMetricsTest extends LoggingTestCase | ||
{ | ||
/** | ||
* @dataProvider clientProvider | ||
*/ | ||
public function testListsMetrics($client) | ||
{ | ||
$found = true; | ||
$name = uniqid(self::TESTING_PREFIX); | ||
$metric = $client->createMetric($name, 'severity >= DEBUG', [ | ||
'description' => 'A description.' | ||
]); | ||
self::$deletionQueue[] = $metric; | ||
|
||
$metrics = iterator_to_array($client->metrics()); | ||
|
||
foreach ($metrics as $metric) { | ||
if ($metric->name() === $name) { | ||
$found = true; | ||
} | ||
} | ||
|
||
$this->assertTrue($found); | ||
} | ||
|
||
/** | ||
* @dataProvider clientProvider | ||
*/ | ||
public function testCreateMetric($client) | ||
{ | ||
$name = uniqid(self::TESTING_PREFIX); | ||
$filter = 'severity >= DEBUG'; | ||
$options = [ | ||
'description' => 'A description.', | ||
]; | ||
$this->assertFalse($client->metric($name)->exists()); | ||
|
||
$metric = $client->createMetric($name, $filter, $options); | ||
self::$deletionQueue[] = $metric; | ||
|
||
$this->assertTrue($client->metric($name)->exists()); | ||
$this->assertEquals($filter, $metric->info()['filter']); | ||
$this->assertEquals($options['description'], $metric->info()['description']); | ||
} | ||
|
||
/** | ||
* @dataProvider clientProvider | ||
*/ | ||
public function testUpdateMetric($client) | ||
{ | ||
$name = uniqid(self::TESTING_PREFIX); | ||
$updateOptions = [ | ||
'description' => 'A new description', | ||
'filter' => 'severity >= INFO' | ||
]; | ||
$metric = $client->createMetric($name, 'severity >= DEBUG', [ | ||
'description' => 'A description.', | ||
]); | ||
self::$deletionQueue[] = $metric; | ||
|
||
$info = $metric->update($updateOptions); | ||
|
||
$this->assertEquals($name, $metric->name()); | ||
$this->assertEquals($updateOptions['filter'], $info['filter']); | ||
$this->assertEquals($updateOptions['description'], $info['description']); | ||
} | ||
|
||
/** | ||
* @dataProvider clientProvider | ||
*/ | ||
public function testReloadMetric($client) | ||
{ | ||
$name = uniqid(self::TESTING_PREFIX); | ||
$filter = 'severity >= ERROR'; | ||
$metric = $client->createMetric($name, $filter, [ | ||
'description' => 'A description.' | ||
]); | ||
|
||
$this->assertEquals($filter, $metric->reload()['filter']); | ||
} | ||
} |
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,136 @@ | ||
<?php | ||
/** | ||
* Copyright 2016 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Google\Cloud\Tests\System\Logging; | ||
|
||
class ManageSinksTest extends LoggingTestCase | ||
{ | ||
/** | ||
* @dataProvider clientProvider | ||
*/ | ||
public function testListsSinks($client) | ||
{ | ||
$found = true; | ||
$name = uniqid(self::TESTING_PREFIX); | ||
$sink = $client->createSink( | ||
$name, | ||
sprintf( | ||
'bigquery.googleapis.com/projects/%s/datasets/%s', | ||
self::$dataset->identity()['projectId'], | ||
self::$dataset->identity()['datasetId'] | ||
), | ||
[ | ||
'outputVersionFormat' => 'V2', | ||
'filter' => 'severity >= ERROR' | ||
] | ||
); | ||
self::$deletionQueue[] = $sink; | ||
|
||
$sinks = iterator_to_array($client->sinks()); | ||
|
||
foreach ($sinks as $sink) { | ||
if ($sink->name() === $name) { | ||
$found = true; | ||
} | ||
} | ||
|
||
$this->assertTrue($found); | ||
} | ||
|
||
/** | ||
* @dataProvider createSinkProvider | ||
*/ | ||
public function testCreateSink($client, $destination) | ||
{ | ||
$name = uniqid(self::TESTING_PREFIX); | ||
$options = [ | ||
'outputVersionFormat' => 'V2', | ||
'filter' => 'severity >= ERROR' | ||
]; | ||
$this->assertFalse($client->sink($name)->exists()); | ||
|
||
$sink = $client->createSink($name, $destination, $options); | ||
self::$deletionQueue[] = $sink; | ||
|
||
$this->assertTrue($client->sink($name)->exists()); | ||
$this->assertEquals($destination, $sink->info()['destination']); | ||
$this->assertEquals($options['outputVersionFormat'], $sink->info()['outputVersionFormat']); | ||
$this->assertEquals($options['filter'], $sink->info()['filter']); | ||
} | ||
|
||
public function createSinkProvider() | ||
{ | ||
self::setUpBeforeClass(); | ||
$bucket = self::$bucket; | ||
$bucket->acl()->add('[email protected]', 'OWNER');- | ||
$bucketDest = sprintf('storage.googleapis.com/%s', $bucket->name()); | ||
$datasetDest = sprintf( | ||
'bigquery.googleapis.com/projects/%s/datasets/%s', | ||
self::$dataset->identity()['projectId'], | ||
self::$dataset->identity()['datasetId'] | ||
); | ||
$topicDest = sprintf('pubsub.googleapis.com/%s', self::$topic->info()['name']); | ||
|
||
return [ | ||
[self::$restClient, $bucketDest], | ||
[self::$restClient, $datasetDest], | ||
[self::$restClient, $topicDest], | ||
[self::$grpcClient, $bucketDest], | ||
[self::$grpcClient, $datasetDest], | ||
[self::$grpcClient, $topicDest] | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider clientProvider | ||
*/ | ||
public function testUpdateSink($client) | ||
{ | ||
$name = uniqid(self::TESTING_PREFIX); | ||
$destination = sprintf('pubsub.googleapis.com/%s', self::$topic->info()['name']); | ||
$createOptions = [ | ||
'outputVersionFormat' => 'V2', | ||
'filter' => 'severity >= ERROR' | ||
]; | ||
$updateOptions = [ | ||
'filter' => 'severity >= DEBUG' | ||
]; | ||
$sink = $client->createSink($name, $destination, $createOptions); | ||
self::$deletionQueue[] = $sink; | ||
|
||
$info = $sink->update($updateOptions); | ||
|
||
$this->assertEquals($name, $sink->name()); | ||
$this->assertEquals($updateOptions['filter'], $info['filter']); | ||
} | ||
|
||
/** | ||
* @dataProvider clientProvider | ||
*/ | ||
public function testReloadSink($client) | ||
{ | ||
$name = uniqid(self::TESTING_PREFIX); | ||
$options = [ | ||
'outputVersionFormat' => 'V2', | ||
'filter' => 'severity >= ERROR' | ||
]; | ||
$destination = sprintf('pubsub.googleapis.com/%s', self::$topic->info()['name']); | ||
$sink = $client->createSink($name, $destination, $options); | ||
|
||
$this->assertEquals($options['outputVersionFormat'], $sink->reload()['outputVersionFormat']); | ||
} | ||
} |
Oops, something went wrong.