-
Notifications
You must be signed in to change notification settings - Fork 193
/
http_test.go
45 lines (35 loc) · 891 Bytes
/
http_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
package main
import (
"bytes"
"io"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/require"
"github.com/abh/geodns/v3/targeting"
"github.com/abh/geodns/v3/targeting/geoip2"
"github.com/abh/geodns/v3/zones"
)
func TestHTTP(t *testing.T) {
geoprovider, err := geoip2.New(geoip2.FindDB())
if err == nil {
targeting.Setup(geoprovider)
}
mm, err := zones.NewMuxManager("dns", &zones.NilReg{})
if err != nil {
t.Fatalf("loading zones: %s", err)
}
hs := NewHTTPServer(mm, serverInfo)
srv := httptest.NewServer(hs.Mux())
baseurl := srv.URL
t.Logf("server base url: '%s'", baseurl)
// metrics := NewMetrics()
// go metrics.Updater()
res, err := http.Get(baseurl + "/version")
require.Nil(t, err)
page, _ := io.ReadAll(res.Body)
if !bytes.HasPrefix(page, []byte("GeoDNS ")) {
t.Log("/version didn't start with 'GeoDNS '")
t.Fail()
}
}