瀏覽代碼

Start tests of the HTTP monitor

Ask Bjørn Hansen 12 年之前
父節點
當前提交
f0a8dc12e6
共有 3 個文件被更改,包括 41 次插入7 次删除
  1. 3 4
      geodns.go
  2. 3 3
      monitor.go
  3. 35 0
      monitor_test.go

+ 3 - 4
geodns.go

@@ -133,14 +133,13 @@ func main() {
 
 
 	inter := getInterfaces()
 	inter := getInterfaces()
 
 
-	go monitor()
-
-	dirName := *flagconfig
-
 	Zones := make(Zones)
 	Zones := make(Zones)
 
 
+	go monitor(Zones)
+
 	setupPgeodnsZone(Zones)
 	setupPgeodnsZone(Zones)
 
 
+	dirName := *flagconfig
 	go zonesReader(dirName, Zones)
 	go zonesReader(dirName, Zones)
 
 
 	for _, host := range inter {
 	for _, host := range inter {

+ 3 - 3
monitor.go

@@ -149,14 +149,14 @@ func logStatus() {
 	}
 	}
 }
 }
 
 
-func monitor() {
+func monitor(zones Zones) {
 	go logStatus()
 	go logStatus()
 
 
 	if len(*flaghttp) == 0 {
 	if len(*flaghttp) == 0 {
 		return
 		return
 	}
 	}
 	go hub.run()
 	go hub.run()
-	go httpHandler()
+	go httpHandler(zones)
 
 
 	lastQueryCount := expVarToInt64(qCounter)
 	lastQueryCount := expVarToInt64(qCounter)
 
 
@@ -251,7 +251,7 @@ func StatusServer(w http.ResponseWriter, req *http.Request) {
 	io.WriteString(w, `</body></html>`)
 	io.WriteString(w, `</body></html>`)
 }
 }
 
 
-func httpHandler() {
+func httpHandler(zones Zones) {
 	http.Handle("/monitor", websocket.Handler(wsHandler))
 	http.Handle("/monitor", websocket.Handler(wsHandler))
 	http.HandleFunc("/status", StatusServer)
 	http.HandleFunc("/status", StatusServer)
 	http.HandleFunc("/", MainServer)
 	http.HandleFunc("/", MainServer)

+ 35 - 0
monitor_test.go

@@ -0,0 +1,35 @@
+package main
+
+import (
+	"fmt"
+	"io/ioutil"
+	. "launchpad.net/gocheck"
+	"net/http"
+	"time"
+)
+
+type MonitorSuite struct {
+	zones Zones
+}
+
+var _ = Suite(&MonitorSuite{})
+
+func (s *MonitorSuite) SetUpSuite(c *C) {
+	s.zones = make(Zones)
+
+	fmt.Println("Starting http server")
+
+	zonesReadDir("dns", s.zones)
+	go httpHandler(s.zones)
+	time.Sleep(500 * time.Millisecond)
+}
+
+func (s *MonitorSuite) TestMonitorVersion(c *C) {
+	c.Check(true, DeepEquals, true)
+
+	res, err := http.Get("http://localhost:8053/version")
+	c.Assert(err, IsNil)
+	page, _ := ioutil.ReadAll(res.Body)
+	c.Check(string(page), Matches, ".*<title>GeoDNS [0-9].*")
+
+}