-
Notifications
You must be signed in to change notification settings - Fork 438
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
Debugger: e2e test #867
Changes from 9 commits
c6499ff
a3305e8
73822ea
9be5a42
93d551b
b658407
66e7b25
8de0570
08daabb
80cc9ea
2b848b5
a0d46fa
fd325e4
0fd7b60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
*/ | ||
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.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong. |
||
$origin = exec('git remote get-url origin'); | ||
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong. |
||
$repo = 'GoogleCloudPlatform/google-cloud-php'; | ||
if (preg_match('/[:\/](.+\/[^\/\.]+)(\.git)?/', $origin, $matches)) { | ||
This comment was marked as spam.
Sorry, something went wrong. |
||
$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.
Sorry, something went wrong. |
||
{ | ||
// 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()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
composer.json |
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 |
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 |
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(); |
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'; |
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.