Skip to content

Commit

Permalink
test: unify integration setup (#275)
Browse files Browse the repository at this point in the history
* test: unify integration setup

* ci: correct debug urls
  • Loading branch information
AuHau authored Apr 21, 2021
1 parent 661df0d commit 4e482f5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ env:
REPLICA: 5
BEE_API_URL: 'http://bee-0.localhost'
BEE_PEER_API_URL: 'http://bee-1.localhost'
BEE_DEBUG_API_URL: 'http://bee-0-debug.localhost'
BEE_PEER_DEBUG_API_URL: 'http://bee-1-debug.localhost'
BEE_TEST_CHEQUEBOOK: true

jobs:
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,14 @@ npm i

The tests run in both context: node and dom with Jest.

To run the integration tests, you need to have a Bee cluster running locally. To create a cluster, please consult the readme of [@ethersphere/bee-local](https://github.com/ethersphere/bee-local).
To run the integration tests, you need to have a Bee cluster running locally. You can run your own local Bee client for test purposes with the help of [test/bee.sh](test/bee.sh).
If you pass `--ephemeral` flag, the container automatically will be removed at the end of the run.

By default, tests are run against local bee node 0 - `http://bee-0.localhost`. You can change it by setting environment variable `BEE_API_URL`.
In order to run tests which require one more node, you need to define `BEE_PEER_API_URL` as well. Its default value `http://bee-1.localhost`
By default, for integration tests two bee nodes are expected to run on localhost on addresses `http://localhost:1633` and `http://localhost:11633`. These are the default values for the `test/bee.sh` script.
If you want to use custom setup, you can change the behavior of tests to different addresses using environment variables `BEE_API_URL`, `BEE_DEBUG_API_URL`, `BEE_PEER_DEBUG_API_URL` and `BEE_PEER_API_URL`.

In Visual Studio environment, the tests have been set up to run against your local bee node on `http://localhost:1633`
To run Jest tests, choose the `vscode-jest-tests` CI job under the Run tab.
You can run your own local Bee client for test purposes with the help of [test/bee.sh](test/bee.sh).
If you pass `--ephemeral` flag, the container automatically will be removed at the end of the run.

There are also browser tests by Puppeteer, which also provide integrity testing.
```sh
Expand Down
4 changes: 2 additions & 2 deletions test/integration/modules/debug/balance.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { beeDebugUrl, beePeerUrl } from '../../../utils'
import { beeDebugUrl, beePeerDebugUrl, beePeerUrl } from '../../../utils'
import * as balance from '../../../../src/modules/debug/balance'
import * as connectivity from '../../../../src/modules/debug/connectivity'

// helper function to get the peer overlay address
async function getPeerOverlay() {
const nodeAddresses = await connectivity.getNodeAddresses(beeDebugUrl(beePeerUrl()))
const nodeAddresses = await connectivity.getNodeAddresses(beePeerDebugUrl())

return nodeAddresses.overlay
}
Expand Down
21 changes: 10 additions & 11 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,29 +105,28 @@ export function randomByteArray(length: number, seed = 500): Uint8Array {
* Returns a url for testing the Bee public API
*/
export function beeUrl(): string {
return process.env.BEE_API_URL || 'http://bee-0.localhost'
return process.env.BEE_API_URL || 'http://localhost:1633'
}

/**
* Returns a url of another peer for testing the Bee public API
*/
export function beePeerUrl(): string {
return process.env.BEE_PEER_API_URL || 'http://bee-1.localhost'
return process.env.BEE_PEER_API_URL || 'http://localhost:11633'
}

/**
* Returns a url for testing the Bee Debug API
*/
export function beeDebugUrl(url: string = beeUrl()): string {
const regexp = /http:\/\/bee-(\d).localhost/

if (url.match(regexp)) {
return url.replace(regexp, 'http://bee-$1-debug.localhost')
}
const urlObj = new URL(url)
const port = urlObj.port ? parseInt(urlObj.port, 10) + 2 : 1635
export function beeDebugUrl(): string {
return process.env.BEE_DEBUG_API_URL || 'http://localhost:1635'
}

return urlObj.protocol + '//' + urlObj.hostname + ':' + port
/**
* Returns a url for testing the Bee Debug API
*/
export function beePeerDebugUrl(): string {
return process.env.BEE_PEER_DEBUG_API_URL || 'http://localhost:11635'
}

/**
Expand Down

0 comments on commit 4e482f5

Please sign in to comment.