-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_test.go
42 lines (39 loc) · 899 Bytes
/
main_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
package main
import (
"fmt"
"github.com/miekg/dns"
"net/http"
"testing"
"time"
)
func TestMain(m *testing.M) {
go main()
time.Sleep(3 * time.Second)
_ = m.Run()
}
func TestDNS(t *testing.T) {
t.Run("req", func(t *testing.T) {
ns := "localhost:53"
c := dns.Client{}
m := dns.Msg{}
m.SetQuestion("dnslogger.local.", dns.TypeA)
r, _, err := c.Exchange(&m, ns)
checkErr(err)
for _, ans := range r.Answer {
if ans.(*dns.A).A.String() != config.ReturnIP {
t.Errorf("DNS解析错误.\n")
}
}
})
ApiBase := fmt.Sprintf("http://%s", config.ListenHttp)
t.Run("queryLatest", func(t *testing.T) {
reqest, err := http.NewRequest("GET", fmt.Sprintf("%s/api/latest", ApiBase), nil)
if err != nil {
panic(err)
}
response, _ := (&http.Client{}).Do(reqest)
if response.StatusCode != 200 {
t.Errorf("API status code异常. %d\n", response.StatusCode)
}
})
}