Skip to content

Commit

Permalink
Merge pull request #9 from jgedarovich/master
Browse files Browse the repository at this point in the history
allow ssl to be used for jenknis_url
  • Loading branch information
jgedarovich committed Apr 15, 2015
2 parents 6884923 + c7a3322 commit ab03300
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
9 changes: 6 additions & 3 deletions TryLib/JenkinsRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ public function __construct(
$try_job_name,
$cmd_runner
) {
$this->jenkins_url = $jenkins_url;
if (filter_var($jenkins_url, FILTER_VALIDATE_URL) !== false) {
$this->jenkins_url = $jenkins_url;
} else {
throw new Exception("jenkins url must include protocol, ie http://, and trailing /, $jenkins_url given");
}
$this->jenkins_cli = $jenkins_cli;
$this->try_job_name = $try_job_name;
$this->cmd_runner = $cmd_runner;
Expand All @@ -47,8 +51,7 @@ abstract protected function getBuildCommand();
abstract protected function getBuildExtraArguments($show_results, $show_progress);

public function runJenkinsCommand($command) {
$cmd = sprintf(
"java -jar %s -s http://%s/ %s",
$cmd = sprintf( "java -jar %s -s %s %s",
$this->jenkins_cli,
$this->jenkins_url,
$command
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/JenkinsRunner/FreeStyleProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require_once "TryLib/Autoload.php";

class FreeStyleProjectTest extends PHPUnit_Framework_TestCase {
const JENKINS_URL = 'url.to.jenkins.com:8080';
const JENKINS_URL = 'http://url.to.jenkins.com:8080/';
const JENKINS_CLI = '/path/to/cli.jar';
const JENKINS_JOB = 'test-try';

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/JenkinsRunner/MasterProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require_once "TryLib/Autoload.php";

class MasterProjectTest extends PHPUnit_Framework_TestCase {
const JENKINS_URL = 'url.to.jenkins.com:8080';
const JENKINS_URL = 'http://url.to.jenkins.com:8080/';
const JENKINS_CLI = '/path/to/cli.jar';
const JENKINS_JOB = 'test-try';

Expand Down
17 changes: 15 additions & 2 deletions tests/phpunit/JenkinsRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function pollForCompletion($pretty) {
}

class JenkinsRunnerTest extends PHPUnit_Framework_TestCase {
const JENKINS_URL = 'url.to.jenkins.com:8080';
const JENKINS_URL = 'https://url.to.jenkins.com:8080/';
const JENKINS_CLI = '/path/to/cli.jar';
const JENKINS_JOB = 'test-try';

Expand All @@ -42,8 +42,21 @@ function setUp() {
vfsStream::setup('testDir');
}

/**
* @expectedException
*/
function testInvalidUrl() {
$this->jenkins_runner = new TestRunner(
'http://totallyvalid.com/',
self::JENKINS_CLI,
self::JENKINS_JOB,
$this->mock_cmd_runner
);
}


function testRunJenkinsCommand() {
$expected_cmd = 'java -jar ' . self::JENKINS_CLI . ' -s http://' . self::JENKINS_URL . '/ dummy-cmd';
$expected_cmd = 'java -jar ' . self::JENKINS_CLI . ' -s ' . self::JENKINS_URL . ' dummy-cmd';

$this->mock_cmd_runner->expects($this->once())
->method('run')
Expand Down

0 comments on commit ab03300

Please sign in to comment.