Skip to content

Commit

Permalink
Merge branch 'main' into add-functions-preload-sample
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerthatdev authored Oct 26, 2023
2 parents 8822b49 + 2112888 commit 1a6e09f
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 25 deletions.
Binary file modified .kokoro/secrets.sh.enc
Binary file not shown.
4 changes: 2 additions & 2 deletions appengine/flexible/metadata/test/DeployTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testIndex()
'200',
$resp->getStatusCode(),
'Top page status code should be 200');
$this->assertRegExp('/External IP: .*/', (string) $resp->getBody());
$this->assertMatchesRegularExpression('/External IP: .*/', (string) $resp->getBody());
}

public function testCurl()
Expand All @@ -42,6 +42,6 @@ public function testCurl()
'200',
$resp->getStatusCode(),
'/curl status code should be 200');
$this->assertRegExp('/External IP: .*/', (string) $resp->getBody());
$this->assertMatchesRegularExpression('/External IP: .*/', (string) $resp->getBody());
}
}
7 changes: 3 additions & 4 deletions dlp/src/deidentify_cloud_storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
use Google\Cloud\Dlp\V2\InspectJobConfig;
use Google\Cloud\Dlp\V2\TransformationConfig;
use Google\Cloud\Dlp\V2\TransformationDetailsStorageConfig;
use Google\Cloud\Dlp\V2\Client\BaseClient\DlpServiceBaseClient;
use Google\Cloud\Dlp\V2\DlpJob\JobState;

/**
Expand Down Expand Up @@ -104,13 +103,13 @@ function deidentify_cloud_storage(
// Specify the de-identify template used for the transformation.
$transformationConfig = (new TransformationConfig())
->setDeidentifyTemplate(
DlpServiceBaseClient::projectDeidentifyTemplateName($callingProjectId, $deidentifyTemplateName)
DlpServiceClient::projectDeidentifyTemplateName($callingProjectId, $deidentifyTemplateName)
)
->setStructuredDeidentifyTemplate(
DlpServiceBaseClient::projectDeidentifyTemplateName($callingProjectId, $structuredDeidentifyTemplateName)
DlpServiceClient::projectDeidentifyTemplateName($callingProjectId, $structuredDeidentifyTemplateName)
)
->setImageRedactTemplate(
DlpServiceBaseClient::projectDeidentifyTemplateName($callingProjectId, $imageRedactTemplateName)
DlpServiceClient::projectDeidentifyTemplateName($callingProjectId, $imageRedactTemplateName)
);

$deidentify = (new Deidentify())
Expand Down
8 changes: 4 additions & 4 deletions monitoring/test/alertsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function testCreatePolicy()
$output = $this->runFunctionSnippet('alert_create_policy', [
'projectId' => self::$projectId,
]);
$this->assertRegexp($regexp, $output);
$this->assertMatchesRegularExpression($regexp, $output);

// Save the policy ID for later
preg_match($regexp, $output, $matches);
Expand Down Expand Up @@ -93,7 +93,7 @@ public function testCreateChannel()
$output = $this->runFunctionSnippet('alert_create_channel', [
'projectId' => self::$projectId,
]);
$this->assertRegexp($regexp, $output);
$this->assertMatchesRegularExpression($regexp, $output);

// Save the channel ID for later
preg_match($regexp, $output, $matches);
Expand All @@ -111,14 +111,14 @@ public function testReplaceChannel()
$output = $this->runFunctionSnippet('alert_create_channel', [
'projectId' => self::$projectId,
]);
$this->assertRegexp($regexp, $output);
$this->assertMatchesRegularExpression($regexp, $output);
preg_match($regexp, $output, $matches);
$channelId1 = $matches[1];

$output = $this->runFunctionSnippet('alert_create_channel', [
'projectId' => self::$projectId,
]);
$this->assertRegexp($regexp, $output);
$this->assertMatchesRegularExpression($regexp, $output);
preg_match($regexp, $output, $matches);
$channelId2 = $matches[1];

Expand Down
2 changes: 1 addition & 1 deletion pubsub/api/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"require": {
"google/cloud-pubsub": "^1.39",
"google/cloud-pubsub": "^1.46",
"rg/avro-php": "^2.0.1||^3.0.0"
}
}
53 changes: 53 additions & 0 deletions pubsub/api/src/create_cloud_storage_subscription.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* Copyright 2023 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.
*/

/**
* For instructions on how to run the full sample:
*
* @see https://github.com/GoogleCloudPlatform/php-docs-samples/blob/main/pubsub/api/README.md
*/

namespace Google\Cloud\Samples\PubSub;

# [START pubsub_create_cloud_storage_subscription]
use Google\Cloud\PubSub\PubSubClient;

/**
* Creates a Pub/Sub GCS subscription.
*
* @param string $projectId The Google project ID.
* @param string $topicName The Pub/Sub topic name.
* @param string $subscriptionName The Pub/Sub subscription name.
* @param string $bucket The Cloud Storage bucket name without any prefix like "gs://".
*/
function create_cloud_storage_subscription($projectId, $topicName, $subscriptionName, $bucket)
{
$pubsub = new PubSubClient([
'projectId' => $projectId,
]);
$topic = $pubsub->topic($topicName);
$subscription = $topic->subscription($subscriptionName);
$config = ['bucket' => $bucket];
$subscription->create([
'cloudStorageConfig' => $config
]);

printf('Subscription created: %s' . PHP_EOL, $subscription->name());
}
# [END pubsub_create_cloud_storage_subscription]
require_once __DIR__ . '/../../../testing/sample_helpers.php';
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);
31 changes: 28 additions & 3 deletions pubsub/api/test/pubsubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,31 @@ public function testCreateAndDeleteBigQuerySubscription()
$this->assertMatchesRegularExpression(sprintf('/%s/', $subscription), $output);
}

public function testCreateAndDeleteStorageSubscription()
{
$topic = $this->requireEnv('GOOGLE_PUBSUB_TOPIC');
$subscription = 'test-subscription-' . rand();
$bucket = $this->requireEnv('GOOGLE_PUBSUB_STORAGE_BUCKET');

$output = $this->runFunctionSnippet('create_cloud_storage_subscription', [
self::$projectId,
$topic,
$subscription,
$bucket,
]);

$this->assertMatchesRegularExpression('/Subscription created:/', $output);
$this->assertMatchesRegularExpression(sprintf('/%s/', $subscription), $output);

$output = $this->runFunctionSnippet('delete_subscription', [
self::$projectId,
$subscription,
]);

$this->assertMatchesRegularExpression('/Subscription deleted:/', $output);
$this->assertMatchesRegularExpression(sprintf('/%s/', $subscription), $output);
}

public function testCreateAndDetachSubscription()
{
$topic = $this->requireEnv('GOOGLE_PUBSUB_TOPIC');
Expand Down Expand Up @@ -433,14 +458,14 @@ public function testPublishAndSubscribeWithOrderingKeys()
self::$projectId,
$topic,
]);
$this->assertRegExp('/Message published/', $output);
$this->assertMatchesRegularExpression('/Message published/', $output);

$output = $this->runFunctionSnippet('enable_subscription_ordering', [
self::$projectId,
$topic,
'subscriberWithOrdering' . rand(),
]);
$this->assertRegExp('/Created subscription with ordering/', $output);
$this->assertRegExp('/\"enableMessageOrdering\":true/', $output);
$this->assertMatchesRegularExpression('/Created subscription with ordering/', $output);
$this->assertMatchesRegularExpression('/\"enableMessageOrdering\":true/', $output);
}
}
6 changes: 3 additions & 3 deletions run/laravel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ The configuration is similar to the deployment to Cloud Run, requiring the datab
1. Create a Cloud Run job to apply database migrations:
```
gcloud beta run jobs create migrate \
gcloud run jobs create migrate \
--image=${REGISTRY_NAME}/laravel \
--region=${REGION} \
--set-cloudsql-instances ${PROJECT_ID}:${REGION}:${INSTANCE_NAME} \
Expand All @@ -247,7 +247,7 @@ The configuration is similar to the deployment to Cloud Run, requiring the datab
1. Execute the job:
```
gcloud beta run jobs execute migrate --region ${REGION} --wait
gcloud run jobs execute migrate --region ${REGION} --wait
```
* Confirm the application of database migrations by clicking the "See logs for this execution" link.
Expand Down Expand Up @@ -323,7 +323,7 @@ To apply application code changes, update the Cloud Run service with this new co
To apply database migrations, run the Cloud Run job using the newly built container:
```bash
gcloud beta run jobs execute migrate --region ${REGION}
gcloud run jobs execute migrate --region ${REGION}
```
Note: To generate new migrations to apply, you will need to run `php artisan make:migration` in a local development environment.
Expand Down
6 changes: 2 additions & 4 deletions run/laravel/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@
colors="true"
>
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
<directory>tests/Feature</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./app</directory>
</include>
</coverage>

<php>
<env name="APP_ENV" value="testing"/>
<env name="BCRYPT_ROUNDS" value="4"/>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion speech/test/speechTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function testTranscribe($command, $audioFile, $requireGrpc = false)

// Check for the word time offsets
if (in_array($command, ['transcribe_async_words'])) {
$this->assertRegexp('/start: "*.*s", end: "*.*s/', $output);
$this->assertMatchesRegularExpression('/start: "*.*s", end: "*.*s/', $output);
}
}

Expand Down
2 changes: 1 addition & 1 deletion storage/test/IamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function testListIamMembers()
%s
/', self::$user);
$this->assertRegexp($binding, $output);
$this->assertMatchesRegularExpression($binding, $output);

$bindingWithCondition = sprintf(
'Role: roles/storage.objectViewer
Expand Down
4 changes: 2 additions & 2 deletions vision/test/visionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function testLandmarkCommand()
{
$path = __DIR__ . '/data/tower.jpg';
$output = $this->runFunctionSnippet('detect_landmark', ['path' => $path]);
$this->assertRegexp(
$this->assertMatchesRegularExpression(
'/Eiffel Tower|Champ de Mars|Trocadéro Gardens/',
$output
);
Expand All @@ -131,7 +131,7 @@ public function testLandmarkCommandGcs()

$path = 'gs://' . $bucketName . '/vision/tower.jpg';
$output = $this->runFunctionSnippet('detect_landmark_gcs', ['path' => $path]);
$this->assertRegexp(
$this->assertMatchesRegularExpression(
'/Eiffel Tower|Champ de Mars|Trocadéro Gardens/',
$output
);
Expand Down

0 comments on commit 1a6e09f

Please sign in to comment.