github.com/criteo/command-launcher@v0.0.0-20230407142452-fb616f546e98/test/integration/test-flag-arg.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 flag and arg environments (available when checkFlags: true) 11 ### 12 rm -rf $CL_HOME/dropins 13 mkdir -p $CL_HOME/dropins 14 cp -R $SCRIPT_DIR/../packages-src/flag-env $CL_HOME/dropins 15 16 echo "> test the flag and arg environment" 17 RESULT=$($OUTPUT_DIR/cl bonjour --name Joe --language French world) 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 $RESULT | grep -q "Joe" 27 if [ $? -eq 0 ]; then 28 echo "OK" 29 else 30 echo "KO - no environment variable CL_FLAG_NAME found" 31 exit 1 32 fi 33 34 echo $RESULT | grep -q "French" 35 if [ $? -eq 0 ]; then 36 echo "OK" 37 else 38 echo "KO - no environment variable CL_FLAG_LANGUAGE found" 39 exit 1 40 fi 41 42 echo $RESULT | grep -q "world" 43 if [ $? -eq 0 ]; then 44 echo "OK" 45 else 46 echo "KO - no environment variable CL_ARG_1 found" 47 exit 1 48 fi 49 50 # test COLA environment variable 51 echo "> test COLA environment variable" 52 echo $RESULT | grep -q "cola flag: Joe" 53 if [ $? -eq 0 ]; then 54 echo "OK" 55 else 56 echo "KO - no environment variable COLA_FLAG_NAME found" 57 exit 1 58 fi 59 60 echo $RESULT | grep -q "cola flag: French" 61 if [ $? -eq 0 ]; then 62 echo "OK" 63 else 64 echo "KO - no environment variable COLA_FLAG_LANGUAGE found" 65 exit 1 66 fi 67 68 echo $RESULT | grep -q "cola arg: world" 69 if [ $? -eq 0 ]; then 70 echo "OK" 71 else 72 echo "KO - no environment variable COLA_ARG_1 found" 73 exit 1 74 fi 75 76 77 echo "> test required flags error" 78 RESULT=$($CL_PATH nihao World 2>&1) 79 echo $RESULT 80 echo "$RESULT" | grep -q "Error: required flag(s) \"isolated-required\", \"name\" not set" 81 if [ $? -eq 0 ]; then 82 echo "OK" 83 else 84 echo "KO - should have error" 85 exit 1 86 fi 87 88 echo "> test exclusive flags error" 89 RESULT=$($CL_PATH nihao --name Joe --language fr World --isolated-required value --json --text 2>&1) 90 echo "$RESULT" | grep -q "Error: if any flags in the group \[text json\] are set none of the others can be; \[json text\] were all set" 91 if [ $? -eq 0 ]; then 92 echo "OK" 93 else 94 echo "KO - should have error" 95 exit 1 96 fi 97 98 echo "> test group flags error" 99 RESULT=$($CL_PATH nihao --name Joe World --isolated-required value 2>&1) 100 echo "$RESULT" | grep -q "Error: if any flags in the group \[name language\] are set they must all be set; missing \[language\]" 101 if [ $? -eq 0 ]; then 102 echo "OK" 103 else 104 echo "KO - should have error" 105 exit 1 106 fi 107 108 echo "> test flags" 109 RESULT=$($CL_PATH nihao --name Joe --language fr World --json --isolated-required value 2>&1) 110 echo "$RESULT" | grep -q "\-\-isolated-required value \-\-json \-\-language fr \-\-name Joe World" 111 if [ $? -eq 0 ]; then 112 echo "OK" 113 else 114 echo "KO - should pass original arguments to the scripts" 115 exit 1 116 fi 117 118 119 echo "> test flags - show contain number of arguments" 120 echo "$RESULT" | grep -q "cola nargs: 1" 121 if [ $? -eq 0 ]; then 122 echo "OK" 123 else 124 echo "KO - show contain number of arguments" 125 exit 1 126 fi