-
Notifications
You must be signed in to change notification settings - Fork 7
/
main_test.go
84 lines (77 loc) · 2.06 KB
/
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
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
package main
import (
"testing"
)
func TestAppConfig_Validate(t *testing.T) {
config = appConfig{}
if err := config.Validate(); err == nil {
t.Error("empty config should not be passed")
}
if err := config.Validate(); err == nil {
t.Error("dnspodtoken should not empty")
}
config.dnspodId = "1234"
if err := config.Validate(); err == nil {
t.Error("only dnspod should not be passed")
}
config.dnspodToken = "bfc41abad5a9852380ba15a124690ec5"
if err := config.Validate(); err == nil {
t.Error("only dnspodToken should not be passed")
}
config.subDomain = "test"
if err := config.Validate(); err == nil {
t.Error("only dnspodId, domain and subDomain should not be passed")
}
config.recordId = "123456"
if err := config.Validate(); err == nil {
t.Error("only domain,subDomain and recordid should not be passed")
}
config.domain = "example.com"
if err := config.Validate(); err == nil {
t.Error("internal should be required")
}
config.internal = -1
if err := config.Validate(); err == nil {
t.Error("internal should exceed than 5")
}
config.internal = 10
if err := config.Validate(); err != nil {
t.Error("all config values are valid, should pass,get error:", err)
}
}
func TestGetPublicIP(t *testing.T) {
ip, err := GetPublicIP()
if err != nil {
t.Error(err.Error())
return
}
t.Log("public ip:", ip)
}
func TestGetRecord(t *testing.T) {
config.dnspodId = "1234"
config.dnspodToken = "helloworld"
config.domain = "example.com"
config.subDomain = "test"
recordId, ip, err := GetRecord()
if err != nil {
t.Error(err.Error())
return
}
if ip != "127.0.0.1" {
t.Error("ip not equal 127.0.0.1,get:", ip)
}
if recordId != "123456" {
t.Error("recordid not correct,get:", recordId)
}
t.Log("ip:", ip, ",recordid:", recordId)
}
func TestUpdateRecord(t *testing.T) {
config.dnspodId = "1234"
config.dnspodToken = "helloworld"
config.domain = "example.com"
config.subDomain = "test"
config.recordId = "123456"
if err := UpdateRecord(config.recordId, "121.40.31.121"); err != nil {
t.Error("update record fail!error:", err.Error())
}
}