From bbe479bcd94ea9bdcebe973b17487c5ca015934b Mon Sep 17 00:00:00 2001 From: Daniel Calviño Sánchez Date: Wed, 19 Apr 2017 07:58:18 +0200 Subject: Generalize names and descriptions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Calviño Sánchez --- .drone.yml | 4 +- .../core/NextcloudTestServerDroneHelper.php | 134 --------------------- .../core/NextcloudTestServerLocalHelper.php | 134 +++++++++++++++++++++ build/acceptance/run-drone.sh | 75 ------------ build/acceptance/run-local.sh | 75 ++++++++++++ 5 files changed, 211 insertions(+), 211 deletions(-) delete mode 100644 build/acceptance/features/core/NextcloudTestServerDroneHelper.php create mode 100644 build/acceptance/features/core/NextcloudTestServerLocalHelper.php delete mode 100755 build/acceptance/run-drone.sh create mode 100755 build/acceptance/run-local.sh diff --git a/.drone.yml b/.drone.yml index 9996b5df5cf..b768fd3f1ea 100644 --- a/.drone.yml +++ b/.drone.yml @@ -481,14 +481,14 @@ pipeline: acceptance-access-levels: image: nextcloudci/php7.0:php7.0-7 commands: - - build/acceptance/run-drone.sh features/access-levels.feature + - build/acceptance/run-local.sh features/access-levels.feature when: matrix: TESTS-ACCEPTANCE: access-levels acceptance-login: image: nextcloudci/php7.0:php7.0-7 commands: - - build/acceptance/run-drone.sh features/login.feature + - build/acceptance/run-local.sh features/login.feature when: matrix: TESTS-ACCEPTANCE: login diff --git a/build/acceptance/features/core/NextcloudTestServerDroneHelper.php b/build/acceptance/features/core/NextcloudTestServerDroneHelper.php deleted file mode 100644 index 23f6db2df97..00000000000 --- a/build/acceptance/features/core/NextcloudTestServerDroneHelper.php +++ /dev/null @@ -1,134 +0,0 @@ -. - * - */ - -/** - * Helper to manage a Nextcloud test server when acceptance tests are run in a - * Drone step. - * - * The Nextcloud test server is executed using the PHP built-in web server - * directly from the grandparent directory of the acceptance tests directory - * (that is, the root directory of the Nextcloud server); note that the - * acceptance tests must be run from the acceptance tests directory. The "setUp" - * method resets the Nextcloud server to its initial state and starts it, while - * the "cleanUp" method stops it. To be able to reset the Nextcloud server to - * its initial state a Git repository must be provided in the root directory of - * the Nextcloud server; the last commit in that Git repository must provide the - * initial state for the Nextcloud server expected by the acceptance tests. - * - * The Nextcloud server is available at "127.0.0.1", so it is expected to see - * "127.0.0.1" as a trusted domain (which would be the case if it was installed - * by running "occ maintenance:install"). The base URL to access the Nextcloud - * server can be got from "getBaseUrl". - */ -class NextcloudTestServerDroneHelper implements NextcloudTestServerHelper { - - /** - * @var string - */ - private $phpServerPid; - - /** - * Creates a new NextcloudTestServerDroneHelper. - */ - public function __construct() { - $this->phpServerPid = ""; - } - - /** - * Sets up the Nextcloud test server. - * - * It resets the Nextcloud test server restoring its last saved Git state - * and then waits for the Nextcloud test server to start again; if the - * server can not be reset or if it does not start again after some time an - * exception is thrown (as it is just a warning for the test runner and - * nothing to be explicitly catched a plain base Exception is used). - * - * @throws \Exception if the Nextcloud test server can not be reset or - * started again. - */ - public function setUp() { - // Ensure that previous PHP server is not running (as cleanUp may not - // have been called). - $this->killPhpServer(); - - $this->execOrException("cd ../../ && git reset --hard HEAD"); - $this->execOrException("cd ../../ && git clean -d --force"); - - // execOrException is not used because the server is started in the - // background, so the command will always succeed even if the server - // itself fails. - $this->phpServerPid = exec("php -S 127.0.0.1:80 -t ../../ >/dev/null 2>&1 & echo $!"); - - $timeout = 60; - if (!Utils::waitForServer($this->getBaseUrl(), $timeout)) { - throw new Exception("Nextcloud test server could not be started"); - } - } - - /** - * Cleans up the Nextcloud test server. - * - * It kills the running Nextcloud test server, if any. - */ - public function cleanUp() { - $this->killPhpServer(); - } - - /** - * Returns the base URL of the Nextcloud test server. - * - * @return string the base URL of the Nextcloud test server. - */ - public function getBaseUrl() { - return "http://127.0.0.1/index.php"; - } - - /** - * Executes the given command, throwing an Exception if it fails. - * - * @param string $command the command to execute. - * @throws \Exception if the command fails to execute. - */ - private function execOrException($command) { - exec($command . " 2>&1", $output, $returnValue); - if ($returnValue != 0) { - throw new Exception("'$command' could not be executed: " . implode("\n", $output)); - } - } - - /** - * Kills the PHP built-in web server started in setUp, if any. - */ - private function killPhpServer() { - if ($this->phpServerPid == "") { - return; - } - - // execOrException is not used because the PID may no longer exist when - // trying to kill it. - exec("kill " . $this->phpServerPid); - - $this->phpServerPid = ""; - } - -} diff --git a/build/acceptance/features/core/NextcloudTestServerLocalHelper.php b/build/acceptance/features/core/NextcloudTestServerLocalHelper.php new file mode 100644 index 00000000000..32b5330c61a --- /dev/null +++ b/build/acceptance/features/core/NextcloudTestServerLocalHelper.php @@ -0,0 +1,134 @@ +. + * + */ + +/** + * Helper to manage a Nextcloud test server started directly by the acceptance + * tests themselves using the PHP built-in web server. + * + * The Nextcloud test server is executed using the PHP built-in web server + * directly from the grandparent directory of the acceptance tests directory + * (that is, the root directory of the Nextcloud server); note that the + * acceptance tests must be run from the acceptance tests directory. The "setUp" + * method resets the Nextcloud server to its initial state and starts it, while + * the "cleanUp" method stops it. To be able to reset the Nextcloud server to + * its initial state a Git repository must be provided in the root directory of + * the Nextcloud server; the last commit in that Git repository must provide the + * initial state for the Nextcloud server expected by the acceptance tests. + * + * The Nextcloud server is available at "127.0.0.1", so it is expected to see + * "127.0.0.1" as a trusted domain (which would be the case if it was installed + * by running "occ maintenance:install"). The base URL to access the Nextcloud + * server can be got from "getBaseUrl". + */ +class NextcloudTestServerLocalHelper implements NextcloudTestServerHelper { + + /** + * @var string + */ + private $phpServerPid; + + /** + * Creates a new NextcloudTestServerLocalHelper. + */ + public function __construct() { + $this->phpServerPid = ""; + } + + /** + * Sets up the Nextcloud test server. + * + * It resets the Nextcloud test server restoring its last saved Git state + * and then waits for the Nextcloud test server to start again; if the + * server can not be reset or if it does not start again after some time an + * exception is thrown (as it is just a warning for the test runner and + * nothing to be explicitly catched a plain base Exception is used). + * + * @throws \Exception if the Nextcloud test server can not be reset or + * started again. + */ + public function setUp() { + // Ensure that previous PHP server is not running (as cleanUp may not + // have been called). + $this->killPhpServer(); + + $this->execOrException("cd ../../ && git reset --hard HEAD"); + $this->execOrException("cd ../../ && git clean -d --force"); + + // execOrException is not used because the server is started in the + // background, so the command will always succeed even if the server + // itself fails. + $this->phpServerPid = exec("php -S 127.0.0.1:80 -t ../../ >/dev/null 2>&1 & echo $!"); + + $timeout = 60; + if (!Utils::waitForServer($this->getBaseUrl(), $timeout)) { + throw new Exception("Nextcloud test server could not be started"); + } + } + + /** + * Cleans up the Nextcloud test server. + * + * It kills the running Nextcloud test server, if any. + */ + public function cleanUp() { + $this->killPhpServer(); + } + + /** + * Returns the base URL of the Nextcloud test server. + * + * @return string the base URL of the Nextcloud test server. + */ + public function getBaseUrl() { + return "http://127.0.0.1/index.php"; + } + + /** + * Executes the given command, throwing an Exception if it fails. + * + * @param string $command the command to execute. + * @throws \Exception if the command fails to execute. + */ + private function execOrException($command) { + exec($command . " 2>&1", $output, $returnValue); + if ($returnValue != 0) { + throw new Exception("'$command' could not be executed: " . implode("\n", $output)); + } + } + + /** + * Kills the PHP built-in web server started in setUp, if any. + */ + private function killPhpServer() { + if ($this->phpServerPid == "") { + return; + } + + // execOrException is not used because the PID may no longer exist when + // trying to kill it. + exec("kill " . $this->phpServerPid); + + $this->phpServerPid = ""; + } + +} diff --git a/build/acceptance/run-drone.sh b/build/acceptance/run-drone.sh deleted file mode 100755 index c90a79c95e0..00000000000 --- a/build/acceptance/run-drone.sh +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env bash - -# @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) -# -# @license GNU AGPL version 3 or any later version -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -# Helper script to run the acceptance tests, which test a running Nextcloud -# instance from the point of view of a real user, in a Drone step. -# -# The acceptance tests are written in Behat so, besides running the tests, this -# script installs Behat, its dependencies, and some related packages in the -# "vendor" subdirectory of the acceptance tests. The acceptance tests expect -# that the last commit in the Git repository provides the default state of the -# Nextcloud server, so the script installs the Nextcloud server and saves a -# snapshot of the whole grandparent directory (no .gitignore file is used) in -# the Git repository. Finally, the acceptance tests also use the Selenium server -# to control a web browser, so this script waits for the Selenium server -# (provided in its own Drone service) to be ready before running the tests. - -# Exit immediately on errors. -set -o errexit - -# Ensure working directory is script directory, as some actions (like installing -# Behat through Composer or running Behat) expect that. -cd "$(dirname $0)" - -SCENARIO_TO_RUN=$1 - -composer install - -# Although Behat documentation states that using the BEHAT_PARAMS environment -# variable "You can set any value for any option that is available in a -# behat.yml file" this is currently not true for the constructor parameters of -# contexts (see https://github.com/Behat/Behat/issues/983). Thus, the default -# "behat.yml" configuration file has to be adjusted to provide the appropriate -# parameters for NextcloudTestServerContext. -ORIGINAL="\ - - NextcloudTestServerContext" -REPLACEMENT="\ - - NextcloudTestServerContext:\n\ - nextcloudTestServerHelper: NextcloudTestServerDroneHelper\n\ - nextcloudTestServerHelperParameters:" -sed "s/$ORIGINAL/$REPLACEMENT/" config/behat.yml > config/behat-drone.yml - -cd ../../ - -echo "Installing and configuring Nextcloud server" -build/acceptance/installAndConfigureServer.sh - -echo "Saving the default state so acceptance tests can reset to it" -find . -name ".gitignore" -exec rm --force {} \; -git add --all && echo 'Default state' | git -c user.name='John Doe' -c user.email='john@doe.org' commit --quiet --file=- - -cd build/acceptance - -# The Selenium server should be ready by now, as Composer typically takes way -# longer to execute than its startup (which is done in parallel in a Drone -# service), but just in case. -echo "Waiting for Selenium" -timeout 60s bash -c "while ! curl 127.0.0.1:4444 >/dev/null 2>&1; do sleep 1; done" - -vendor/bin/behat --config=config/behat-drone.yml $SCENARIO_TO_RUN diff --git a/build/acceptance/run-local.sh b/build/acceptance/run-local.sh new file mode 100755 index 00000000000..900b0ba30a4 --- /dev/null +++ b/build/acceptance/run-local.sh @@ -0,0 +1,75 @@ +#!/usr/bin/env bash + +# @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com) +# +# @license GNU AGPL version 3 or any later version +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +# Helper script to run the acceptance tests, which test a running Nextcloud +# instance from the point of view of a real user, configured to start the +# Nextcloud server themselves and from their grandparent directory. +# +# The acceptance tests are written in Behat so, besides running the tests, this +# script installs Behat, its dependencies, and some related packages in the +# "vendor" subdirectory of the acceptance tests. The acceptance tests expect +# that the last commit in the Git repository provides the default state of the +# Nextcloud server, so the script installs the Nextcloud server and saves a +# snapshot of the whole grandparent directory (no .gitignore file is used) in +# the Git repository. Finally, the acceptance tests also use the Selenium server +# to control a web browser, so this script waits for the Selenium server +# (which should have been started before executing this script) to be ready +# before running the tests. + +# Exit immediately on errors. +set -o errexit + +# Ensure working directory is script directory, as some actions (like installing +# Behat through Composer or running Behat) expect that. +cd "$(dirname $0)" + +SCENARIO_TO_RUN=$1 + +composer install + +# Although Behat documentation states that using the BEHAT_PARAMS environment +# variable "You can set any value for any option that is available in a +# behat.yml file" this is currently not true for the constructor parameters of +# contexts (see https://github.com/Behat/Behat/issues/983). Thus, the default +# "behat.yml" configuration file has to be adjusted to provide the appropriate +# parameters for NextcloudTestServerContext. +ORIGINAL="\ + - NextcloudTestServerContext" +REPLACEMENT="\ + - NextcloudTestServerContext:\n\ + nextcloudTestServerHelper: NextcloudTestServerLocalHelper\n\ + nextcloudTestServerHelperParameters:" +sed "s/$ORIGINAL/$REPLACEMENT/" config/behat.yml > config/behat-local.yml + +cd ../../ + +echo "Installing and configuring Nextcloud server" +build/acceptance/installAndConfigureServer.sh + +echo "Saving the default state so acceptance tests can reset to it" +find . -name ".gitignore" -exec rm --force {} \; +git add --all && echo 'Default state' | git -c user.name='John Doe' -c user.email='john@doe.org' commit --quiet --file=- + +cd build/acceptance + +# Ensure that the Selenium server is ready before running the tests. +echo "Waiting for Selenium" +timeout 60s bash -c "while ! curl 127.0.0.1:4444 >/dev/null 2>&1; do sleep 1; done" + +vendor/bin/behat --config=config/behat-local.yml $SCENARIO_TO_RUN -- cgit v1.2.3