Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.38 KB | None | 0 0
  1. #!/bin/bash
  2. set -e
  3. set -o pipefail
  4.  
  5. function find_in_docker_log {
  6.     CONTAINER_NAME=$1
  7.     TIMEOUT=$2
  8.     SUBSTRING=$3
  9.     COMMAND="docker logs -f $CONTAINER_NAME"
  10.     expect -c "log_user 0; set timeout $TIMEOUT; spawn $COMMAND; expect \"$SUBSTRING\" { exit 0 } timeout { exit 1 }"
  11. }
  12.  
  13. IMAGE_NAME=single_horizontal.jpg
  14. CONTAINER_NAME=alpr_test
  15.  
  16. # Start the container
  17. docker run --name $CONTAINER_NAME -d flyingtophat/alpr
  18.     http://127.0.0.1/$IMAGE_NAME \ # URL to poll for photo
  19.     http://127.0.0.1/ \ # URL to post the results (not used for test)
  20.     --verbose \ # Increase verbosity to ensure data that would be posted is printed to stdout
  21.     --interval 1 # Small increment to speed up tests
  22.  
  23. # Run the image with the localhost URL to poll
  24. docker run --name $CONTAINER_NAME -d flyingtophat/alpr http://127.0.0.1/$IMAGE_NAME http://127.0.0.1/ --verbose
  25.  
  26. # Start web-server to serve test data
  27. docker exec -d $CONTAINER_NAME python -m SimpleHTTPServer 80
  28.  
  29. # Copy test data to the working directory for Python's HTTP Server to serve
  30. docker cp ./test_files/$TEST_DATA_FILENAME $CONTAINER_NAME:/opt/docker-alpr/
  31.  
  32. # Wait for license plate to appear in image's output
  33. find_in_docker_log $CONTAINER_NAME $TIMEOUT "WR62XDF"
  34. TEST_RESULT=$?
  35.  
  36. # Report test status
  37. docker rm -f $CONTAINER_NAME
  38. if [ $TEST_RESULT == 0 ]; then
  39.     echo "SUCCESS"
  40. else
  41.     echo "FAILED"
  42.     exit 1
  43. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement