#!/bin/sh
# Simulate valid and invalid output of the sacct command for use in testing
# xdmod-slurm-helper.  Depending on the XDMOD_SACCT_OUTPUT_TYPE environment
# variable the script will output valid sacct data in the expected format,
# invalid data, no data or an error message to STDERR.  Exits with the value in
# the XDMOD_SACCT_EXIT_STATUS environment variable.

case "$XDMOD_SACCT_OUTPUT_TYPE" in
    no_output)
        ;;
    valid_output)
        echo '4103947_100|4103947|hpc|general-compute|anon|anon|918273|unknown|192837|2015-06-26T13:57:00|2015-06-26T13:57:00|2015-06-28T02:55:50|2015-07-01T02:55:50|3-00:00:00|1:0|TIMEOUT|32|256|256|3000Mc|||billing=256,cpu=256,mem=768000M,node=32|3-00:00:00|d07n07s02,d07n19s02,d07n25s01,d07n28s01,d07n29s01,d07n31s02,d07n38s02,d09n04s[01-02],d09n05s02,d09n06s01,d09n07s01,d09n08s[01-02],d09n09s01,d09n11s[01-02],d09n13s01,d09n14s01,d09n15s01,d09n16s01,d09n17s01,d09n24s01,d09n25s02,d09n28s01,d09n35s01,d09n38s02,d13n[03,05,07-08,16]|1AbC-2-3'
        ;;
    invalid_output)
        echo This is not valid sacct output
        ;;
    stderr_output)
        echo sacct failed 1>&2
        ;;
    *)
        echo XDMOD_SACCT_OUTPUT_TYPE value not recognized 1>&2
        exit 1
        ;;
esac

if [ "$XDMOD_SACCT_EXIT_STATUS" = "" ]; then
    echo XDMOD_SACCT_EXIT_STATUS not set 1>&2
    exit 1
fi

exit $XDMOD_SACCT_EXIT_STATUS
