Adding simple tests
This commit is contained in:
50
test.ksh
Executable file
50
test.ksh
Executable file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/ksh
|
||||
echo "Testing HP-UX compatibility for Rubrik scripts..."
|
||||
|
||||
# Check for required commands
|
||||
for cmd in ksh awk readlink egrep date dfsdf expr mkdir; do
|
||||
if ! command -v $cmd >/dev/null 2>&1; then
|
||||
echo "ERROR: $cmd not found in PATH"
|
||||
else
|
||||
echo "OK: $cmd found"
|
||||
fi
|
||||
done
|
||||
|
||||
# Test awk JSON extraction for numChannels
|
||||
echo '{"numChannels": 4, "foo": "bar"}' > /tmp/testjson.$$
|
||||
numChannels=$(awk '{match($0, /"numChannels":[ ]*[0-9]+/); if (RSTART > 0) {val=substr($0, RSTART, RLENGTH); sub(/.*:[ ]*/, "", val); print val}}' /tmp/testjson.$$)
|
||||
if [ "$numChannels" = "4" ]; then
|
||||
echo "OK: awk numChannels extraction works"
|
||||
else
|
||||
echo "ERROR: awk numChannels extraction failed (got '$numChannels')"
|
||||
fi
|
||||
|
||||
# Test awk JSON extraction for ManagedVolume
|
||||
echo '{"id":"ManagedVolume:::abc-123-xyz"}' > /tmp/testjson.$$
|
||||
mvId=$(awk '{match($0, /ManagedVolume:::[a-z0-9-]*/); if (RSTART > 0) {id=substr($0, RSTART, RLENGTH); sub(/"$/, "", id); print id}}' /tmp/testjson.$$)
|
||||
if [ "$mvId" = "ManagedVolume:::abc-123-xyz" ]; then
|
||||
echo "OK: awk ManagedVolume extraction works"
|
||||
else
|
||||
echo "ERROR: awk ManagedVolume extraction failed (got '$mvId')"
|
||||
fi
|
||||
|
||||
# Test readlink
|
||||
ln -s /tmp/testjson.$$ /tmp/testlink.$$
|
||||
linkres=$(readlink /tmp/testlink.$$ 2>/dev/null)
|
||||
if [ "$linkres" = "/tmp/testjson.$$" ]; then
|
||||
echo "OK: readlink works"
|
||||
else
|
||||
echo "WARNING: readlink did not return expected result (got '$linkres')"
|
||||
fi
|
||||
rm -f /tmp/testjson.$$ /tmp/testlink.$$
|
||||
|
||||
# Test expr arithmetic
|
||||
i=0
|
||||
i=$(expr $i + 1)
|
||||
if [ "$i" = "1" ]; then
|
||||
echo "OK: expr arithmetic works"
|
||||
else
|
||||
echo "ERROR: expr arithmetic failed"
|
||||
fi
|
||||
|
||||
echo "Testing complete."
|
||||
Reference in New Issue
Block a user