-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #769 from telefonicaid/task/add-functional-tests-s…
…uite Add new functional tests suite
- Loading branch information
Showing
7 changed files
with
505 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
## Functional test suite | ||
|
||
This directory contains the functional test suite for the project. This relies on the IoT Agent Node Lib Functional test | ||
suite. For further information, visit the | ||
[documentation](https://github.com/telefonicaid/iotagent-node-lib/tree/master/test/functional). | ||
|
||
The `functional-tests-runner.js` script is used to run the functional test suite. It is similar to the one used in the | ||
IoT Agent Node Lib, but it has been adapted to the particularities of the IoT Agent JSON. This script imports both the | ||
IoT Agent Node Lib `testCases.js` and the local `testCases.js` file. The latter contains the test cases that are | ||
specific to the IoT Agent JSON, while the former contains the test cases that are common to all IoT Agents. | ||
|
||
If you plan to include a tests for an specific feature of the IoT Agent JSON, please, consider added it into the IoTA | ||
Node Lib `testCases.js` file and use the skip feature to avoid running it for other agents that do not support it. You | ||
can check the documentation of the IoT Agent Node Lib Functional test suite linked previously for further information. | ||
|
||
Additionally, the `functional-tests.js` file is a simple example of how to implement code bases tests using the IoT | ||
Agent Node Lib Functional test suite utilities. (This test is coded implemented and suites more complex cases than the | ||
ones contained in the `testCases.js` file). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2023 Telefonica Investigación y Desarrollo, S.A.U | ||
* | ||
* This file is part of iotagent-json | ||
* | ||
* iotagent-json is free software: you can redistribute it and/or | ||
* modify it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the License, | ||
* or (at your option) any later version. | ||
* | ||
* iotagent-json is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public | ||
* License along with iotagent-json. | ||
* If not, seehttp://www.gnu.org/licenses/. | ||
* | ||
* For those usages not covered by the GNU Affero General Public License | ||
* please contact with::[contacto@tid.es] | ||
* | ||
* Modified by: Miguel Angel Pedraza | ||
*/ | ||
|
||
/* eslint-disable no-unused-vars */ | ||
|
||
const config = {}; | ||
|
||
config.mqtt = { | ||
host: 'localhost', | ||
port: 1883 | ||
}; | ||
|
||
config.http = { | ||
port: 7896, | ||
host: 'localhost' | ||
}; | ||
|
||
config.amqp = { | ||
port: 5672, | ||
exchange: 'amq.topic', | ||
queue: 'iota_queue', | ||
options: { durable: true } | ||
}; | ||
|
||
config.iota = { | ||
logLevel: 'FATAL', | ||
contextBroker: { | ||
host: '192.168.1.1', | ||
port: '1026', | ||
ngsiVersion: 'v2' | ||
}, | ||
server: { | ||
port: 4041, | ||
host: 'localhost' | ||
}, | ||
deviceRegistry: { | ||
type: 'memory' | ||
}, | ||
types: {}, | ||
service: 'howtoservice', | ||
subservice: '/howto', | ||
providerUrl: 'http://localhost:4041', | ||
deviceRegistrationDuration: 'P1M', | ||
defaultType: 'Thing', | ||
defaultResource: '/iot/json' | ||
}; | ||
|
||
config.defaultKey = '1234'; | ||
config.defaultTransport = 'MQTT'; | ||
|
||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
* Copyright 2023 Telefonica Investigación y Desarrollo, S.A.U | ||
* | ||
* This file is part of iotagent-json | ||
* | ||
* iotagent-json is free software: you can redistribute it and/or | ||
* modify it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the License, | ||
* or (at your option) any later version. | ||
* | ||
* iotagent-json is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public | ||
* License along with iotagent-json. | ||
* If not, seehttp://www.gnu.org/licenses/. | ||
* | ||
* For those usages not covered by the GNU Affero General Public License | ||
* please contact with::[contacto@tid.es] | ||
* | ||
* Modified by: Miguel Angel Pedraza | ||
*/ | ||
|
||
/* eslint-disable no-unused-vars*/ | ||
/* eslint-disable no-unused-expressions*/ | ||
|
||
const iotaJson = require('../../lib/iotagent-json'); | ||
const config = require('./config-test.js'); | ||
const nock = require('nock'); | ||
const chai = require('chai'); | ||
const expect = chai.expect; | ||
const iotAgentLib = require('iotagent-node-lib'); | ||
const async = require('async'); | ||
const utils = require('../utils'); | ||
const testUtils = require('../../node_modules/iotagent-node-lib/test/functional/testUtils.js'); | ||
const request = utils.request; | ||
const logger = require('logops'); | ||
const chaiMatchPattern = require('chai-match-pattern'); | ||
const e = require('express'); | ||
chai.config.truncateThreshold = 0; | ||
|
||
const baseTestCases = require('../../node_modules/iotagent-node-lib/test/functional/testCases.js').testCases; | ||
const jsonTestCases = require('./testCases.js').testCases; | ||
|
||
const env = { | ||
service: 'smartgondor', | ||
servicePath: '/gardens' | ||
}; | ||
|
||
// You can add here your own test cases to be executed in addition to the base ones | ||
// It is useful to test new features or to test specific scenarios. If you are going | ||
// to add a new test case, please, add it to the testCases.js file instead of adding | ||
// it here. | ||
let testCases = []; | ||
|
||
// If you want to execute only the test cases defined above, you can comment | ||
// the following line. Otherwise, the tests defined in testCases.js will be | ||
// executed as well. | ||
testCases = testCases.concat(baseTestCases); | ||
|
||
// Add specific test cases for IoTA JSON | ||
testCases = testCases.concat(jsonTestCases); | ||
|
||
describe('FUNCTIONAL TESTS', function () { | ||
beforeEach(function (done) { | ||
// Check if the test case should be skipped | ||
iotaJson.start(config, function (error) { | ||
done(error); | ||
}); | ||
}); | ||
|
||
afterEach(function (done) { | ||
async.series([iotAgentLib.clearAll, iotaJson.stop], done); | ||
}); | ||
|
||
testCases.forEach((testCase) => { | ||
describe(testCase.describeName, function () { | ||
beforeEach(function (done) { | ||
if (testCase.skip && testUtils.checkSkip(testCase.skip, 'json')) { | ||
this.skip(); | ||
} | ||
if (testCase.loglevel) { | ||
logger.setLevel(testCase.loglevel); | ||
} | ||
request(testCase.provision, function (error, response, body) { | ||
let err = null; | ||
if (response.statusCode !== 201) { | ||
err = new Error('Error creating the device group'); | ||
} | ||
done(err); | ||
}); | ||
}); | ||
|
||
afterEach(function () { | ||
logger.setLevel('FATAL'); | ||
nock.cleanAll(); | ||
}); | ||
|
||
testCase.should.forEach((should) => { | ||
it(should.shouldName, async function () { | ||
if (testCase.skip && testUtils.checkSkip(testCase.skip, 'json')) { | ||
this.skip(); | ||
} | ||
|
||
this.retries(2); // pass the maximum no of retries | ||
if (should.loglevel) { | ||
// You can use this line to set a breakpoint in the test in order to debug it | ||
// You just need to add a loglevel element to the test case with the desired log level | ||
// and then set a breakpoint in the next line. By default, the log level is FATAL and | ||
// the following line will never be executed | ||
logger.setLevel(should.loglevel); | ||
} | ||
|
||
await testUtils.testCase( | ||
should.measure, | ||
should.expectation, | ||
testCase.provision, | ||
env, | ||
config, | ||
should.type ? should.type : 'single', | ||
should.transport ? should.transport : 'HTTP', | ||
should.isRegex ? should.isRegex : false | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.