github.com/criteo/command-launcher@v0.0.0-20230407142452-fb616f546e98/test/integration/test-cmd-context.sh (about)

     1  #!/bin/bash
     2  
     3  # required environment varibale
     4  # CL_PATH
     5  # CL_HOME
     6  # OUTPUT_DIR
     7  SCRIPT_DIR=${1:-$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )}
     8  
     9  ##
    10  # test command context
    11  ##
    12  rm -rf $CL_HOME/dropins
    13  mkdir -p $CL_HOME/dropins
    14  cp -R $SCRIPT_DIR/../packages-src/bonjour $CL_HOME/dropins
    15  
    16  echo "> test the command without LOG_LEVEL"
    17  RESULT=$($OUTPUT_DIR/cl bonjour)
    18  echo "$RESULT" | grep -q "bonjour!"
    19  if [ $? -eq 0 ]; then
    20    echo "OK"
    21  else
    22    echo "KO - wrong output of hello command: $RESULT"
    23    exit 1
    24  fi
    25  
    26  echo "> test set config"
    27  RESULT=$($OUTPUT_DIR/cl config log_level debug)
    28  RESULT=$($OUTPUT_DIR/cl config)
    29  echo "$RESULT" | grep -q "log_level                               : debug"
    30  if [ $? -eq 0 ]; then
    31    echo "OK"
    32  else
    33    echo "KO - failed to set config: log_level"
    34    exit 1
    35  fi
    36  
    37  echo "> test get single config"
    38  RESULT=$($OUTPUT_DIR/cl config log_level)
    39  if [ "$RESULT" = "debug" ]; then
    40    echo "OK"
    41  else
    42    echo "KO - failed to get config: log_level"
    43    exit 1
    44  fi
    45  
    46  echo "> test the command with LOG_LEVEL"
    47  RESULT=$($OUTPUT_DIR/cl bonjour)
    48  echo $RESULT | grep -q "bonjour! debug"
    49  if [ $? -eq 0 ]; then
    50    echo "OK"
    51  else
    52    echo "KO - wrong output of hello command: $RESULT"
    53    exit 1
    54  fi
    55  
    56  echo "> test default checkFlags = false, no flag and arg environment should be injected"
    57  RESULT=$($OUTPUT_DIR/cl bonjour --name Joe --language French world)
    58  echo "$RESULT" | grep -q "Joe"
    59  if [ $? -eq 0 ]; then
    60    echo "KO - no environment variable CL_FLAG_NAME should be found"
    61    exit 1
    62  else
    63    echo "OK"
    64  fi
    65  
    66  echo "$RESULT" | grep -q "French"
    67  if [ $? -eq 0 ]; then
    68    echo "KO - no environment variable CL_FLAG_LANGUAGE should be found"
    69    exit 1
    70  else
    71    echo "OK"
    72  fi
    73  
    74  echo "$RESULT" | grep -q "world"
    75  if [ $? -eq 0 ]; then
    76    echo "KO - no environment variable CL_ARG_1 should be found"
    77    exit 1
    78  else
    79    echo "OK"
    80  fi
    81  
    82  echo "> test PACKAGE_DIR environment variable"
    83  RESULT=$($CL_PATH bonjour)
    84  echo "$RESULT" | grep "home"
    85  if [ $? -eq 0 ]; then
    86    echo "OK"
    87  else
    88    echo "KO - should have PACKAGE_DIR environment variable"
    89    exit 1
    90  fi
    91