github.com/upcmd/up@v0.8.1-0.20230108151705-ad8b797bf04f/tests/functests/c0209.yml (about) 1 tasks: 2 - 3 name: task 4 task: 5 - 6 func: shell 7 desc: shows that all exit codes are 0 in the test of curl even though the http responses are different 8 do: 9 - | 10 curl http://httpbin.org/status/200 --write-out "%{http_code}" 11 echo " \nexit code:$?" 12 13 - | 14 curl http://httpbin.org/status/401 --write-out "%{http_code}" 15 echo " \nexit code:$?" 16 17 - | 18 curl http://httpbin.org/status/500 --write-out "%{http_code}" 19 echo " \nexit code:$?" 20 21 - 22 func: call 23 desc: | 24 wrap up a task to deal with return codes 25 treat the transactions with code 200 and 201 as successful 26 the handle_exit_code task could be extend to take more input variable such as endpoint etc 27 do: handle_exit_code 28 loop: '{{loopRange 1 50 "try5times"}}' 29 30 - func: cmd 31 desc: show if the above http request is successful 32 do: 33 - name: print 34 cmd: '?success: {{.success}}' 35 36 - 37 name: handle_exit_code 38 task: 39 - 40 func: shell 41 desc: prototyping the case to randomly get a http response either 200 or 201 42 do: | 43 array[0]=200 44 array[1]=201 45 array[2]=301 46 array[3]=302 47 array[4]=404 48 array[5]=500 49 size=${#array[@]} 50 index=$(($RANDOM % $size)) 51 echo ${array[$index]} 52 reg: result 53 54 - func: cmd 55 dvars: 56 - name: success 57 value: '{{ list "200" "201" | has .result.Output }}' 58 flags: 59 - v 60 do: 61 - name: return 62 cmd: 63 - success