-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new functional tests suite #769
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
50b4ee9
Add initial files and changes
mapedraza 0a8d8c2
Remove leftovers + suggestions
mapedraza ce2e261
Make assertions more verbose
mapedraza fcbdd43
Fix lint
mapedraza 9fdb31c
Fix lint 2
mapedraza 6727014
Wrap measure promise + err messages
mapedraza e5d10cf
Add automated tests suite + doc
mapedraza c245d8b
Fix doc
mapedraza 0a5b7ed
fix lint
mapedraza 650c7be
fix deps
mapedraza 39f5bfc
rename file
mapedraza d415b7f
Use node-lib cases + utils
mapedraza a8b531e
Add header
mapedraza f9b53e9
Add readme file
mapedraza 9ef8e9c
Update package.json
fgalan f4ab126
ADD link to new README.md from root README.md
fgalan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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::[[email protected]] | ||
* | ||
* 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::[[email protected]] | ||
* | ||
* 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A GitAction for this test should be included.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No real needed since they are executed as part of normal tests
'test/**/*.js'
. In other words, functional tests are executed as part of normal tests (npm test
).Unless we want to add a new section under CI tests, it is not required
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, why don't just keep
test
target and removetest:functional
?Not sure if having overlapping targets is a good idea...