Skip to content
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 integration tests of invalid REST floating point and Boolean parameters. #1796

Merged

Conversation

aaronweeden
Copy link
Contributor

@aaronweeden aaronweeden commented Dec 11, 2023

Description

This PR adds the ability to test for invalid REST floating point and Boolean parameters using the existing method IntegrationTests\BaseTest::provideRestEndpointTests().

This PR also adds an exception to that method if an option is provided that is unrecognized. This is to help with development of new tests that use the method by helping catching typos in option names.

Motivation and Context

The main xdmod module has no calls to the methods getFloatParam() and getBooleanParam() from Rest\Controllers\BaseControllerProvider, but the xdmod-appkernels module does. ubccr/xdmod-appkernels#95 adds tests of invalid floating point and Boolean parameters that will use the changes in this PR.

Tests performed

To make sure this didn't cause any changes in the tests that are run, in a Docker container running tools-ext-01.ccr.xdmod.org/xdmod-10.5.0-x86_64:rockylinux8.5-0.3:

  1. Run the following commands:
    export COMPOSER_ALLOW_SUPERUSER=1
    export XDMOD_REALMS='jobs,storage,cloud'
    export XDMOD_IS_CORE=yes
    export XDMOD_INSTALL_DIR=/xdmod
    export XDMOD_TEST_MODE=upgrade
    openssl genrsa -rand /proc/cpuinfo:/proc/dma:/proc/filesystems:/proc/interrupts:/proc/ioports:/proc/uptime 2048 > /etc/pki/tls/private/localhost.key
    /usr/bin/openssl req -new -key /etc/pki/tls/private/localhost.key -x509 -sha256 -days 365 -set_serial $RANDOM -extensions v3_req -out /etc/pki/tls/certs/localhost.crt -subj "/C=XX/L=Default City/O=Default Company Ltd"
    git clone https://github.com/ubccr/xdmod /xdmod
    cd /xdmod
    composer install
    mkdir ~/phpunit
    mkdir /tmp/screenshots
    ~/bin/buildrpm xdmod
    ./tests/ci/bootstrap.sh
    ./tests/ci/validate.sh
    composer install --no-progress
    mv ./configuration/organization.json ./configuration/organization.json.old
    mv ./configuration/portal_settings.ini ./configuration/portal_settings.ini.old
    cp /etc/xdmod/portal_settings.ini ./configuration/portal_settings.ini
    cp /etc/xdmod/organization.json ./configuration/organization.json
    ./tests/ci/scripts/qa-test-setup.sh
    sed -i 's/\$phpunit /$phpunit --debug /' /xdmod/tests/unit/runtests.sh
    ./tests/unit/runtests.sh > /unit-before.txt
    sed -i 's/\$phpunit /$phpunit --debug /' ./tests/regression/runtests.sh
    ./tests/regression/runtests.sh > /regression-before.txt
    cd ./tests/integration
    ../../vendor/bin/phpunit --testsuite default --group UserAdminTest.createUsers --debug > /integration-before.txt
    ../../vendor/bin/phpunit --testsuite default --exclude-group UserAdminTest.createUsers --debug >> /integration-before.txt
    cd ../../
    sed -i 's/\$phpunit /$phpunit --debug /' ./tests/component/runtests.sh
    ./tests/component/runtests.sh > /component-before.txt
    git clone https://github.com/aaronweeden/xdmod -b add-bool-and-float-param-tests /xdmod-new
    unalias rm
    rm -r /xdmod/tests/integration/lib
    cp -r /xdmod{-new,}/tests/integration/lib
    ./tests/unit/runtests.sh > /unit-after.txt
    ./tests/component/runtests.sh > /component-after.txt
    ./tests/regression/runtests.sh > /regression-after.txt
    cd ./tests/integration
    ../../vendor/bin/phpunit --testsuite default --group UserAdminTest.createUsers --debug > /integration-after.txt
    ../../vendor/bin/phpunit --testsuite default --exclude-group UserAdminTest.createUsers --debug >> /integration-after.txt
    cd ../../
    for file in /regression-{before,after}.txt; do
        for test in {testChartSettings,testChartFilters,testCsvExport}; do
            for realm in {Jobs,Cloud,Storage}; do
                sed -i "s/$test with data set.*$realm.*/$test $realm/" $file;
            done;
        done;
        sort $file > $file-sorted;
    done
    
  2. Compare /unit-{before,after}.txt and make sure the only differences are namespace names, user hashes, and amount of time the tests ran.
  3. Compare /component-{before,after}.txt and make sure the only differences are namespace names, test name hashes, and amount of time the tests ran.
  4. Compare /regression-{before,after}.txt-sorted and make sure the only differences are namespace names, amount of time the tests ran, and possibly transient "other notices" related to small differences in column values.
  5. Compare /integration-{before,after}.txt and make sure the only differences are namespace names, random values for ControllerTest::testEnumTargetAddresses, and amount of time the tests ran.

I also manually tested to make sure the InvalidArgumentException can be properly thrown by changing a call to provideRestEndpointTests to have an invalid argument key.

Checklist:

  • The pull request description is suitable for a Changelog entry
  • The milestone is set correctly on the pull request
  • The appropriate labels have been added to the pull request

@aaronweeden aaronweeden added the qa / testing Updates/additions to tests label Dec 11, 2023
@aaronweeden aaronweeden added this to the 11.0.0 milestone Dec 11, 2023
@aaronweeden aaronweeden merged commit 0d59e49 into ubccr:xdmod11.0 Dec 12, 2023
4 checks passed
@aaronweeden aaronweeden deleted the add-bool-and-float-param-tests branch December 12, 2023 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
qa / testing Updates/additions to tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants