mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 04:30:05 +00:00
update: 增加更多占位符与单元测试
This commit is contained in:
@@ -37,14 +37,43 @@ func execCase(t *testing.T, item testSt) {
|
||||
RequestHeader: item.header,
|
||||
}
|
||||
server := Server{
|
||||
Common: Common{},
|
||||
Name: "ServerName",
|
||||
Tag: "",
|
||||
Secret: "",
|
||||
Note: "",
|
||||
DisplayIndex: 0,
|
||||
Host: nil,
|
||||
State: nil,
|
||||
Common: Common{},
|
||||
Name: "ServerName",
|
||||
Tag: "",
|
||||
Secret: "",
|
||||
Note: "",
|
||||
DisplayIndex: 0,
|
||||
Host: &Host{
|
||||
Platform: "",
|
||||
PlatformVersion: "",
|
||||
CPU: nil,
|
||||
MemTotal: 0,
|
||||
DiskTotal: 0,
|
||||
SwapTotal: 0,
|
||||
Arch: "",
|
||||
Virtualization: "",
|
||||
BootTime: 0,
|
||||
IP: "1.1.1.1",
|
||||
CountryCode: "",
|
||||
Version: "",
|
||||
},
|
||||
State: &HostState{
|
||||
CPU: 0,
|
||||
MemUsed: 0,
|
||||
SwapUsed: 8888,
|
||||
DiskUsed: 0,
|
||||
NetInTransfer: 0,
|
||||
NetOutTransfer: 0,
|
||||
NetInSpeed: 0,
|
||||
NetOutSpeed: 0,
|
||||
Uptime: 0,
|
||||
Load1: 0,
|
||||
Load5: 0,
|
||||
Load15: 0,
|
||||
TcpConnCount: 0,
|
||||
UdpConnCount: 0,
|
||||
ProcessCount: 0,
|
||||
},
|
||||
LastActive: time.Time{},
|
||||
TaskClose: nil,
|
||||
TaskStream: nil,
|
||||
@@ -139,16 +168,26 @@ func TestNotification(t *testing.T) {
|
||||
},
|
||||
{
|
||||
url: "https://example.com/?m=#NEZHA#",
|
||||
body: `{"Server":"#SERVER#"}`,
|
||||
body: `{"Server":"#SERVER.NAME#","ServerIP":"#SERVER.IP#","ServerSWAP":#SERVER.SWAP#}`,
|
||||
reqMethod: NotificationRequestMethodPOST,
|
||||
header: `{"asd":"dsa11"}`,
|
||||
reqType: NotificationRequestTypeJSON,
|
||||
expectURL: "https://example.com/?m=" + msg,
|
||||
expectMethod: http.MethodPost,
|
||||
expectContentType: reqTypeJSON,
|
||||
expectBody: `{"Server":"ServerName"}`,
|
||||
expectBody: `{"Server":"ServerName","ServerIP":"1.1.1.1","ServerSWAP":8888}`,
|
||||
expectHeader: map[string]string{"asd": "dsa11"},
|
||||
},
|
||||
{
|
||||
url: "https://example.com/?m=#NEZHA#",
|
||||
body: `{"#NEZHA#":"#NEZHA#","Server":"#SERVER.NAME#","ServerIP":"#SERVER.IP#","ServerSWAP":"#SERVER.SWAP#"}`,
|
||||
reqMethod: NotificationRequestMethodPOST,
|
||||
reqType: NotificationRequestTypeForm,
|
||||
expectURL: "https://example.com/?m=" + msg,
|
||||
expectMethod: http.MethodPost,
|
||||
expectContentType: reqTypeForm,
|
||||
expectBody: "%23NEZHA%23=" + msg + "&Server=ServerName&ServerIP=1.1.1.1&ServerSWAP=8888",
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
|
||||
Reference in New Issue
Block a user