rewritte of test

This commit is contained in:
Tomas Juhasz 2025-01-08 12:49:33 +01:00
commit 6e021788e1
36 changed files with 382 additions and 687 deletions

View file

@ -1,7 +0,0 @@
summary: Runs internal expressjs tests.
description: |
Test to verify Expresss compatibility with the Node.js.
duration: 5m
require:
- nodejs
- git

View file

@ -0,0 +1,14 @@
summary: FS module test
test: ./runtest.sh
framework: beakerlib
description: |
Test ensures that nodejs can read and write files
duration: 5m
require:
- nodejs
- type: file
pattern:
- /script.js
tier: integration
component:
- nodejs

View file

@ -0,0 +1,22 @@
#!/bin/bash
. /usr/share/beakerlib/beakerlib.sh || exit 1
rlJournalStart
rlPhaseStartSetup
rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory"
rlRun "mv script.js $tmp"
rlRun "pushd $tmp"
rlRun "set -o pipefail"
rlPhaseEnd
rlPhaseStartTest
rlShowPackageVersion nodejs
rlRun "node script.js > out.log" 0 "Running a script"
rlAssertGrep "All tests passed!" out.log
rlPhaseEnd
rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -r $tmp" 0 "Remove tmp directory"
rlPhaseEnd
rlJournalEnd

View file

@ -0,0 +1,41 @@
const fs = require('fs');
const path = require('path');
// Test file path
const testFile = path.join(__dirname, 'test-file.txt');
try {
// Step 1: Write to a file
console.log('Writing to file...');
const data = 'Hello, TMT fs test!';
fs.writeFileSync(testFile, data);
if (fs.existsSync(testFile)) {
console.log('✔ File created successfully.');
} else {
throw new Error('✘ Failed to create file.');
}
// Step 2: Read from the file
console.log('Reading from file...');
const fileContent = fs.readFileSync(testFile, 'utf8');
if (fileContent === data) {
console.log('✔ File content matches expected.');
} else {
throw new Error('✘ File content mismatch.');
}
// Step 3: Delete the file
console.log('Deleting file...');
fs.unlinkSync(testFile);
if (!fs.existsSync(testFile)) {
console.log('✔ File deleted successfully.');
} else {
throw new Error('✘ Failed to delete file.');
}
console.log('All tests passed!');
process.exit(0); // Success exit code
} catch (error) {
console.error(error.message);
process.exit(1); // Failure exit code
}

View file

@ -0,0 +1,12 @@
summary: User of different priviliges can use global modules
test: ./runtest.sh
framework: beakerlib
description: |
Test ensures that users of various priviliges can access global module.
duration: 5m
recommend:
require:
tier: '1'
component:
- npm
- nodejs

View file

@ -0,0 +1,120 @@
#!/bin/bash
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2013 Red Hat, Inc. All rights reserved.
#
# This copyrighted material is made available to anyone wishing
# to use, modify, copy, or redistribute it subject to the terms
# and conditions of the GNU General Public License version 2.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/share/beakerlib/beakerlib.sh || exit 1
function check_and_cleanup()
{
rlAssertExists "./node_modules/optimist/package.json"
rlRun "[[ -e './node_modules/optimist/node_modules/wordwrap/package.json' ]] || [[ -e './node_modules/wordwrap/package.json' ]]" 0 "File wordwrap/package.json should exist."
# Skip directory cleanup if the first parameter is empty
[[ -z "$1" ]] && rlRun "rm -rf ./node_modules && ! ls ./node_modules" 0 "Cleaning up local modules"
rlRun "$NPMJS cache clean --force" 0 "Cleaning up npm cache"
}
function create_user()
{
local username=$1
local role=$2
rlLog "Creating user '$username' with role '$role'"
rlRun "useradd -g "$role" "$username""
}
function verify_user_access()
{
local username=$1
rlLog "Verifying npm access for user '$username'"
rlRun "su "$username" -c 'coffee -h'"
}
function delete_user()
{
local username=$1
rlLog "Deleting user '$username'"
rlRun "userdel -r "$username""
}
# Packages to be tested
PACKAGES=${PACKAGES:-nodejs}
# Other required packages
REQUIRES=${REQUIRES:-}
# Node binary name parametrized
NODEJS=${NODEJS:-node}
# NPM binary name parametrized
NPMJS=${NPMJS:-npm}
# Parameters to check using "npm parameter" and what to look for in their output
rlJournalStart
rlPhaseStartSetup
rlAssertRpm --all
rlAssertBinaryOrigin $NODEJS
rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
rlRun "pushd $TmpDir"
#Create user
#Install package globbaly
rlLog "Installing globally from web repository:"
rlRun "$NPMJS install coffeescript --global " 0 "Installing \"coffeescript\" globally"
rlRun "which coffee" 0 "Executable \"coffeescript\" should be in binary path"
rlRun "$NPMJS cache clean --force" 0 "Cleaning up npm cache"
rlRun "coffee -h"
#Creating various users
rlLog "Creating users:"
create_user test_admin wheel
create_user test_editor users
create_user test_viewer adm
rlPhaseEnd
rlPhaseStartTest "Install"
rlLog "Verifying user access to global npm module:"
verify_user_access test_admin
verify_user_access test_editor
verify_user_access test_viewer
rlPhaseEnd
rlPhaseStartTest "Remove"
rlLog "Removing global package:"
rlRun "$NPMJS remove coffeescript --global" 0 "Removing global \"coffeescript\""
rlAssertNotExists "${npm_global_path}/coffeescript/package.json"
rlLog "Deleting test users:"
delete_user test_admin
delete_user test_editor
delete_user test_viewer
rlPhaseEnd
rlPhaseStartCleanup
rlRun "rm /root/.npmrc" 0,1
rlRun "rm /root/.npm" 0,1
rlRun "popd"
rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
rlPhaseEnd
rlJournalPrintText
rlJournalEnd

View file

@ -18,6 +18,28 @@ or if you want all tools (virtual and container):
```bash
sudo dnf install -y tmt+all
```
## If not provided create koji build and set env variable
you can use the following allias to create build and set env automatically:
```bash
alias scratchbuild='function _scratchbuild() { \
SRC_RPM=$(ls *.src.rpm | head -n 1); \
if [ -z "$SRC_RPM" ]; then \
echo "No source RPM file found in the current directory."; \
return 1; \
fi; \
BUILD_OUTPUT=$(koji build --scratch rawhide $SRC_RPM 2>&1); \
KOJI_TASK_ID=$(echo "$BUILD_OUTPUT" | grep -oP "(?<=Task ID: )[0-9]+"); \
if [[ -n $KOJI_TASK_ID ]]; then \
export KOJI_TASK_ID=$KOJI_TASK_ID; \
echo "Scratch build completed. Task ID: $KOJI_TASK_ID"; \
else \
echo "Failed to extract Task ID."; \
return 1; \
fi; \
}; _scratchbuild'
```
check what test plans and sub plans are available:
```bash
tmt plans

View file

@ -1,10 +0,0 @@
summary: extension fs is installed without error
test: ./runtest.sh
framework: beakerlib
description: |
Test ensures that extension fs is installed without errors.
duration: 5m
recommend: nodejs
require:
- nodejs
tier: '1'

View file

@ -1,62 +0,0 @@
#!/bin/bash
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2020 Red Hat, Inc.
#
# This copyrighted material is made available to anyone wishing
# to use, modify, copy, or redistribute it subject to the terms
# and conditions of the GNU General Public License version 2.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/share/beakerlib/beakerlib.sh || exit 1
# Packages to be tested
PACKAGES=${PACKAGES:-nodejs nodejs-npm}
# Other required packages
REQUIRES=${REQUIRES:-git}
rlJournalStart
rlPhaseStartSetup
rlAssertRpm --all
rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
rlRun "pushd $TmpDir"
rlPhaseEnd
rlPhaseStartTest "Testsuite"
rlRun "git clone https://github.com/expressjs/express.git" 0 "Clone the upstream repo with the Express framework"
rlRun "pushd express" 0 "Change directory to the express repo directory"
rlRun "latest_express=$(npm show express version)" 0 "Figuring out what the latest express version is"
rlRun "npm install mocha"
rlLog "Latest Express version: ${latest_express}"
rlRun "git stash" 0 "Stashing eventual changes so they don't prevent checkout"
rlRun "git checkout '${latest_express}'" 0 "Checkout git's tag ${latest_express}"
rlRun -s "npm test" 0 "Running the test-suite"
rlAssertGrep "[0-9]* passing" "$rlRun_LOG" -E
rlAssertNotGrep "[0-9]* failing" "$rlRun_LOG" -E
rlAssertNotGrep "Test failed" "$rlRun_LOG"
rlRun "popd" 0 "Get back to the original directory"
rlPhaseEnd
rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
rlPhaseEnd
rlJournalPrintText
rlJournalEnd

View file

@ -1,7 +0,0 @@
summary: Basic server running.
description: |
Test ensures that nodejs can import http module and run basic http server.
duration: 5m
require:
- nodejs
component: nodejs

View file

@ -1,97 +0,0 @@
#!/bin/bash
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2013 Red Hat, Inc. All rights reserved.
#
# This copyrighted material is made available to anyone wishing
# to use, modify, copy, or redistribute it subject to the terms
# and conditions of the GNU General Public License version 2.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/share/beakerlib/beakerlib.sh || exit 1
# Packages to be tested
PACKAGES=${PACKAGES:-nodejs}
# Other required packages
REQUIRES=${REQUIRES:-curl}
# Binary name parametrized
NODEJS=${NODEJS:-node}
# Port range for server to choose from
MIN_SERVER_PORT=${MIN_SERVER_PORT:-8000}
MAX_SERVER_PORT=${MAX_SERVER_PORT:-8080}
# Actual server port to use
SERVER_PORT=${SERVER_PORT:-8008}
# Time delay for server to start and for curl to download
SLEEP_TIME=${SLEEP_TIME:-10}
rlJournalStart
rlPhaseStartSetup
rlAssertRpm --all
rlAssertBinaryOrigin $NODEJS
port_chosen=false
rlLogInfo "Choosing server port..."
for port in $(seq ${MIN_SERVER_PORT} 1 ${MAX_SERVER_PORT}); do
if ! fuser ${port}/tcp >/dev/null 2>&1; then
SERVER_PORT=${port}
port_chosen=true
rlLogInfo "\"${SERVER_PORT}\" chosen"
break
fi
done
$port_chosen || rlLogWarning "No port available from a given range \"${MIN_SERVER_PORT}\" - \"${MAX_SERVER_PORT}\". Using \"${SERVER_PORT}\" anyway."
rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
rlRun "cp server.js $TmpDir/." 0 "Copying server source file"
rlRun "pushd $TmpDir"
rlPhaseEnd
rlPhaseStartTest
echo "---node-processes--"
ps -e | grep node
echo "---"
rlRun "${NODEJS} server.js ${SERVER_PORT} 2>&1 > server_out &" 0 "Running server and logging output"
rlRun "sleep ${SLEEP_TIME}" 0 "Giving server \"${SLEEP_TIME}\" seconds to start"
rlRun "curl --max-time ${SLEEP_TIME} http://127.0.0.1:${SERVER_PORT} > curl_out && cat curl_out" 0 "Querying server"
rlRun "grep 'Hello World' curl_out" 0 "Response should contain \"Hello World\""
rlRun "kill $!" 0 "Stopping the server"
sleep 1
rlRun "ps -e | grep $!" 1 "Server should not be running"
echo "---server-output--"
cat server_out
echo "---"
rlRun "grep 'Request received.' server_out" 0 "Output should contain \"Request received.\""
rlRun "grep 'Server has started.' server_out" 0 "Output should contain \"Server has started.\""
rlRun "kill -SIGKILL $!" 0,1 "Attempt killing possibly leftover server process"
echo "---node-processes-and-directory-contents--"
ps -e | grep node
ls -lah
echo "---"
rlPhaseEnd
rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
rlPhaseEnd
rlJournalPrintText
rlJournalEnd

View file

@ -1,18 +0,0 @@
// server.js -- minimal node.js http server
// Usage: node server.js [PORT]
// Default port is 8000
var http = require("http");
var port = process.argv[2] || 8000;
function onRequest(request, response) {
console.log("Request received.");
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World\n");
response.end();
}
http.createServer(onRequest).listen(port);
console.log("Server has started.");

View file

@ -1,10 +0,0 @@
summary: extension fs is installed without error
test: ./runtest.sh
framework: beakerlib
description: |
Test ensures that extension fs is installed without errors.
duration: 5m
recommend: nodejs
require:
- nodejs
tier: '1'

View file

@ -1,50 +0,0 @@
#!/bin/bash
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Description: Basic sanity test for express module.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2020 Red Hat, Inc.
#
# This copyrighted material is made available to anyone wishing
# to use, modify, copy, or redistribute it subject to the terms
# and conditions of the GNU General Public License version 2.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
. /usr/share/beakerlib/beakerlib.sh || exit 1
NPMJS=${NPMJS:-npm}
rlJournalStart
rlPhaseStartSetup
rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory"
rlRun "pushd $tmp"
rlPhaseEnd
#Test an installation and usage of expo
rlPhaseStartTest
rlRun "$NPMJS install -g expo" 0
rlRun "$NPMJS list -g expo" 0
rlRun "npx create-expo-app my-app -y" 0
rlRun "cd my-app && npx expo start --port 19000 &" 0 "starting server"
rlRun "sleep 10" 0
rlRun "curl http://localhost:19000" 0
rlPhaseEnd
rlPhaseStartCleanup
rlLogInfo "Deleting files created by npm install"
rlRun "popd"
rlRun "rm -r $tmp" 0 "Remove tmp directory"
rlPhaseEnd
rlJournalEnd

View file

@ -1,4 +0,0 @@
summary: Basic nodejs smoke test using beakerlib framework.
component: nodejs
require:
- nodejs

View file

@ -1,44 +0,0 @@
#!/bin/bash
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Description: Basic smoke tests for nodejs.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2020 Red Hat, Inc.
#
# This copyrighted material is made available to anyone wishing
# to use, modify, copy, or redistribute it subject to the terms
# and conditions of the GNU General Public License version 2.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
. /usr/share/beakerlib/beakerlib.sh || exit 1
rlJournalStart
rlPhaseStartSetup
rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory"
rlRun "pushd $tmp"
rlRun "set -o pipefail"
rlPhaseEnd
rlPhaseStartTest
rlRun "node -v" 0 "Check Node Version"
rlPhaseEnd
rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -r $tmp" 0 "Remove tmp directory"
rlPhaseEnd
rlJournalEnd

View file

@ -1,11 +0,0 @@
summary: extension fs is installed without error
test: ./runtest.sh
framework: beakerlib
description: |
Test ensures that extension fs is installed without errors.
duration: 5m
recommend: nodejs
require:
- nodejs
- gcc
tier: '1'

View file

@ -1,56 +0,0 @@
#!/bin/bash
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Description: Basic sanity test for npm install.
#
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2020 Red Hat, Inc.
#
# This copyrighted material is made available to anyone wishing
# to use, modify, copy, or redistribute it subject to the terms
# and conditions of the GNU General Public License version 2.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
. /usr/share/beakerlib/beakerlib.sh || exit 1
TEST_USER="nodeuser"
rlJournalStart
rlPhaseStartSetup
rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory"
rlRun "pushd $tmp"
rlRun "set -o pipefail"
id $TEST_USER && rlRun "userdel -r $TEST_USER"
rlRun "useradd $TEST_USER" 0 "Adding user '$TEST_USER' to the system"
rlRun "chown -R $TEST_USER:$TEST_USER $tmp" 0 "$TEST_USER can (un)install npm in $tmp"
rlPhaseEnd
rlPhaseStartTest
rlRun "su -c 'npm install fs' $TEST_USER" 0 "Try to install fs with npm under $TEST_USER"
rlPhaseEnd
rlPhaseStartCleanup
rlLogInfo "Deleting files created by npm install"
su -c 'set -o pipefail; npm config get cache | xargs rm -rf' $TEST_USER || \
su -c 'set -o pipefail; npm config list | grep "cache" | awk -F "=" '"'"'{print $2}'"'"' | xargs rm -rf' $TEST_USER
rlRun "userdel -r $TEST_USER"
rlRun "popd"
rlRun "rm -r $tmp" 0 "Remove tmp directory"
rlPhaseEnd
rlJournalEnd

View file

@ -1,13 +0,0 @@
summary: extension fs is installed without error
test: ./runtest.sh
framework: beakerlib
description: |
Test ensures that extension fs is installed without errors.
duration: 5m
recommend:
- nodejs
- nodejs-npm
require:
- nodejs
- nodejs-npm
tier: '1'

View file

@ -1,11 +0,0 @@
summary: extension fs is installed without error
test: ./runtest.sh
framework: beakerlib
description: |
Test ensures that extension fs is installed without errors.
duration: 5m
recommend: nodejs
require:
- nodejs
- rpm-build
tier: '1'

View file

@ -1,72 +0,0 @@
#!/bin/bash
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2024 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE=${PACKAGE:-"npm"}
REQUIRES=${REQUIRES:-"rpm-build"}
rlJournalStart
rlPhaseStartSetup
rlAssertRpm --all
rlRun "pushd /root"
#Currently running locally against newest version
rlRun "rlFetchSrcForInstalled nodejs"
rlRun "rpm -ivh ~/nodejs*.src.rpm"
rlRun "dnf -y builddep ~/rpmbuild/SPECS/nodejs22.spec"
rlRun "rpmbuild -bp ~/rpmbuild/SPECS/nodejs22.spec"
## Installing npm modules needed to test itself
rlRun "mkdir modules"
rlRun "cd modules"
rlRun "npm config set registry https://registry.npmjs.org/"
rlRun "npm install tap"
rlRun "npm install mock-globals"
rlRun "npm install npm-registry-mock"
rlRun "cp -r ~/modules/* ~/rpmbuild/BUILD/nodejs22-22.11.0-build/node-v22.11.0/deps/npm/test"
rlRun "cd ~/rpmbuild/BUILD/nodejs22-22.11.0-build/node-v22.11.0/deps/npm/test"
rlPhaseEnd
rlPhaseStartTest
rlRun "node index.js &> log.out" 0,1 "Run npm unit tests"
echo "== log.out ==========="
cat log.out
echo "==/log.out ==========="
if [ `node -e "console.log(process.version.split('.')[0].split('v')[1])"` == 16 ]; then
rlAssertGrep "{ total: 5, pass: 5 }" log.out
else
rlAssertGrep "total: 3, pass: 2, fail: 1 " log.out
fi
rlPhaseEnd
rlPhaseStartCleanup
rlRun "cd ~"
rlRun "rm -rf rpmbuild"
rlRun "rm -rf nodejs*.src.rpm"
rlRun "rm -rf modules"
rlRun "popd"
rlPhaseEnd
rlJournalPrintText
rlJournalEnd

View file

@ -1,4 +0,0 @@
summary: Run basic js script
recommend:
nodejs
tier: smoke

View file

@ -1,54 +0,0 @@
#!/bin/bash
. /usr/share/beakerlib/beakerlib.sh || exit 1
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Description: Basic sanity test for running a JavaScript.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2020 Red Hat, Inc.
#
# This copyrighted material is made available to anyone wishing
# to use, modify, copy, or redistribute it subject to the terms
# and conditions of the GNU General Public License version 2.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TEST_USER="nodeuser"
JS_FILE="$tmp/test-script.js"
rlJournalStart
rlPhaseStartSetup
rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory"
rlRun "pushd $tmp"
rlRun "set -o pipefail"
id $TEST_USER && rlRun "userdel -r $TEST_USER"
rlRun "useradd $TEST_USER" 0 "Adding user '$TEST_USER' to the system"
rlRun "chown -R $TEST_USER:$TEST_USER $tmp" 0 "$TEST_USER can (un)install modules in $tmp"
rlPhaseEnd
rlPhaseStartTest
rlRun "node -v" 0 "Check Node Version"
# Create the JavaScript file
rlRun "echo 'console.log(\"Hello from BeakerLib!\");' > $JS_FILE" 0 "Create JavaScript file"
rlRun "node $JS_FILE > out.log" 0 "Run basic script and output into log file"
rlAssertGrep "Hello from BeakerLib!" out.log
rlPhaseEnd
rlPhaseStartCleanup
rlRun "userdel -r $TEST_USER"
rlRun "popd"
rlRun "rm -r $tmp" 0 "Remove tmp directory"
rlRun "rm -f $JS_FILE" 0 "Remove JavaScript file"
rlPhaseEnd
rlJournalEnd

View file

@ -1,10 +0,0 @@
summary: extension fs is installed without error
test: ./runtest.sh
framework: beakerlib
description: |
Test ensures that extension fs is installed without errors.
duration: 5m
recommend: nodejs
require:
- nodejs
tier: '1'

View file

@ -1,98 +0,0 @@
#!/bin/bash
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2013 Red Hat, Inc. All rights reserved.
#
# This copyrighted material is made available to anyone wishing
# to use, modify, copy, or redistribute it subject to the terms
# and conditions of the GNU General Public License version 2.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/share/beakerlib/beakerlib.sh || exit 1
# Packages to be tested
PACKAGES=${PACKAGES:-nodejs}
# Other required packages
REQUIRES=${REQUIRES:-curl}
# Binary name parametrized
NODEJS=${NODEJS:-node}
# Port range for server to choose from
MIN_SERVER_PORT=${MIN_SERVER_PORT:-8000}
MAX_SERVER_PORT=${MAX_SERVER_PORT:-8080}
# Actual server port to use
SERVER_PORT=${SERVER_PORT:-8008}
# Time delay for server to start and for curl to download
SLEEP_TIME=${SLEEP_TIME:-10}
rlJournalStart
rlPhaseStartSetup
rlAssertRpm --all
rlAssertBinaryOrigin $NODEJS
# Try to choose port from a port range
port_chosen=false
rlLogInfo "Choosing server port..."
for port in $(seq ${MIN_SERVER_PORT} 1 ${MAX_SERVER_PORT}); do
if ! fuser ${port}/tcp >/dev/null 2>&1; then
SERVER_PORT=${port}
port_chosen=true
rlLogInfo "\"${SERVER_PORT}\" chosen"
break
fi
done
# Warn if port was not chosen from a port range
$port_chosen || rlLogWarning "No port available from a given range \"${MIN_SERVER_PORT}\" - \"${MAX_SERVER_PORT}\". Using \"${SERVER_PORT}\" anyway."
rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
rlRun "cp server.js $TmpDir/." 0 "Copying server source file"
rlRun "pushd $TmpDir"
rlPhaseEnd
rlPhaseStartTest
echo "---node-processes--"
ps -e | grep node
echo "---"
rlRun "${NODEJS} server.js ${SERVER_PORT} 2>&1 > server_out &" 0 "Running server and logging output"
rlRun "sleep ${SLEEP_TIME}" 0 "Giving server \"${SLEEP_TIME}\" seconds to start"
rlRun "curl --max-time ${SLEEP_TIME} http://127.0.0.1:${SERVER_PORT} > curl_out && cat curl_out" 0 "Querying server"
rlRun "grep 'Hello World' curl_out" 0 "Response should contain \"Hello World\""
rlRun "kill $!" 0 "Stopping the server"
sleep 1
rlRun "ps -e | grep $!" 1 "Server should not be running"
echo "---server-output--"
cat server_out
echo "---"
rlRun "grep 'Request received.' server_out" 0 "Output should contain \"Request received.\""
rlRun "grep 'Server has started.' server_out" 0 "Output should contain \"Server has started.\""
rlRun "kill -SIGKILL $!" 0,1 "Attempt killing possibly leftover server process"
echo "---node-processes-and-directory-contents--"
ps -e | grep node
ls -lah
echo "---"
rlPhaseEnd
rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
rlPhaseEnd
rlJournalPrintText
rlJournalEnd

View file

@ -1,18 +0,0 @@
// server.js -- minimal node.js http server
// Usage: node server.js [PORT]
// Default port is 8000
var http = require("http");
var port = process.argv[2] || 8000;
function onRequest(request, response) {
console.log("Request received.");
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World\n");
response.end();
}
http.createServer(onRequest).listen(port);
console.log("Server has started.");

View file

@ -0,0 +1,11 @@
summary: Basic expo server test
test: ./runtest.sh
framework: beakerlib
description: |
Test ensures that nodejs and npm can install and run expo app
duration: 15m
require: nodejs
tier: smoke
component:
- npm
- nodejs

30
Smoke/install-expo/runtest.sh Executable file
View file

@ -0,0 +1,30 @@
#!/bin/bash
. /usr/share/beakerlib/beakerlib.sh || exit 1
TEST_USER="nodeuser"
NPMJS=${NPMJS:-npm}
rlJournalStart
rlPhaseStartSetup
rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory"
rlRun "pushd $tmp"
rlPhaseEnd
#Test installation and usage of expo
rlPhaseStartTest
rlShowPackageVersion nodejs
rlRun "npm install expo create-expo-app --verbose" 0
rlRun "npx create-expo-app my-app -y" 0
rlRun "cd my-app" 0
rlRun "nohup npx expo start --port=19000 &>server.log &" 0 "Starting a server"
rlRun "sleep 10" 0
rlRun "curl http://localhost:19000" 0
rlPhaseEnd
rlPhaseStartCleanup
rlLogInfo "Deleting files created by npm install"
rlRun "popd"
rlRun "rm -r $tmp" 0 "Remove tmp directory"
rlPhaseEnd
rlJournalEnd

View file

@ -0,0 +1,12 @@
summary: Verify ability to install modules through various means
test: ./runtest.sh
framework: beakerlib
description: |
Test ensures that npm has the ability to install modules through various means.
duration: 5m
recommend:
require:
tier: '1'
component:
- npm
- nodejs

View file

@ -1,4 +1,8 @@
#!/bin/bash
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2013 Red Hat, Inc. All rights reserved.
@ -41,6 +45,7 @@ NODEJS=${NODEJS:-node}
# NPM binary name parametrized
NPMJS=${NPMJS:-npm}
# Parameters to check using "npm parameter" and what to look for in their output
rlJournalStart
rlPhaseStartSetup
@ -123,4 +128,3 @@ rlJournalStart
rlJournalPrintText
rlJournalEnd

View file

@ -0,0 +1,13 @@
summary: NPM implementation can pass upstream test suite
test: ./runtest.sh
framework: beakerlib
description: |
Test ensures that NPM implementation can pass upstream test suite.
duration: 5m
recommend:
require:
- git
tier: '1'
component:
- npm
- nodejs

View file

@ -1,7 +1,11 @@
#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of /CoreOS/nodejs/Sanity/express-testsuite
# Description: Basic sanity test for express module.
# Author: Tomáš Juhász <tjuhasz@redhat.com>
# Inspired by internal test by: Honza Horak <hhorak@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
@ -22,6 +26,10 @@
# Boston, MA 02110-1301, USA.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# This test supports following parameters:
# Standard PACKAGES, REQUIRES, COLLECTIONS parameters.
# Include Beaker environment
. /usr/share/beakerlib/beakerlib.sh || exit 1
@ -45,8 +53,6 @@ rlJournalStart
rlRun "latest_express=$(npm show express version)" 0 "Figuring out what the latest express version is"
rlLog "Latest Express version: ${latest_express}"
rlRun "git stash" 0 "Stashing eventual changes so they don't prevent checkout"
rlRun "git checkout '${latest_express}'" 0 "Checkout git's tag ${latest_express}"
rlRun "npm install mocha"
rlRun -s "npm test" 0 "Running the test-suite"
rlAssertGrep "[0-9]* passing" "$rlRun_LOG" -E

44
install-rpms.sh Executable file
View file

@ -0,0 +1,44 @@
#!/bin/bash
KOJI_TASK_ID=2596437
#KOJI_TASK_ID=${KOJI_TASK_ID:-} # Use the environment variable, or an empty string if not set
# Check if KOJI_TASK_ID is set
[ -n "$KOJI_TASK_ID" ] || {
echo "env variable \$KOJI_TASK_ID not specified" >&2
echo "This variable should be present in TestingFarm" >&2
exit 1
}
# Get the current architecture
ARCH=$(uname -m)
# Download the build for the current architecture
koji download-build $KOJI_TASK_ID --arch=$ARCH || {
echo "Failed to download build $KOJI_TASK_ID for architecture $ARCH using koji" >&2
exit 1
}
#( koji download-build --debuginfo --task-id --arch noarch --arch x86_64 --arch i686 --arch src $KOJI_TASK_ID || koji download-task --arch noarch --arch x86_64 --arch i686 --arch src $KOJI_TASK_ID ) | egrep Downloading | cut -d " " -f 3 | tee rpms-list-$KOJI_TASK_ID
#ls *[^.src].rpm | sed -r "s/(.*)-.*-.*/\1 \0/" | egrep -v "i686" | awk "{print \$2}" | tee rpms-list
#dnf -y reinstall $(cat rpms-list) || true
#if [ ! -z "$(sed 's/\s//g' rpms-list)" ];then dnf -y install --allowerasing $(cat rpms-list);else echo "Nothing to install, rpms-list is empty"; fi
#if [ ! -z "$(sed 's/\s//g' rpms-list)" ];then sed 's/.rpm$//' rpms-list | xargs -n1 command printf '%q\n' | xargs -d'\n' rpm -q;else echo 'Nothing to verify, rpms-list is empty'; fi
# Ensure the required RPMs exist
MAIN_RPM=$(ls nodejs-*.x86_64.rpm 2>/dev/null | head -n 1)
DEPENDENCY_RPM=$(ls nodejs-libs-*.x86_64.rpm 2>/dev/null | head -n 1)
NPM_RPM=$(ls nodejs-npm-*.x86_64.rpm 2>/dev/null | head -n 1)
# Check if all necessary RPMs are found
if [ -z "$MAIN_RPM" ] || [ -z "$DEPENDENCY_RPM" ] || [ -z "$NPM_RPM" ]; then
echo "Required RPMs not found for x86_64 architecture." >&2
exit 1
fi
# Install the main package, its dependency, and npm package
rpm -ivh "$MAIN_RPM" "$DEPENDENCY_RPM" "$NPM_RPM" || {
echo "Failed to install RPMs" >&2
exit 1
}

View file

@ -1,5 +1,4 @@
# This metadata will be applied to each test case
contact: Tomas Juhasz <tjuhasz@redhat.com> Andrei Radchenko <aradchen@redhat.com>
test: ./runtest.sh
framework: beakerlib

View file

@ -1,36 +1,37 @@
# Root plan: Defines common metadata
/:
# To not inherit anything from some tests 'above'?
inherit: false
# This will apply to each sub-plans below
# Shared metadata
discover:
how: fmf
execute:
how: tmt
environment:
KOJI_BUILD_ID: 123
provision:
how: container
image: 'fedora:rawhide'
prepare:
- name: Install test deps
how: install
package:
- beakerlib
- koji
- libuv
- cpio
- name: Install fresh packages from Koji
how: shell
script: ./install-rpms.sh
# Subplan: Run all the tests
# Filtering
/all:
summary: Run all Node.js tests.
discover:
how: fmf
# You probably dont want to run all TCs on each commit to this repo.
# Still need to figure out where this check happens
adjust:
- when: trigger == commit
enabled: false
# Subplan: Run smoke tests only
summary: Run all available tests
/smoke:
summary: Run smoke tests for Node.js.
summary: Run all smoke tests
discover:
how: fmf
filter: "tier:smoke" # Filter tests tagged as smoke tests
filter: "tier: smoke"
# Subplan: Run extended tests (long-running)
/extended:
summary: Run extended Node.js tests.
/integration:
summary: Run all intergraion tests
discover:
how: fmf
filter: "tier:extended" # Filter tests tagged as extended
adjust:
- when: environment == production
enabled: false # Disable extended tests in production environments
filter: "tier: integration"