test_helper.bash 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. setup() {
  2. IMAGE_NAME="$NAME:$VERSION"
  3. }
  4. # function relative to the current container / image
  5. build_image() {
  6. #disable outputs
  7. docker build -t $IMAGE_NAME $BATS_TEST_DIRNAME/../image &> /dev/null
  8. }
  9. run_image() {
  10. CONTAINER_ID=$(docker run $@ -d $IMAGE_NAME)
  11. CONTAINER_IP=$(get_container_ip_by_cid $CONTAINER_ID)
  12. }
  13. start_container() {
  14. start_containers_by_cid $CONTAINER_ID
  15. }
  16. stop_container() {
  17. stop_containers_by_cid $CONTAINER_ID
  18. }
  19. remove_container() {
  20. remove_containers_by_cid $CONTAINER_ID
  21. }
  22. clear_container() {
  23. stop_containers_by_cid $CONTAINER_ID
  24. remove_containers_by_cid $CONTAINER_ID
  25. }
  26. wait_process() {
  27. wait_process_by_cid $CONTAINER_ID $@
  28. }
  29. # generic functions
  30. get_container_ip_by_cid() {
  31. local IP=$(docker inspect -f "{{ .NetworkSettings.IPAddress }}" $1)
  32. echo "$IP"
  33. }
  34. start_containers_by_cid() {
  35. for cid in "$@"
  36. do
  37. #disable outputs
  38. docker start $cid &> /dev/null
  39. done
  40. }
  41. stop_containers_by_cid() {
  42. for cid in "$@"
  43. do
  44. #disable outputs
  45. docker stop $cid &> /dev/null
  46. done
  47. }
  48. remove_containers_by_cid() {
  49. for cid in "$@"
  50. do
  51. #disable outputs
  52. docker rm $cid &> /dev/null
  53. done
  54. }
  55. clear_containers_by_cid() {
  56. stop_containers_by_cid $@
  57. remove_containers_by_cid $@
  58. }
  59. wait_process_by_cid() {
  60. cid=$1
  61. docker exec $cid /container/tool/wait-process ${@:2}
  62. }