Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 1 addition & 49 deletions functions/firebase_firestore/test/DeployTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
use Google\Cloud\Firestore\FirestoreClient;
use Google\Cloud\Logging\LoggingClient;
use Google\Cloud\TestUtils\CloudFunctionDeploymentTrait;
use Google\Cloud\TestUtils\EventuallyConsistentTestTrait;
use Google\Cloud\TestUtils\GcloudWrapper\CloudFunction;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\ExpectationFailedException;

/**
* Class DeployTest.
Expand All @@ -38,7 +35,6 @@
class DeployTest extends TestCase
{
use CloudFunctionDeploymentTrait;
use EventuallyConsistentTestTrait;

/** @var string */
private static $entryPoint = 'firebaseFirestore';
Expand Down Expand Up @@ -108,7 +104,7 @@ public function testFirebaseFirestore(array $data, string $expected): void
sleep(5);

$fiveMinAgo = date(\DateTime::RFC3339, strtotime('-5 minutes'));
$this->processFunctionLogs(self::$fn, $fiveMinAgo, function (\Iterator $logs) use ($expected) {
$this->processFunctionLogs($fiveMinAgo, function (\Iterator $logs) use ($expected) {
// Concatenate all relevant log messages.
$actual = '';
foreach ($logs as $log) {
Expand All @@ -124,50 +120,6 @@ public function testFirebaseFirestore(array $data, string $expected): void
});
}

/**
* Retrieve and process logs for the defined function.
*
* @param CloudFunction $fn function whose logs should be checked.
* @param string $startTime RFC3339 timestamp marking start of time range to retrieve.
* @param callable $process callback function to run on the logs.
*/
private function processFunctionLogs(CloudFunction $fn, string $startTime, callable $process)
{
$projectId = self::requireEnv('GOOGLE_PROJECT_ID');

if (empty(self::$loggingClient)) {
self::$loggingClient = new LoggingClient([
'projectId' => $projectId
]);
}

// Define the log search criteria.
$logFullName = 'projects/' . $projectId . '/logs/cloudfunctions.googleapis.com%2Fcloud-functions';
$filter = sprintf(
'logName="%s" resource.labels.function_name="%s" timestamp>="%s"',
$logFullName,
$fn->getFunctionName(),
$startTime
);

echo "\nRetrieving logs [$filter]...\n";

// Check for new logs for the function.
$attempt = 1;
$this->runEventuallyConsistentTest(function () use ($filter, $process, &$attempt) {
$entries = self::$loggingClient->entries(['filter' => $filter]);

// If no logs came in try again.
if (empty($entries->current())) {
echo 'Logs not found, attempting retry #' . $attempt++ . PHP_EOL;
throw new ExpectationFailedException('Log Entries not available');
}
echo 'Processing logs...' . PHP_EOL;

$process($entries);
}, $retries = 10);
}

/**
* Update a value in Firebase Realtime Database (RTDB).
*
Expand Down
50 changes: 1 addition & 49 deletions functions/firebase_remote_config/test/DeployTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
use Google\Auth\CredentialsLoader;
use Google\Cloud\Logging\LoggingClient;
use Google\Cloud\TestUtils\CloudFunctionDeploymentTrait;
use Google\Cloud\TestUtils\EventuallyConsistentTestTrait;
use Google\Cloud\TestUtils\GcloudWrapper\CloudFunction;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\ExpectationFailedException;

/**
* Class DeployTest.
Expand All @@ -39,7 +36,6 @@
class DeployTest extends TestCase
{
use CloudFunctionDeploymentTrait;
use EventuallyConsistentTestTrait;

/** @var string */
private static $entryPoint = 'firebaseRemoteConfig';
Expand Down Expand Up @@ -110,7 +106,7 @@ public function testFirebaseRemoteConfig(
sleep(5);

$fiveMinAgo = date(\DateTime::RFC3339, strtotime('-5 minutes'));
$this->processFunctionLogs(self::$fn, $fiveMinAgo, function (\Iterator $logs) use ($expected, $label) {
$this->processFunctionLogs($fiveMinAgo, function (\Iterator $logs) use ($expected, $label) {
// Concatenate all relevant log messages.
$actual = '';
foreach ($logs as $log) {
Expand All @@ -126,50 +122,6 @@ public function testFirebaseRemoteConfig(
});
}

/**
* Retrieve and process logs for the defined function.
*
* @param CloudFunction $fn function whose logs should be checked.
* @param string $startTime RFC3339 timestamp marking start of time range to retrieve.
* @param callable $process callback function to run on the logs.
*/
private function processFunctionLogs(CloudFunction $fn, string $startTime, callable $process)
{
$projectId = self::requireEnv('GOOGLE_PROJECT_ID');

if (empty(self::$loggingClient)) {
self::$loggingClient = new LoggingClient([
'projectId' => $projectId
]);
}

// Define the log search criteria.
$logFullName = 'projects/' . $projectId . '/logs/cloudfunctions.googleapis.com%2Fcloud-functions';
$filter = sprintf(
'logName="%s" resource.labels.function_name="%s" timestamp>="%s"',
$logFullName,
$fn->getFunctionName(),
$startTime
);

echo "\nRetrieving logs [$filter]...\n";

// Check for new logs for the function.
$attempt = 1;
$this->runEventuallyConsistentTest(function () use ($filter, $process, &$attempt) {
$entries = self::$loggingClient->entries(['filter' => $filter]);

// If no logs came in try again.
if (empty($entries->current())) {
echo 'Logs not found, attempting retry #' . $attempt++ . PHP_EOL;
throw new ExpectationFailedException('Log Entries not available');
}
echo 'Processing logs...' . PHP_EOL;

$process($entries);
}, $retries = 10);
}

/**
* Update a value in Firebase Remote Config.
*
Expand Down
50 changes: 1 addition & 49 deletions functions/helloworld_pubsub/test/DeployTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@

use Google\Cloud\Logging\LoggingClient;
use Google\Cloud\TestUtils\CloudFunctionDeploymentTrait;
use Google\Cloud\TestUtils\EventuallyConsistentTestTrait;
use Google\Cloud\TestUtils\GcloudWrapper\CloudFunction;
use Google\Cloud\PubSub\PubSubClient;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\ExpectationFailedException;

/**
* Class DeployTest.
Expand All @@ -38,7 +35,6 @@
class DeployTest extends TestCase
{
use CloudFunctionDeploymentTrait;
use EventuallyConsistentTestTrait;

private static $entryPoint = 'helloworldPubsub';

Expand Down Expand Up @@ -80,7 +76,7 @@ public function testHelloworldPubsub(string $name, string $expected, string $lab
sleep(60);

$fiveMinAgo = date(\DateTime::RFC3339, strtotime('-5 minutes'));
$this->processFunctionLogs(self::$fn, $fiveMinAgo, function (\Iterator $logs) use ($name, $expected, $label) {
$this->processFunctionLogs($fiveMinAgo, function (\Iterator $logs) use ($name, $expected, $label) {
// Concatenate all relevant log messages.
$actual = '';
foreach ($logs as $log) {
Expand All @@ -106,50 +102,6 @@ private function publishMessage(string $name): void
]);
}

/**
* Retrieve and process logs for the defined function.
*
* @param CloudFunction $fn function whose logs should be checked.
* @param string $startTime RFC3339 timestamp marking start of time range to retrieve.
* @param callable $process callback function to run on the logs.
*/
private function processFunctionLogs(CloudFunction $fn, string $startTime, callable $process)
{
$projectId = self::requireEnv('GOOGLE_PROJECT_ID');

if (empty(self::$loggingClient)) {
self::$loggingClient = new LoggingClient([
'projectId' => $projectId
]);
}

// Define the log search criteria.
$logFullName = 'projects/' . $projectId . '/logs/cloudfunctions.googleapis.com%2Fcloud-functions';
$filter = sprintf(
'logName="%s" resource.labels.function_name="%s" timestamp>="%s"',
$logFullName,
$fn->getFunctionName(),
$startTime
);

echo "\nRetrieving logs [$filter]...\n";

// Check for new logs for the function.
$attempt = 1;
$this->runEventuallyConsistentTest(function () use ($filter, $process, &$attempt) {
$entries = self::$loggingClient->entries(['filter' => $filter]);

// If no logs came in try again.
if (empty($entries->current())) {
echo 'Logs not found, attempting retry #' . $attempt++ . PHP_EOL;
throw new ExpectationFailedException('Log Entries not available');
}
echo 'Processing logs...' . PHP_EOL;

$process($entries);
}, $retries = 10);
}

/**
* Deploy the Cloud Function, called from DeploymentTrait::deployApp().
*
Expand Down
49 changes: 1 addition & 48 deletions functions/helloworld_storage/test/DeployTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
use Google\Cloud\Logging\LoggingClient;
use Google\Cloud\Storage\StorageClient;
use Google\Cloud\TestUtils\CloudFunctionDeploymentTrait;
use Google\Cloud\TestUtils\EventuallyConsistentTestTrait;
use Google\Cloud\TestUtils\GcloudWrapper\CloudFunction;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\ExpectationFailedException;

/**
* Class DeployTest.
Expand All @@ -38,7 +35,6 @@
class DeployTest extends TestCase
{
use CloudFunctionDeploymentTrait;
use EventuallyConsistentTestTrait;

/** @var string */
private static $entryPoint = 'helloGCS';
Expand Down Expand Up @@ -90,7 +86,7 @@ public function testHelloGCS(string $name, string $expected): void
sleep(5);

$fiveMinAgo = date(\DateTime::RFC3339, strtotime('-5 minutes'));
$this->processFunctionLogs(self::$fn, $fiveMinAgo, function (\Iterator $logs) use ($expected) {
$this->processFunctionLogs($fiveMinAgo, function (\Iterator $logs) use ($expected) {
// Concatenate all relevant log messages.
$actual = '';
foreach ($logs as $log) {
Expand All @@ -106,49 +102,6 @@ public function testHelloGCS(string $name, string $expected): void
unlink($objectUri);
}

/**
* Retrieve and process logs for the defined function.
*
* @param CloudFunction $fn function whose logs should be checked.
* @param string $startTime RFC3339 timestamp marking start of time range to retrieve.
* @param callable $process callback function to run on the logs.
*/
private function processFunctionLogs(CloudFunction $fn, string $startTime, callable $process)
{
$projectId = self::requireEnv('GOOGLE_PROJECT_ID');

if (empty(self::$loggingClient)) {
self::$loggingClient = new LoggingClient([
'projectId' => $projectId
]);
}

// Define the log search criteria.
$logFullName = 'projects/' . $projectId . '/logs/cloudfunctions.googleapis.com%2Fcloud-functions';
$filter = sprintf('logName="%s" resource.labels.function_name="%s" timestamp>="%s"',
$logFullName,
$fn->getFunctionName(),
$startTime
);

echo "\nRetrieving logs [$filter]...\n";

// Check for new logs for the function.
$attempt = 1;
$this->runEventuallyConsistentTest(function () use ($filter, $process, &$attempt) {
$entries = self::$loggingClient->entries(['filter' => $filter]);

// If no logs came in try again.
if (empty($entries->current())) {
echo 'Logs not found, attempting retry #' . $attempt++ . PHP_EOL;
throw new ExpectationFailedException('Log Entries not available');
}
echo 'Processing logs...' . PHP_EOL;

$process($entries);
}, $retries = 10);
}

/**
* Upload data to the storage bucket.
*
Expand Down
50 changes: 1 addition & 49 deletions functions/imagemagick/test/DeployTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
use Google\Cloud\Storage\StorageClient;
use Google\Cloud\Logging\LoggingClient;
use Google\Cloud\TestUtils\CloudFunctionDeploymentTrait;
use Google\Cloud\TestUtils\EventuallyConsistentTestTrait;
use Google\Cloud\TestUtils\GcloudWrapper\CloudFunction;
use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Framework\TestCase;

require_once __DIR__ . '/TestCasesTrait.php';
Expand All @@ -40,7 +37,6 @@
class DeployTest extends TestCase
{
use CloudFunctionDeploymentTrait;
use EventuallyConsistentTestTrait;
use TestCasesTrait;

/** @var string */
Expand Down Expand Up @@ -89,7 +85,7 @@ public function testFunction(
sleep(5);

$fiveMinAgo = date(\DateTime::RFC3339, strtotime('-5 minutes'));
$this->processFunctionLogs(self::$fn, $fiveMinAgo, function (\Iterator $logs) use ($expected, $label) {
$this->processFunctionLogs($fiveMinAgo, function (\Iterator $logs) use ($expected, $label) {
// Concatenate all relevant log messages.
$actual = '';
foreach ($logs as $log) {
Expand All @@ -103,50 +99,6 @@ public function testFunction(
});
}

/**
* Retrieve and process logs for the defined function.
*
* @param CloudFunction $fn function whose logs should be checked.
* @param string $startTime RFC3339 timestamp marking start of time range to retrieve.
* @param callable $process callback function to run on the logs.
*/
private function processFunctionLogs(CloudFunction $fn, string $startTime, callable $process)
{
$projectId = self::requireEnv('GOOGLE_PROJECT_ID');

if (empty(self::$loggingClient)) {
self::$loggingClient = new LoggingClient([
'projectId' => $projectId
]);
}

// Define the log search criteria.
$logFullName = 'projects/' . $projectId . '/logs/cloudfunctions.googleapis.com%2Fcloud-functions';
$filter = sprintf(
'logName="%s" resource.labels.function_name="%s" timestamp>="%s"',
$logFullName,
$fn->getFunctionName(),
$startTime
);

echo "\nRetrieving logs [$filter]...\n";

// Check for new logs for the function.
$attempt = 1;
$this->runEventuallyConsistentTest(function () use ($filter, $process, &$attempt) {
$entries = self::$loggingClient->entries(['filter' => $filter]);

// If no logs came in try again.
if (empty($entries->current())) {
echo 'Logs not found, attempting retry #' . $attempt++ . PHP_EOL;
throw new ExpectationFailedException('Log Entries not available');
}
echo 'Processing logs...' . PHP_EOL;

$process($entries);
}, $retries = 10);
}

/**
* Deploy the Function.
*
Expand Down
Loading