Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugger: e2e test #867

Merged
merged 14 commits into from
Jan 30, 2018
Merged
Show file tree
Hide file tree
Changes from 8 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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
"erusev/parsedown": "^1.6",
"vierbergenlars/php-semver": "^3.0",
"symfony/lock": "3.3.x-dev#1ba6ac9",
"phpseclib/phpseclib": "^2"
"phpseclib/phpseclib": "^2",
"google/cloud-tools": "^0.6"
},
"replace": {
"google/cloud-bigquery": "1.0.2",
Expand Down
168 changes: 168 additions & 0 deletions tests/system/Debugger/E2ETest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
<?php
/**
* Copyright 2018 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\Debugger;

use Google\Cloud\Debugger\V2\Gapic\Debugger2GapicClient as GapicClient;
use Google\Cloud\Debugger\V2\Breakpoint;
use Google\Cloud\Debugger\V2\SourceLocation;
use Google\Cloud\TestUtils\EventuallyConsistentTestTrait;
use Google\Cloud\TestUtils\AppEngineDeploymentTrait;
use GuzzleHttp\Client;
use PHPUnit\Framework\TestCase;

/**
* The test deploys the sample app contained in the app folder to Google App
* Engine Flexible Environment. Before deployment, we generate a composer.json
* that uses the current branch of google/cloud to test against.
*
* Each test sets a breakpoint, ensures that the app has seen the breakpoint,
* then makes a request to the app that should trigger the breakpoint. We then
* ensure that the breakpoint has been fulfilled.
*
* @group debugger

This comment was marked as spam.

This comment was marked as spam.

*/
class E2ETest extends TestCase
{
protected static $debuggeeId;
protected static $httpClient;

use AppEngineDeploymentTrait;
use EventuallyConsistentTestTrait;

public static function beforeDeploy()
{
self::createComposerJson();
self::$gcloudWrapper->setDir(implode(DIRECTORY_SEPARATOR, [__DIR__, 'app']));
}

public static function afterDeploy()
{
$url = self::$gcloudWrapper->getBaseUrl();
self::$httpClient = new Client(['base_uri' => $url]);

$resp = self::$httpClient->get('/debuggee');
$data = json_decode($resp->getBody()->getContents(), true);
self::$debuggeeId = $data['debuggeeId'];
}

public static function tearDownAfterClass()
{
self::deleteApp();
}

public static function createComposerJson()
{
$branch = exec('git rev-parse --abbrev-ref HEAD');

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

$origin = exec('git remote get-url origin');

This comment was marked as spam.

This comment was marked as spam.

$repo = 'GoogleCloudPlatform/google-cloud-php';
if (preg_match('/[:\/](.+\/[^\/\.]+)(\.git)?/', $origin, $matches)) {

This comment was marked as spam.

$repo = $matches[1];
}

$data = [
'name' => 'google/debugger-test-app',
'type' => 'project',
'require' => [
'php' => '^7.0',
'silex/silex' => '~2.0',
'google/cloud' => 'dev-' . $branch,
'ext-stackdriver_debugger' => '*'
],
'repositories' => [
[
'type' => 'git',
'url' => 'https://github.com/' . $repo
]
]
];
$file = implode(DIRECTORY_SEPARATOR, [__DIR__, 'app', 'composer.json']);
file_put_contents($file, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
}

public function testWithFullPath()
{
$this->setBreakpoint('web/app.php', 13);

$this->runEventuallyConsistentTest(function () {
$this->assertBreakpointCount(1);
});

$resp = self::$httpClient->get('hello/full');
$this->assertEquals('200', $resp->getStatusCode(), 'hello/full status code');
$this->assertContains('Hello, full', $resp->getBody()->getContents());

$this->runEventuallyConsistentTest(function () {
$this->assertBreakpointCount(0);
});
}

private function assertBreakpointCount($count)
{
$resp = self::$httpClient->get('/debuggee');
$data = json_decode($resp->getBody()->getContents(), true);
$this->assertEquals($count, (int) $data['numBreakpoints']);
}

public function testWithExtraPath()
{
$this->setBreakpoint('/extra/web/app.php', 13);

$this->runEventuallyConsistentTest(function () {
$this->assertBreakpointCount(1);
});

$resp = self::$httpClient->get('hello/extra');
$this->assertEquals('200', $resp->getStatusCode(), 'hello/extra status code');
$this->assertContains('Hello, extra', $resp->getBody()->getContents());

$this->runEventuallyConsistentTest(function () {
$this->assertBreakpointCount(0);
});
}

public function testWithMissingPath()
{
$this->setBreakpoint('app.php', 13);

$this->runEventuallyConsistentTest(function () {
$this->assertBreakpointCount(1);
});

$resp = self::$httpClient->get('hello/missing');
$this->assertEquals('200', $resp->getStatusCode(), 'hello/missing status code');
$this->assertContains('Hello, missing', $resp->getBody()->getContents());

$this->runEventuallyConsistentTest(function () {
$this->assertBreakpointCount(0);
});
}

private function setBreakpoint($file, $line)

This comment was marked as spam.

{
// Set a breakpoint
$client = new GapicClient();
$breakpoint = new Breakpoint();
$location = new SourceLocation();
$location->setPath($file);
$location->setLine($line);
$breakpoint->setLocation($location);
$resp = $client->setBreakpoint(self::$debuggeeId, $breakpoint, 'google.com/php/v0.1');
$bp = $resp->getBreakpoint();
$this->assertNotEmpty($bp->getId());
}
}
1 change: 1 addition & 0 deletions tests/system/Debugger/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
composer.json
11 changes: 11 additions & 0 deletions tests/system/Debugger/app/additional-supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[program:debugger-daemon]
command = php -d auto_prepend_file='' -d disable_functions='' /app/vendor/bin/google-cloud-debugger /app
stdout_logfile = /dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile = /dev/stderr
stderr_logfile_maxbytes=0
user = www-data
autostart = true
autorestart = true
priority = 5
stopwaitsecs = 20
9 changes: 9 additions & 0 deletions tests/system/Debugger/app/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
runtime: php
env: flex

runtime_config:
document_root: web
enable_stackdriver_integration: true

manual_scaling:
instances: 1
16 changes: 16 additions & 0 deletions tests/system/Debugger/app/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "google/debugger-test-app",
"type": "project",
"require": {
"php": "^7.0",
"silex/silex": "~2.0",
"google/cloud": "dev-debugger-e2e-test",
"ext-stackdriver_debugger": "*"
},
"repositories": [
{
"type": "git",
"url": "https://github.com/chingor13/google-cloud-php"
}
]
}
41 changes: 41 additions & 0 deletions tests/system/Debugger/app/web/app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Copyright 2018 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.
*/

require_once __DIR__ . '/../vendor/autoload.php';

use Symfony\Component\HttpFoundation\JsonResponse;

$app = new Silex\Application();

$app->get('/', function() {
return 'Silex version ' . Silex\Application::VERSION;
});

$app->get('/hello/{name}', function ($name) use ($app) {
return 'Hello, ' . $name;
});

$app->get('/debuggee', function () use ($app, $agent) {
$storage = new Google\Cloud\Debugger\BreakpointStorage\SysvBreakpointStorage();
list($debuggeeId, $breakpoints) = $storage->load();
return $app->json([
'debuggeeId' => $debuggeeId,
'numBreakpoints' => count($breakpoints)
], 200, ['Content-Type' => 'application/json']);
});

$app->run();
22 changes: 22 additions & 0 deletions tests/system/Debugger/app/web/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Copyright 2018 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.
*/

require_once __DIR__ . '/../vendor/autoload.php';

$agent = new Google\Cloud\Debugger\Agent(['sourceRoot' => realpath('../')]);

require 'app.php';