var (
post = flag.String("post", "", "urlencoded form data to POST")
- port = flag.Bool("port", false, "find open port and print to stdout")
+ addr = flag.Bool("addr", false, "find open address and print to stdout")
)
func main() {
flag.Parse()
- if *port {
+ if *addr {
l, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
log.Exit(err)
}
defer l.Close()
- fmt.Print(l.Addr().(*net.TCPAddr).Port)
+ fmt.Print(l.Addr())
return
}
url := flag.Arg(0)
-#!/bin/bash
+#!/usr/bin/env bash
+set -e
wiki_pid=
-
cleanup() {
kill $wiki_pid
rm -f test_*.out Test.txt final-test.bin final-test.go
- exit ${1:-1}
}
-trap cleanup INT
+trap cleanup 0 INT
-port=$(./get.bin -port)
-sed s/8080/$port/ < final.go > final-test.go
-gomake final-test.bin || cleanup 1
+gomake get.bin
+addr=$(./get.bin -addr)
+sed s/:8080/$addr/ < final.go > final-test.go
+gomake final-test.bin
./final-test.bin &
wiki_pid=$!
sleep 1
-./get.bin http://127.0.0.1:$port/edit/Test > test_edit.out
-diff -u test_edit.out test_edit.good || cleanup 1
-./get.bin -post=body=some%20content http://127.0.0.1:$port/save/Test
-diff -u Test.txt test_Test.txt.good || cleanup 1
-./get.bin http://127.0.0.1:$port/view/Test > test_view.out
-diff -u test_view.out test_view.good || cleanup 1
-
-echo "Passed"
-cleanup 0
+./get.bin http://$addr/edit/Test > test_edit.out
+diff -u test_edit.out test_edit.good
+./get.bin -post=body=some%20content http://$addr/save/Test
+diff -u Test.txt test_Test.txt.good
+./get.bin http://$addr/view/Test > test_view.out
+diff -u test_view.out test_view.good
+echo PASS