Skip to content

Commit

Permalink
issue 3305 add report into integration tests (hyperledger-archives#3337)
Browse files Browse the repository at this point in the history
issue 3305 add report into integration tests

Signed-off-by: Sam Smith <[email protected]>
  • Loading branch information
samjsmith authored and cazfletch committed Feb 7, 2018
1 parent c242e04 commit 646b5d4
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 1 deletion.
41 changes: 40 additions & 1 deletion packages/composer-tests-integration/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,41 @@
# Composer-Integration-Tests
Integration tests for Hyperledger Composer
## Integration tests for Hyperledger Composer

To run the tests, make sure you've lerna bootstrapped and then run the script that starts the integration tests with

```
./scripts/run-integration-tests.sh
```

Note that this leaves a load of docker containers hanging around afterwards which you can get rid of using the good old

```
docker ps -aq | xargs docker kill
docker rm $(docker ps -aq)
```

As long as the script finishes, it should tidy up all the artifacts that are created during tests but if it fails then you
may have to do a manual clean up.

## Manual testing

Sometimes you might want to run an individual test in which case you can use the tagging feature of cucumber like this.
First modify your `.feature` file to include a suitable tag.

```
@testdeservespenguin
Scenario: Using the CLI, I can run a composer fish command to create some fish
When I run the following CLI command
"""
composer fish
"""
Then The stdout information should include text matching /your fish has been created/
```

Then you can modify the `test-inner` task in the `package.json` file to add your tag like this:

```
"test-inner": "cucumber-js --tags @testdeservespenguin",
```


12 changes: 12 additions & 0 deletions packages/composer-tests-integration/features/cli.feature
Original file line number Diff line number Diff line change
Expand Up @@ -367,5 +367,17 @@ Feature: Cli steps
Then The stdout information should include text matching /The current identity, with the name '.+?' and the identifier '.+?', has been revoked/
Then The stderr information should include text matching /List business network from card bob@basic-sample-network/

@sams
Scenario: Using the CLI, I can run a composer report command to create a file about the current environment
When I run the following CLI command
"""
composer report
"""
Then The stdout information should include text matching /Creating Composer report/
Then The stdout information should include text matching /Triggering node report.../
Then The stdout information should include text matching /Created archive file: composer-report-/
Then The stdout information should include text matching /Command succeeded/
Then A new file matching this regex should be created /composer-report-/



4 changes: 4 additions & 0 deletions packages/composer-tests-integration/lib/clisteps.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ module.exports = function () {
this.Then(/^The stderr information should include text matching \/(.+?)\/$/, function (regex) {
return this.composer.checkConsoleOutput(new RegExp(regex), true);
});

this.Then(/^A new file matching this regex should be created \/(.+?)\/$/, function (regex) {
return this.composer.checkFileWasCreated(new RegExp(regex));
});
};
21 changes: 21 additions & 0 deletions packages/composer-tests-integration/lib/composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,27 @@ class Composer {
});
}

/**
* Check that a file with a name matching the regex has been created.
* @param {RegExp} [regex] regular expression.
* @return {Promise} - Pomise that will be resolved or rejected with an error
*/
checkFileWasCreated(regex) {
return new Promise( (resolve, reject) => {
let fileExists = false;
fs.readdirSync('.').forEach((file) => {
if(file.match(regex)) {
fileExists = true;
}
});
if(fileExists) {
resolve();
} else {
reject('could not find file with name matching ', regex);
}
});
}

/**
* Check the HTTP response status
* @param {Number} code expected HTTP response code.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ for INTEST in $(echo ${INTEST} | tr "," " "); do
rm -rf ./tmp/*
rm -rf ./networkadmin
rm -rf ${HOME}/.npmrc
rm ./*.tgz
rm ./networkadmin.card
if [ "${DOCKER_FILE}" != "" ]; then
cd ../composer-runtime-hlfv1
rm .npmrc
Expand Down

0 comments on commit 646b5d4

Please sign in to comment.