mirror of
https://github.com/golang/go
synced 2024-11-22 01:44:40 -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
|
%.bin: %.$O
|
||||||
$(LD) -o $@ $<
|
$(LD) -o $@ $<
|
||||||
%.$O:
|
|
||||||
|
%.$O: %.go
|
||||||
$(GC) $*.go
|
$(GC) $*.go
|
||||||
|
|
||||||
|
@ -13,18 +13,18 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
post = flag.String("post", "", "urlencoded form data to POST")
|
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() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if *port {
|
if *addr {
|
||||||
l, err := net.Listen("tcp", "127.0.0.1:0")
|
l, err := net.Listen("tcp", "127.0.0.1:0")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Exit(err)
|
log.Exit(err)
|
||||||
}
|
}
|
||||||
defer l.Close()
|
defer l.Close()
|
||||||
fmt.Print(l.Addr().(*net.TCPAddr).Port)
|
fmt.Print(l.Addr())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
url := flag.Arg(0)
|
url := flag.Arg(0)
|
||||||
|
@ -1,29 +1,27 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -e
|
||||||
wiki_pid=
|
wiki_pid=
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
kill $wiki_pid
|
kill $wiki_pid
|
||||||
rm -f test_*.out Test.txt final-test.bin final-test.go
|
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)
|
gomake get.bin
|
||||||
sed s/8080/$port/ < final.go > final-test.go
|
addr=$(./get.bin -addr)
|
||||||
gomake final-test.bin || cleanup 1
|
sed s/:8080/$addr/ < final.go > final-test.go
|
||||||
|
gomake final-test.bin
|
||||||
./final-test.bin &
|
./final-test.bin &
|
||||||
wiki_pid=$!
|
wiki_pid=$!
|
||||||
|
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|
||||||
./get.bin http://127.0.0.1:$port/edit/Test > test_edit.out
|
./get.bin http://$addr/edit/Test > test_edit.out
|
||||||
diff -u test_edit.out test_edit.good || cleanup 1
|
diff -u test_edit.out test_edit.good
|
||||||
./get.bin -post=body=some%20content http://127.0.0.1:$port/save/Test
|
./get.bin -post=body=some%20content http://$addr/save/Test
|
||||||
diff -u Test.txt test_Test.txt.good || cleanup 1
|
diff -u Test.txt test_Test.txt.good
|
||||||
./get.bin http://127.0.0.1:$port/view/Test > test_view.out
|
./get.bin http://$addr/view/Test > test_view.out
|
||||||
diff -u test_view.out test_view.good || cleanup 1
|
diff -u test_view.out test_view.good
|
||||||
|
|
||||||
echo "Passed"
|
|
||||||
cleanup 0
|
|
||||||
|
|
||||||
|
echo PASS
|
||||||
|
Loading…
Reference in New Issue
Block a user