Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Feature/tests #123

Merged
merged 76 commits into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
4d430f3
Setup the testing framework for fadi.
Oct 21, 2019
a3bd80f
First commit of Fadi tests.
Nov 4, 2019
30a3290
Reorganize the tests repository.
Nov 4, 2019
7c4ff34
Merge branch 'feature/tests' of https://github.com/cetic/fadi.git into
Nov 4, 2019
d2b94f4
A new reorganisation of tests forlder.
Nov 4, 2019
6a3de89
Update package.json and remove unused require.
Nov 4, 2019
b692f18
Add missed configuration files.
Nov 4, 2019
3f8003d
Test upload Nifi template feature.
Dec 16, 2019
fdc9f77
Adding the cockburns and test scripts specification in the repository…
Dec 18, 2019
786eb76
Adding the links to the tes scripts specifications
SellamiRami Dec 18, 2019
6175c2d
Adding the test scripts repository
Dec 18, 2019
90541da
Merge branch 'feature/testsDOC' of https://github.com/cetic/fadi into…
Dec 18, 2019
4433ff5
Adding links to the test scripts in the table
SellamiRami Dec 18, 2019
1f5892a
Update Test-scripts-specifications.md
SellamiRami Dec 18, 2019
8c5f68b
Rename Cockburns-specification to Cockburns-specification.md
SellamiRami Dec 18, 2019
9a7efa4
Update Cockburns-specification.md
SellamiRami Dec 18, 2019
696a413
Update Cockburns-specification.md
SellamiRami Dec 18, 2019
b6f5313
Adding the cockburn repository
Dec 18, 2019
60ef775
Update TC-18.md
SellamiRami Dec 18, 2019
443229d
Update TC-19.md
SellamiRami Dec 18, 2019
eb727f1
Update TC-20.md
SellamiRami Dec 18, 2019
a340d01
Update TC-21.md
SellamiRami Dec 18, 2019
d161996
Update TC-21.md
SellamiRami Dec 18, 2019
d0260ae
Adding a README file for the doc repository
SellamiRami Dec 18, 2019
2ca931b
Delete README.md
SellamiRami Dec 18, 2019
969e1bc
Adding a README file for the tests repository
SellamiRami Dec 18, 2019
ae72716
Adding a template to create a new test case
SellamiRami Dec 18, 2019
4d1509c
Adding a template to create a new test script
SellamiRami Dec 18, 2019
b79b03c
Defining a README for the test repository
SellamiRami Dec 18, 2019
310553a
Update README.md
SellamiRami Dec 18, 2019
914b0ea
Update README.md
SellamiRami Dec 18, 2019
c8f6616
check selector before drag and drop
Dec 24, 2019
73cd732
test the instantiation of a Nifi template
Dec 24, 2019
a7b979a
fix some typos and add reference.
fzalila Jan 2, 2020
c295d40
Fix URLs.
fzalila Jan 7, 2020
64deab5
Add test sequencer to order the tests.
Jan 13, 2020
32a1573
Order the different tests by name.
Jan 13, 2020
ffe96f8
Add reference to the test.
fzalila Jan 13, 2020
8869fd0
Add reference to the test.
fzalila Jan 13, 2020
4169f75
Refer to the test.
fzalila Jan 14, 2020
add3dc2
Refer to the test.
fzalila Jan 14, 2020
649eace
Refer to the different elements of the test.
fzalila Jan 14, 2020
b0b3dbc
Replace Pgadmin with Adminer service.
Feb 20, 2020
53154cc
Update the tests of Apache Nifi.
Feb 20, 2020
3259b0c
Add tests of Grafana service.
Feb 20, 2020
d2b9c04
Update configuration.
Feb 20, 2020
239216a
Merge pull request #104 from cetic/feature/testsDOC
fzalila Feb 20, 2020
ee13c21
Fix #106.
Feb 24, 2020
e5cdc3c
Fix #106.
Feb 25, 2020
380152c
Update configuration file.
Feb 25, 2020
ebdc756
Add a documentation to the tests feature.
Feb 25, 2020
c291ab2
Update the documentation.
Feb 25, 2020
d2b241e
Make urls generic.
Mar 30, 2020
4586b93
Add a testing example.
Mar 30, 2020
8d36305
Update Test-scripts-specifications.md
SellamiRami Jun 2, 2020
a300338
Fixing a typos in the links
SellamiRami Jun 2, 2020
7fad84b
Removing the pgAdmin + fixing an absolute link
SellamiRami Jun 2, 2020
e855ed9
Adding cockburns for Adminer
SellamiRami Jun 2, 2020
3d00303
Update Cockburns-specification.md
SellamiRami Jun 2, 2020
2d8082a
Update Cockburns-specification.md
SellamiRami Jun 2, 2020
32904fd
Defining the cockborn Creating a table in Adminer
SellamiRami Jun 2, 2020
376fb07
Adding the specification of Adminer test script
SellamiRami Jun 2, 2020
88c40a4
Specifying the test script for the Adminer
SellamiRami Jun 2, 2020
da29e43
Updating the content of the column Test script ID
SellamiRami Jun 2, 2020
7320b1f
Removing a link in TC-4
SellamiRami Jun 2, 2020
23d2d06
Removing a wrong link in TC-4
SellamiRami Jun 2, 2020
e190455
Replacing pgAdmin by Adminer
SellamiRami Jun 2, 2020
aa791ec
Merge branch 'develop' into feature/tests
Jun 3, 2020
0f3df92
* Formatting, typos, TOC's, cleanup, ...
Jun 3, 2020
ea4eaf0
ignore .vscode
Jun 3, 2020
4e54882
Fix small issues.
Jun 15, 2020
a99ed26
Update test docker image.
Jun 16, 2020
cfb01b4
add issues references, removed `ls` command from CI script
Jun 22, 2020
4cfc7ac
Documentation update
Jun 22, 2020
a7f8285
Documentation cleanup
Jun 22, 2020
3a00ed5
Fix anchor
Jun 22, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@ teardown.log
*.tgz

# https://github.com/ekalinin/github-markdown-toc
gh-md-toc
gh-md-toc

.vscode
12 changes: 12 additions & 0 deletions .gitlab-ci.sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ stages:
- tf_plan
- tf_apply
- deployWithHelm
- test

variables:
KUBECONFIG: /etc/deploy/config
Expand Down Expand Up @@ -132,3 +133,14 @@ deployWithHelm:
url: http://$PROJECT
only:
- master

test:
stage: test
image: ceticasbl/puppeteer-jest
script:
- cd tests/
- npm run test
tags:
- docker
only:
- develop
1 change: 1 addition & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ FADI Documentation
* [Users management](USERMANAGEMENT.md) - user identification and authorization (LDAP, RBAC, ...)
* [Reverse proxy](REVERSEPROXY.md) - Traefik reverse proxy configuration
* [Security](SECURITY.md) - SSL setup
* [Testing](/tests/README.md) - tests for the FADI framework
* [TSimulus](TSIMULUS.md) - how to simulate sensors and generate realistic data with [TSimulus](https://github.com/cetic/TSimulus)
* [Sample self-hosted infrastructure](RANCHER_PROXMOX.md) - How to install FADI on a self hosted infrastructure using
* [Proxmox](https://www.proxmox.com/en/) as a self-hosted private cloud (IaaS) provider. It provides virtual machines for the various Kubernetes nodes.
Expand Down
9 changes: 9 additions & 0 deletions tests/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"semi": false,
"singleQuote": true,
"useTabs": true,
"tabWidth": 2,
"bracketSpacing": true,
"arrowParens": "avoid",
"trailingComma": "es5"
}
106 changes: 106 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Testing the FADI framework

<img src="https://miro.medium.com/max/1788/1*wby6AkTf3SggijT3GSTu4w.png" height="100" align="right" alt="Jest Puppeteer">

[![implemented with puppeteer](https://img.shields.io/badge/implemented%20with-puppeteer-%2300D8A2)](https://pptr.dev) [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest)

* [Introduction](#introduction)
* [Quick start](#quick-start)
* [Example](#examples)
* [Documentation](#documentation)
* [References](#references)

## Introduction

The FADI framework is tested using Puppeteer and Jest.

[Puppeteer](https://pptr.dev) is a Node library which provides a high-level API to control Chrome or Chromium over the DevTools Protocol. Puppeteer runs headless by default, but can be configured to run full (non-headless) Chrome or Chromium.

[Jest](https://jestjs.io) is a JavaScript Testing Framework with a focus on simplicity. It works with projects using: Babel, TypeScript, Node, React, Angular, Vue and more!

## Quick start

To test the FADI framework, you need to implement the following instructions:

1. Install FADI framework. Refer to [the INSTALL section](../INSTALL.md).
2. Create a Docker container using [the Puppeteer-Jest Docker image](https://hub.docker.com/repository/docker/fzalila/docker-puppeteer-jest). To achieve that, run the following command:

```bash
docker container run --name testing-fadi fzalila/docker-puppeteer-jest:latest
```

3. Inside the created container, clone the FADI repository:

```bash
git clone https://github.com/cetic/fadi.git
```

4. Configure [here](./lib/config.js) the urls and paths of different FADI platform services

5. Go to the `tests` folder and launch the tests:

```bash
cd fadi/tests
npm run test
```

If tests pass, you should obtain the following results:

<img src="doc/images/test_results.png" height="500" alt="Tests results" />

## Examples

The following example checks the creation of a `example_basic` table in the `postgres` database.

```js
it('should create a table', async () => {
// Go to the indicated page
await page.goto(url)

// Click on SQL query button
await click(page, '.ltr > #menu > .links > a:nth-child(1)')

// type the query
await typeText(page, 'CREATE TABLE example_basic (measure_ts TIMESTAMP NOT NULL,temperature FLOAT (50));', '.ltr > #content > #form > p > .jush')

// Execute the table creation query
await click(page, '.ltr > #content > #form > p > input:nth-child(1)')

// Check the creation of the table
await shouldExist(page, '#content > p.message')
})
```

More examples are available in the [test-scripts folder](doc/test-scripts/).

## Documentation

Test cases of the FADI framework are specified using Cockburns[[1](#references)] templates, available [here](doc/Cockburns-specification.md).

Test scripts specifications are available [here](doc/Test-scripts-specifications.md).

Two templates are available in order to define a new [test case](doc/cockburns/TC-template.md) and a new [test script](doc/test-scripts/TS-template.md).

## Continuous integration

To automate testing inside a continuous integration process, you can for example add a `test` stage to a Gitlab-CI pipeline by editing the [`.gitlab-ci.yml`](../.gitlab-ci.sample.yml) configuration:

```yaml
stages:
- deployWithHelm
- test

deployWithHelm:
[...]

test:
stage: test
image: ceticasbl/puppeteer-jest
script:
- cd tests/
- npm run test
```

## References

[1] Alistair Cockburn. 2000. Writing Effective Use Cases (1st. ed.). Addison-Wesley Longman Publishing Co., Inc., USA.
9 changes: 9 additions & 0 deletions tests/TestSequencer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const TestSequencer = require('@jest/test-sequencer').default;

class CustomSequencer extends TestSequencer {
sort(tests) {
const copyTests = Array.from(tests);
return copyTests.sort((testA, testB) => (testA.path > testB.path ? 1 : -1));
}}

module.exports = CustomSequencer;
96 changes: 96 additions & 0 deletions tests/__tests__/1-adminer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
const puppeteer = require('puppeteer')
const jestpkg = require('jest')
const config = require('../lib/config')
const click = require('../lib/helpers').click
const typeText = require('../lib/helpers').typeText
const loadUrl = require('../lib/helpers').loadUrl
const waitForText = require('../lib/helpers').waitForText
const pressKey = require('../lib/helpers').pressKey
const shouldExist = require('../lib/helpers').shouldExist
const shouldNotExist = require('../lib/helpers').shouldNotExist
const dragAndDrop = require('../lib/helpers').dragAndDrop
const Sequencer = require('@jest/test-sequencer').default

const url = config.AdminerUrl
//const utils = require('../lib/utils')

describe('Test the authentification to the Adminer service', () => {
/** @type {puppeteer.Browser} */
let browser

/** @type {puppeteer.Page} */
let page

beforeAll(async function () {
browser = await puppeteer.launch({
headless: config.isHeadless,
slowMo: config.slowMo,
devtools: config.isDevtools,
timeout: config.launchTimeout,
args: ['--no-sandbox']
})
page = await browser.newPage()
await page.setDefaultNavigationTimeout(config.waitingTimeout) //10 seconds is the industry standard
await page.setViewport({
width: config.viewportWidth,
height: config.viewportHeight
})
})
afterAll(async function () {
await browser.close()
})
it('should success the authentification process', async () => {
// Go to the indicated page
await page.goto(url)

// Click on the DBMS list
await click(page, '.layout > tbody > tr > td > select')

// Select the postgresql DBMS
await page.select('.layout > tbody > tr > td > select', 'pgsql')

// Empty the server value content (usually 'db')
await page.evaluate(() => document.querySelector(".layout > tbody > tr:nth-child(2) > td > input").value = "")

// Insert the server name fadi-postgresql
await typeText(page, 'fadi-postgresql', ".layout > tbody > tr:nth-child(2) > td > input")

// Insert the user
await typeText(page, 'admin', '.layout #username')

// Insert password
await typeText(page, 'password1', '.layout > tbody > tr:nth-child(4) > td > input')

// insert the db name
await typeText(page, 'postgres', '.layout > tbody > tr:nth-child(5) > td > input')

// Click on the authentification
await click(page, '.ltr > #content > form > p > input')

await page.waitFor(6000)

// Check access to the authentification page
const selector = await page.$('#content > h2')
const text = await page.evaluate(selector => selector.textContent, selector);
const result = text.includes('public')
//console.log(text.includes('public'))
expect(result).toBe(true)
})

it('should create a table', async () => {
// Go to the indicated page
//await page.goto(url)

// Click on SQL query button
await click(page, '.ltr > #menu > .links > a:nth-child(1)')

// type the query
await typeText(page, 'CREATE TABLE example_basic (measure_ts TIMESTAMP NOT NULL,temperature FLOAT (50));', '.ltr > #content > #form > p > .jush')

// Execute the table creation query
await click(page, '.ltr > #content > #form > p > input:nth-child(1)')

// Check the creation of the table
await shouldExist(page, '#content > p.message')
})
})
Loading