-
Notifications
You must be signed in to change notification settings - Fork 25
/
SnowPearDNS_test.go
126 lines (114 loc) · 3.5 KB
/
SnowPearDNS_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package main
import (
"encoding/json"
"fmt"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func Test_byteString(t *testing.T) {
Convey("byetString_test", t, func() {
var retbyte []byte = []byte("8.8.8.8;3.3.3.3")
t.Logf("start test bytes")
fmt.Printf(byteString(retbyte))
//t.Log(byteString(retbyte))
So(byteString(retbyte), ShouldNotBeBlank)
})
}
func Test_cx(t *testing.T) {
var testres string = "{\"Status\":0,\"TC\":false,\"RD\":true,\"RA\":true,\"AD\":false,\"CD\":false,\"Question\":[{\"name\":\"github.com.\",\"type\":1}],\"Answer\":[{\"name\":\"github.com.\",\"type\":1,\"TTL\":180,\"Expires\":\"Tue, 14 Dec 2021 23:45:41 UTC\",\"data\":\"20.205.243.166\"}],\"edns_client_subnet\":\"116.227.244.37/22\"}"
var cnameres string = "{\"Status\":0,\"TC\":false,\"RD\":true,\"RA\":true,\"AD\":false,\"CD\":false,\"Question\":[{\"name\":\"www.baidu.com.\",\"type\":5}],\"Answer\":[{\"name\":\"www.baidu.com.\",\"type\":5,\"TTL\":1200,\"Expires\":\"Wed, 15 Dec 2021 00:18:23 UTC\",\"data\":\"www.a.shifen.com.\"}],\"edns_client_subnet\":\"116.227.244.37/24\"}"
t.Log(testres)
t.Log(cnameres)
var ans DOH_Response
json.Unmarshal([]byte(testres), &ans)
fmt.Println("here we go")
fmt.Println(ans.Status)
fmt.Println(string(ans.Answer[0].Data))
PrettyPrint(ans)
//fmt.Printf("%+v\n", ans)
/*in := []int{2, 5, 6}
randomIndex := rand.Intn(len(in))
pick := in[randomIndex]
fmt.Println(pick)*/
//https://go.dev/play/p/bVovbZHNGRQ.go?download=true
/*package main
import (
"encoding/json"
"fmt"
)
// The same json tags will be used to encode data into JSON
type Bird struct {
Species string `json:"birdType"`
Description string `json:"what it does"`
}
func main() {
pigeon := &Bird{
Species: "Pigeon",
Description: "likes to eat seed",
}
// we can use the json.Marhal function to
// encode the pigeon variable to a JSON string
data, _ := json.Marshal(pigeon)
// data is the JSON string represented as bytes
// the second parameter here is the error, which we
// are ignoring for now, but which you should ideally handle
// in production grade code
// to print the data, we can typecast it to a string
fmt.Println(string(data))
}*/
}
func PrettyPrint(data interface{}) {
var p []byte
// var err := error
p, err := json.MarshalIndent(data, "", "\t")
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%s \n", p)
}
func Test_get_a(t *testing.T) {
Convey("get_a_test", t, func() {
Convey("get_n_test", func() {
var domain string = "www.github.com"
t.Logf("start test bytes")
//fmt.Printf(string(get_a(domain)))
for _, vl := range get_a(domain) {
fmt.Println(vl)
}
fmt.Println("get_a")
//t.Log(byteString(retbyte))
So(get_a(domain)[0], ShouldNotBeBlank)
})
Convey("mix cnametest", func() {
//hdls3.douyucdn.cn
t.Logf("ah")
var domain string = "hdls3.douyucdn.cn"
//fmt.Println(get_a(domain)[0])
x := get_a(domain)[0]
//fmt.Print()
fmt.Printf("%+v\n", x)
So(x, ShouldNotBeBlank)
})
})
}
func Test_get_cname(t *testing.T) {
Convey("get_cname_test", t, func() {
var domain string = "www.baidu.com"
t.Logf("start test bytes")
//fmt.Printf(string(get_a(domain)))
for _, vl := range get_cname(domain) {
fmt.Println(vl)
}
fmt.Println("get_cname")
//t.Log(byteString(retbyte))
So(get_cname(domain)[0], ShouldNotBeBlank)
})
}
func Test_init_dohip(t *testing.T) {
Convey("dohinit_test", t, func() {
//fmt.Printf(string(get_a(domain)))
//t.Log(byteString(retbyte))
So(init_dohip(), ShouldBeTrue)
})
}