Skip to content

Commit

Permalink
Merge pull request #33041 from owncloud/test-acceptance-cli-infrastru…
Browse files Browse the repository at this point in the history
…cture

Test acceptance cli infrastructure
  • Loading branch information
paurakhsharma authored Oct 8, 2018
2 parents eaf2f7e + 9415c8c commit 782913b
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 18 deletions.
23 changes: 23 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,19 @@ pipeline:
matrix:
TEST_SUITE: api

cli-acceptance-tests:
image: owncloudci/php:${PHP_VERSION}
pull: true
environment:
- TEST_SERVER_URL=https://server
commands:
- touch /drone/saved-settings.sh
- . /drone/saved-settings.sh
- make test-acceptance-cli TESTING_REMOTE_SYSTEM=true
when:
matrix:
TEST_SUITE: cli

webui-acceptance-tests:
image: owncloudci/php:${PHP_VERSION}
pull: true
Expand Down Expand Up @@ -791,6 +804,16 @@ matrix:
CHOWN_SERVER: true
OWNCLOUD_LOG: true

# CLI Acceptance tests
- PHP_VERSION: 7.1
TEST_SUITE: cli
BEHAT_SUITE: cliProvisioning
DB_TYPE: mariadb
USE_SERVER: true
INSTALL_SERVER: true
CHOWN_SERVER: true
OWNCLOUD_LOG: true

# UI Acceptance tests
- PHP_VERSION: 7.1
TEST_SUITE: selenium
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ help:
@echo -e "make test-js\t\t\trun Javascript tests"
@echo -e "make test-js-debug\t\trun Javascript tests in debug mode (continuous)"
@echo -e "make test-acceptance-api\trun API acceptance tests"
@echo -e "make test-acceptance-cli\trun CLI acceptance tests"
@echo -e "make test-acceptance-webui\trun webUI acceptance tests"
@echo -e "make clean-test\t\t\tclean test results"
@echo
Expand Down Expand Up @@ -185,6 +186,10 @@ test-js-debug: $(nodejs_deps)
test-acceptance-api: $(composer_dev_deps)
./tests/acceptance/run.sh --type api

.PHONY: test-acceptance-cli
test-acceptance-cli: $(composer_dev_deps)
./tests/acceptance/run.sh --type cli

.PHONY: test-acceptance-webui
test-acceptance-webui: $(composer_dev_deps)
./tests/acceptance/run.sh --type webUI
Expand All @@ -208,7 +213,7 @@ test-php-phan: $(PHAN_BIN)
php $(PHAN_BIN) --config-file .phan/config.php --require-config-exists -p

.PHONY: test
test: test-php-lint test-php-style test-php test-js test-acceptance-api test-acceptance-webui
test: test-php-lint test-php-style test-php test-js test-acceptance-api test-acceptance-cli test-acceptance-webui

.PHONY: clean-test-acceptance
clean-test-acceptance:
Expand Down
7 changes: 7 additions & 0 deletions tests/acceptance/config/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ default:
- FeatureContext: *common_feature_context_params
- LoggingContext:

cliProvisioning:
paths:
- %paths.base%/../features/cliProvisioning
contexts:
- FeatureContext: *common_feature_context_params
- OccContext:

webUIAdminSettings:
paths:
- %paths.base%/../features/webUIAdminSettings
Expand Down
28 changes: 14 additions & 14 deletions tests/acceptance/features/bootstrap/CommandLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,13 @@ public function theCommandOutputContainsTheText($text) {
// end of the captured string, so trim them.
$text = \trim($text, $text[0]);
$lines = $this->findLines($this->lastStdOut, $text);
if (empty($lines)) {
throw new \Exception(
"The command output did not contain the expected text on stdout '$text'\n" .
"The command output on stdout was:\n" .
$this->lastStdOut
);
}
PHPUnit_Framework_Assert::assertGreaterThanOrEqual(
1,
\count($lines),
"The command output did not contain the expected text on stdout '$text'\n" .
"The command output on stdout was:\n" .
$this->lastStdOut
);
}

/**
Expand All @@ -299,13 +299,13 @@ public function theCommandErrorOutputContainsTheText($text) {
// end of the captured string, so trim them.
$text = \trim($text, $text[0]);
$lines = $this->findLines($this->lastStdErr, $text);
if (empty($lines)) {
throw new \Exception(
"The command output did not contain the expected text on stderr '$text'\n" .
"The command output on stderr was:\n" .
$this->lastStdOut
);
}
PHPUnit_Framework_Assert::assertGreaterThanOrEqual(
1,
\count($lines),
"The command output did not contain the expected text on stderr '$text'\n" .
"The command output on stderr was:\n" .
$this->lastStdErr
);
}

private $lastTransferPath;
Expand Down
13 changes: 13 additions & 0 deletions tests/acceptance/features/bootstrap/WebDav.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,19 @@ public function userUsingPasswordShouldNotBeAbleToDownloadFile(
);
}

/**
* @Then /^user "([^"]*)" should be able to access a skeleton file$/
*
* @param string $user
*
* @return void
*/
public function userShouldBeAbleToAccessASkeletonFile($user) {
$this->contentOfFileForUserShouldBePlusEndOfLine(
"textfile0.txt", $user, "ownCloud test text file 0"
);
}

/**
* @Then /^the downloaded content should be "([^"]*)"$/
*
Expand Down
31 changes: 31 additions & 0 deletions tests/acceptance/features/cliProvisioning/addUser.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@cli @skipOnLDAP
Feature: add a user using the using the occ command

As an administrator
I want to be able to add users via the command line
So that I can give people controlled individual access to resources on the ownCloud server and
So that I can write scripts to add users

Scenario: admin creates an ordinary user using the occ command
When the administrator creates this user using the occ command:
| username |
| justauser |
Then the command should have been successful
And the command output should contain the text 'The user "justauser" was created successfully'
And user "justauser" should exist
And user "justauser" should be able to access a skeleton file

Scenario: admin creates an ordinary user sspecifying attributes using the occ command
When the administrator creates this user using the occ command:
| username | displayname | email |
| justauser | Just A User | justauser@example.com |
Then the command should have been successful
And the command output should contain the text 'The user "justauser" was created successfully'
And the command output should contain the text 'Display name set to "Just A User"'
And the command output should contain the text 'Email address set to "justauser@example.com"'
And user "justauser" should exist
And user "justauser" should be able to access a skeleton file
When the administrator retrieves the information of user "justauser" using the provisioning API
Then the user attributes returned by the API should include
| displayname | Just A User |
| email | justauser@example.com |
24 changes: 21 additions & 3 deletions tests/acceptance/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fi
# -c or --config - specify a behat.yml to use
# --feature - specify a single feature to run
# --suite - specify a single suite to run
# --type - api or webui - if no individual feature or suite is specified, then
# --type - api, cli or webui - if no individual feature or suite is specified, then
# specify the type of acceptance tests to run. Default api.
# --tags - specify tags for scenarios to run (or not)
# --browser - for webUI tests, which browser to use. "chrome", "firefox",
Expand Down Expand Up @@ -103,7 +103,7 @@ do
shift
;;
--type)
# Lowercase the parameter value, so the user can provide "API", "webUI" etc
# Lowercase the parameter value, so the user can provide "API", "CLI", "webUI" etc
ACCEPTANCE_TEST_TYPE="${2,,}"
shift
;;
Expand Down Expand Up @@ -552,15 +552,24 @@ then
TEST_TYPE_TAG="@webUI"
TEST_TYPE_TEXT="webUI"
RUNNING_API_TESTS=false
RUNNING_CLI_TESTS=false
RUNNING_WEBUI_TESTS=true
elif [[ "${BEHAT_SUITE}" == cli* ]] || [ "${ACCEPTANCE_TEST_TYPE}" = "cli" ]
then
TEST_TYPE_TAG="@cli"
TEST_TYPE_TEXT="cli"
RUNNING_API_TESTS=false
RUNNING_CLI_TESTS=true
RUNNING_WEBUI_TESTS=false
else
TEST_TYPE_TAG="@api"
TEST_TYPE_TEXT="API"
RUNNING_API_TESTS=true
RUNNING_CLI_TESTS=false
RUNNING_WEBUI_TESTS=false
fi

# Always have one of "@api" or "@webUI" filter tags
# Always have one of "@api", "@cli" or "@webUI" filter tags
if [ -z "${BEHAT_FILTER_TAGS}" ]
then
BEHAT_FILTER_TAGS="${TEST_TYPE_TAG}"
Expand Down Expand Up @@ -634,6 +643,11 @@ fi
if [ "${RUNNING_API_TESTS}" = true ]
then
export SRC_SKELETON_DIR="${SCRIPT_PATH}/../../apps/testing/data/apiSkeleton"
elif [ "${RUNNING_CLI_TESTS}" = true ]
then
# CLI tests use the apiSkeleton so that API-based "then" steps can be used
# to check the state of users after CLI commands
export SRC_SKELETON_DIR="${SCRIPT_PATH}/../../apps/testing/data/apiSkeleton"
else
export SRC_SKELETON_DIR="${SCRIPT_PATH}/../../apps/testing/data/webUISkeleton"
fi
Expand Down Expand Up @@ -795,6 +809,10 @@ else
fi

if [ "${RUNNING_API_TESTS}" = true ]
then
EXTRA_CAPABILITIES=""
BROWSER_TEXT=""
elif [ "${RUNNING_CLI_TESTS}" = true ]
then
EXTRA_CAPABILITIES=""
BROWSER_TEXT=""
Expand Down

0 comments on commit 782913b

Please sign in to comment.