Skip to content
This repository has been archived by the owner on Dec 17, 2019. It is now read-only.

Commit

Permalink
feat: integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
psturc committed Nov 12, 2018
1 parent fb430db commit 7e28a91
Show file tree
Hide file tree
Showing 7 changed files with 356 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ main
.r.logs.log
server.log
*/_tmp*
*/node_modules
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,18 @@ Changes to `.js` files are handled by Node server([react-scripts](https://github

## Test

### Backend unit tests
```bash
make test
```

### Backend integration tests
1. Build the API Server: `make build`
2. Follow [these instructions](#Run-locally) to target existing OpenShift project (**Note:** the project must not contain existing mobile clients)
3. Install dependencies: `cd integration_tests && npm install`
4. Run the tests: `npm test`


## Generate the API definition for the CRD

If you are changing the type definition of (MobileClient)[./pkg/apis/aerogear/v1alpha1/types.go], you should run the following command to regenerate some of the files.
Expand Down
66 changes: 66 additions & 0 deletions integration_tests/mobile_clients/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const assert = require('assert')
const sendRequest = require('../util/sendRequest')

const template = {
name: "integration-test-client",
appIdentifier: "integration.test",
clientType: "android"
}

describe('initially', () => {
it('should have no mobile clients present', async () => {
const res = await sendRequest('GET', 'mobileclients')
assert.equal(res.status, 200)
assert.equal(res.data.items.length, 0)
});
});

describe('when creating a new client', () => {
let res;
it('should be created without error', async () => {
res = await sendRequest('POST', 'mobileclients', template)
assert.equal(res.status, 200)
});

it('created client should have required metadata', () => {
assert.equal(res.data.metadata.name, template.name)
assert.equal(res.data.spec.name, template.name)
assert.equal(res.data.spec.clientType, template.clientType)
assert.equal(res.data.spec.appIdentifier, template.appIdentifier)
assert.equal(res.data.status.clientId, template.name)
});

});

describe('when listing a client', () => {
let res;
it('should be listed without error', async () => {
res = await sendRequest('GET', 'mobileclients')
assert.equal(res.status, 200)
});

it('listed client should have required metadata', () => {
const listedClientData = res.data.items[0]
assert.equal(listedClientData.metadata.name, template.name)
assert.equal(listedClientData.spec.name, template.name)
assert.equal(listedClientData.spec.clientType, template.clientType)
assert.equal(listedClientData.spec.appIdentifier, template.appIdentifier)
assert.equal(listedClientData.status.clientId, template.name)
});

});

describe('when deleting a client', () => {
let res;
it('should be deleted without error', async () => {
res = await sendRequest('DELETE', `mobileclients/${template.name}`)
assert.equal(res.status, 200)
});

it('deleted client should be no longer present in the list', async () => {
res = await sendRequest('GET', 'mobileclients')
assert.equal(res.status, 200)
assert.equal(res.data.items.length, 0)
});

});
221 changes: 221 additions & 0 deletions integration_tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions integration_tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "mdc-integration-tests",
"description": "Integration tests for MDC",
"version": "0.0.1",
"scripts": {
"test": "mocha ."
},
"devDependencies": {
"axios": "^0.18.0",
"mocha": "^5.2.0"
}
}
30 changes: 30 additions & 0 deletions integration_tests/runner.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const { exec } = require('child_process')

process.env.NAMESPACE = process.env.NAMESPACE || "mdc-integration-testing"
process.env.KUBERNETES_CONFIG = process.env.KUBERNETES_CONFIG || `${process.env.HOME}/.kube/config`

let goOutput

// Spin up backend server on port 4000
before( function(done) {
this.timeout(10000)
goOutput = exec('../mobile-developer-console')
goOutput.stdout.on('data', data => {
console.log(data.toString())
})
goOutput.stderr.on('data', data => {
const message = data.toString()
console.log(message)
if (message.indexOf("Starting application") > -1) {
done()
}
})
});

after(() => {
goOutput.kill("SIGINT")
})

describe('Mobile Clients', () => {
require('./mobile_clients')
});
18 changes: 18 additions & 0 deletions integration_tests/util/sendRequest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const axios = require('axios')

const api = "http://localhost:4000/api"

const sendRequest = async (method, path, data) => {
let headers
if (method === "POST") {
headers = {'Content-Type': 'application/json'}
}
return await axios({
url: `${api}/${path}`,
method,
data,
headers
})
}

module.exports = sendRequest

0 comments on commit 7e28a91

Please sign in to comment.