mirror of
https://github.com/golang/go
synced 2024-11-25 04:57:56 -07:00
doc/codelab/wiki: fixes
make test.sh runnable as a command. announce only on 127.0.0.1. rebuild final-test.bin when final-test.go changes. R=adg, r CC=golang-dev https://golang.org/cl/4030044
This commit is contained in:
parent
9b07abab78
commit
634cef25c3
@ -19,6 +19,7 @@ test: get.bin
|
||||
|
||||
%.bin: %.$O
|
||||
$(LD) -o $@ $<
|
||||
%.$O:
|
||||
|
||||
%.$O: %.go
|
||||
$(GC) $*.go
|
||||
|
||||
|
@ -13,18 +13,18 @@ import (
|
||||
|
||||
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)
|
||||
|
@ -1,29 +1,27 @@
|
||||
#!/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
|
||||
|
Loading…
Reference in New Issue
Block a user