node js tests

This commit is contained in:
Tomas Juhasz 2025-01-03 11:33:05 +01:00
commit f1ee23f5fa
26 changed files with 935 additions and 2 deletions

View file

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

View file

@ -0,0 +1,54 @@
#!/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