rsc.io/go@v0.0.0-20150416155037-e040fd465409/doc/articles/wiki/test.bash (about)

     1  #!/usr/bin/env bash
     2  # Copyright 2010 The Go Authors. All rights reserved.
     3  # Use of this source code is governed by a BSD-style
     4  # license that can be found in the LICENSE file.
     5  
     6  set -e
     7  wiki_pid=
     8  cleanup() {
     9  	kill $wiki_pid
    10  	rm -f test_*.out Test.txt final.bin final-port.txt a.out get.bin
    11  }
    12  trap cleanup 0 INT
    13  
    14  rm -f get.bin final.bin a.out
    15  
    16  # If called with -all, check that all code snippets compile.
    17  if [ "$1" == "-all" ]; then
    18  	for fn in *.go; do
    19  		go build -o a.out $fn
    20  	done
    21  fi
    22  
    23  go build -o get.bin get.go
    24  go build -o final.bin final.go
    25  (./final.bin --addr) &
    26  wiki_pid=$!
    27  
    28  l=0
    29  while [ ! -f ./final-port.txt ]
    30  do
    31  	l=$(($l+1))
    32  	if [ "$l" -gt 5 ]
    33  	then
    34  		echo "port not available within 5 seconds"
    35  		exit 1
    36  		break
    37  	fi
    38  	sleep 1
    39  done
    40  
    41  addr=$(cat final-port.txt)
    42  ./get.bin http://$addr/edit/Test > test_edit.out
    43  diff -u test_edit.out test_edit.good
    44  ./get.bin -post=body=some%20content http://$addr/save/Test > test_save.out
    45  diff -u test_save.out test_view.good # should be the same as viewing
    46  diff -u Test.txt test_Test.txt.good
    47  ./get.bin http://$addr/view/Test > test_view.out
    48  diff -u test_view.out test_view.good
    49  
    50  echo PASS