Skip to content

Commit

Permalink
Automatic test (#1)
Browse files Browse the repository at this point in the history
* Automatic test

* Complete test

* npm update
  • Loading branch information
Alkarex authored Oct 11, 2023
1 parent bc5b6f8 commit d24c8dc
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
node-version: [18.x, 20.x]
node-version: [16.x, 20.x]

steps:
- uses: actions/checkout@v4
Expand Down
22 changes: 22 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';
/**
* Command-line interface for Node-RED nodes.
*
* Script to run our Node-RED nodes from terminal without Node-RED and using STDIN / STDOUT.
*
* @author Alexandre Alapetite <https://github.com/Alkarex>
* @copyright Alexandra Institute <https://alexandra.dk> for the SynchroniCity European project <https://synchronicity-iot.eu>
* as a contribution to FIWARE <https://www.fiware.org>
* @license MIT
* @date 2019-11-28 / 2022-02-02
*/

// Load fake/mocked Node-RED
const RED = require('node-red-contrib-mock-cli');
const noderedNode = RED.load(require.main);

if (noderedNode) {
RED.run();
} else {
console.error('Error loading Node-RED node!');
}
18 changes: 14 additions & 4 deletions package-lock.json

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

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,15 @@
"eslint-plugin-html": "^7.1.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-n": "^16.1.0",
"eslint-plugin-promise": "^6.1.1"
"eslint-plugin-promise": "^6.1.1",
"node-red-contrib-mock-cli": "^1.3.0"
},
"scripts": {
"start": "node ./index.js",
"eslint": "eslint --ext .js,.html .",
"eslint_fix": "eslint --fix --ext .js,.html .",
"fix": "npm run eslint_fix",
"test": "npm run eslint"
"pretest": "npm run-script eslint",
"test": "./test.sh"
}
}
45 changes: 45 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/sh

test=$(
cat <<'EOF' | node ./index.js http-basic-auth --realm='"node-red"' --username='"test"' --password='"$2y$10$5TSZDldoJ7MxDZdtK/SG2O3cwORqLDhHabYlKX9OsM.W/Z/oLwKW6"'
{"req":{"headers":{"authorization":"Basic dGVzdDp0ZXN0"}}}
EOF
)

if [ "$test" = "" ]; then
echo 'ERROR 1'
exit 1
fi

test=$(
cat <<'EOF' | node ./index.js http-basic-auth --realm='"node-red"' --username='"test"' --password='"test"'
{"req":{"headers":{"authorization":"Basic dGVzdDp0ZXN0"}}}
EOF
)

if [ "$test" = "" ]; then
echo 'ERROR 2'
exit 1
fi

test=$(
cat <<'EOF' | node ./index.js http-basic-auth --realm='"node-red"' --username='"wrong"' --password='"$2y$10$5TSZDldoJ7MxDZdtK/SG2O3cwORqLDhHabYlKX9OsM.W/Z/oLwKW6"'
{"req":{"headers":{"authorization":"Basic dGVzdDp0ZXN0"}}}
EOF
)

if [ "$test" != "" ]; then
echo 'ERROR 3'
exit 1
fi

test=$(
cat <<'EOF' | node ./index.js http-basic-auth --realm='"node-red"' --username='"test"' --password='"wrong"'
{"req":{"headers":{"authorization":"Basic dGVzdDp0ZXN0"}}}
EOF
)

if [ "$test" != "" ]; then
echo 'ERROR 4'
exit 1
fi

0 comments on commit d24c8dc

Please sign in to comment.