forked from abh/geodns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor_test.go
53 lines (40 loc) · 1.11 KB
/
monitor_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"fmt"
. "github.com/abh/geodns/Godeps/_workspace/src/gopkg.in/check.v1"
"io/ioutil"
"net/http"
"strings"
"time"
)
type MonitorSuite struct {
zones Zones
metrics *ServerMetrics
}
var _ = Suite(&MonitorSuite{})
func (s *MonitorSuite) SetUpSuite(c *C) {
s.zones = make(Zones)
s.metrics = NewMetrics()
go s.metrics.Updater()
*flaghttp = ":8881"
fmt.Println("Starting http server")
// TODO: use httptest
// https://groups.google.com/forum/?fromgroups=#!topic/golang-nuts/Jk785WB7F8I
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:8881/version")
c.Assert(err, IsNil)
page, _ := ioutil.ReadAll(res.Body)
c.Check(string(page), Matches, ".*<title>GeoDNS [0-9].*")
res, err = http.Get("http://localhost:8881/status")
c.Assert(err, IsNil)
page, _ = ioutil.ReadAll(res.Body)
// just check that template basically works
isOk := strings.Contains(string(page), "<html>")
// page has <html>
c.Check(isOk, Equals, true)
}