Skip to content

Commit e9dca4c

Browse files
committed
feat: shared Repository test suite
Creates infrastructure for writing tests for different `Repositiory` interfaces and executing them against different Repository implementations (e.g. `DefaultCrudRepository` and `CrudRepositoryImpl`) and different databases (e.g. `MongoDB` and `MySQL`). The initial version of the shared test suite has only two very basic test cases to verify the testing infrastructure. My intention is to move relevant tests from `packages/repository/src/__tests__` to the new test suite later.
1 parent abda918 commit e9dca4c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2337
-33
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ npm-debug.log
55
coverage
66
.nyc_output
77
**/*.tgz
8+
acceptance/*/dist
89
packages/*/dist
910
examples/*/dist
1011
benchmark/dist

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ packages/tsdocs/fixtures/monorepo/docs
77
packages/tsdocs/fixtures/monorepo/**/dist
88
packages/tsdocs/fixtures/monorepo/**/docs
99
**/.sandbox
10+
acceptance/*/dist
1011
packages/*/dist
1112
examples/*/dist
1213
benchmark/dist

.travis.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,33 @@ matrix:
4040
os: linux
4141
env: TASK=verify-docs
4242
script: ./bin/verify-doc-changes.sh
43+
- node_js: "10"
44+
os: linux
45+
env:
46+
- TASK=test-repository-mongodb
47+
services:
48+
- mongodb
49+
script:
50+
- npm run postinstall -- --scope "@loopback/test-repository-mongodb" --include-filtered-dependencies
51+
- npm run build -- --scope "@loopback/test-repository-mongodb" --include-filtered-dependencies
52+
- cd acceptance/repository-mongodb && npm run mocha
53+
- node_js: "10"
54+
os: linux
55+
env:
56+
- TASK=test-repository-mysql
57+
- MYSQL_USER=test
58+
- MYSQL_PASSWORD=test
59+
services:
60+
- mysql
61+
before_install:
62+
- mysql -u root -e "CREATE USER 'test'@'localhost' IDENTIFIED BY 'test';"
63+
- mysql -e "use mysql; update user set authentication_string=PASSWORD('test') where User='test'; update user set plugin='mysql_native_password';FLUSH PRIVILEGES;"
64+
- mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'test'@'localhost' WITH GRANT OPTION;FLUSH PRIVILEGES;"
65+
- mysql -e "GRANT SUPER ON *.* TO 'test'@'localhost' IDENTIFIED BY 'test';FLUSH PRIVILEGES;"
66+
script:
67+
- npm run postinstall -- --scope "@loopback/test-repository-mysql" --include-filtered-dependencies
68+
- npm run build -- --scope "@loopback/test-repository-mysql" --include-filtered-dependencies
69+
- cd acceptance/repository-mysql && npm run mocha
4370

4471
branches:
4572
only:

CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
* @bajtos @raymondfeng
88

9+
acceptance/repository-mongodb/* @bajtos
10+
acceptance/repository-mysql/* @bajtos
911
packages/authentication/* @bajtos @raymondfeng
1012
packages/boot/* @raymondfeng @hacksparrow
1113
packages/booter-lb3app/* @bajtos @nabdelgadir
@@ -21,6 +23,7 @@ packages/openapi-spec-builder/* @bajtos @raymondfeng
2123
packages/openapi-v3/* @bajtos @jannyHou
2224
packages/openapi-v3-types/* @bajtos @jannyHou
2325
packages/repository/* @raymondfeng
26+
packages/repository-tests/* @bajtos
2427
packages/repository-json-schema/* @bajtos
2528
packages/rest/* @bajtos @raymondfeng
2629
packages/service-proxy/* @raymondfeng

acceptance/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Acceptance tests
2+
3+
This directory contains packages with acceptance-level tests. These tests are
4+
not invoked as part of root `npm test`, you have to run them manually. Consult
5+
README files of individual packages for instructions on how to run the tests.

acceptance/repository-mongodb/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=true

acceptance/repository-mongodb/LICENSE

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Copyright (c) IBM Corp. 2017,2019. All Rights Reserved.
2+
Node module: @loopback/test-repository-mongodb
3+
This project is licensed under the MIT License, full text below.
4+
5+
--------
6+
7+
MIT license
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a copy
10+
of this software and associated documentation files (the "Software"), to deal
11+
in the Software without restriction, including without limitation the rights
12+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
copies of the Software, and to permit persons to whom the Software is
14+
furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included in
17+
all copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
THE SOFTWARE.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# @loopback/test-repository-mongodb
2+
3+
Acceptance tests for `@loopback/repository` + `loopback-connector-mongodb`.
4+
5+
## Running the test suite
6+
7+
### Using own MongoDB instance
8+
9+
If you have a local MongoDB instance listening on `localhost` and the default
10+
port, use the following command:
11+
12+
```bash
13+
npm test
14+
```
15+
16+
If you have a local or remote MongoDB instance and would like to use that to run
17+
the test suite, use the following command:
18+
19+
**Linux & MacOS**
20+
21+
```bash
22+
MONGODB_HOST=<HOST> MONGODB_PORT=<PORT> MONGODB_DATABASE=<DATABASE> npm test
23+
```
24+
25+
**Windows**
26+
27+
```bash
28+
SET MONGODB_HOST=<HOST>
29+
SET MONGODB_PORT=<PORT>
30+
SET MONGODB_DATABASE=<DATABASE>
31+
npm test
32+
```
33+
34+
### Using Docker (Linux, MacOS, WSL)
35+
36+
If you do not have a local MongoDB instance, you can also run the test suite
37+
with very minimal requirements.
38+
39+
- Assuming you have [Docker](https://docs.docker.com/engine/installation/)
40+
installed, run the following script which would spawn a MongoDB instance on
41+
your local:
42+
43+
```bash
44+
source setup.sh <HOST> <PORT> <DATABASE>
45+
```
46+
47+
Where `<HOST>`, `<PORT>` and `<DATABASE>` are optional parameters. The default
48+
values are `localhost`, `27017` and `testdb` respectively.
49+
50+
- Run the test:
51+
52+
```bash
53+
npm test
54+
```
55+
56+
## Contributors
57+
58+
See
59+
[all contributors](https://github.com/strongloop/loopback-next/graphs/contributors).
60+
61+
## License
62+
63+
MIT
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright IBM Corp. 2019. All Rights Reserved.
2+
// Node module: @loopback/test-repository-mongodb
3+
// This file is licensed under the MIT License.
4+
// License text available at https://opensource.org/licenses/MIT
5+
6+
export * from './dist';
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright IBM Corp. 2019. All Rights Reserved.
2+
// Node module: @loopback/test-repository-mongodb
3+
// This file is licensed under the MIT License.
4+
// License text available at https://opensource.org/licenses/MIT
5+
6+
module.exports = require('./dist');

0 commit comments

Comments
 (0)