Tests[CompatAck]

This commit is contained in:
Mike Schwörer 2023-01-17 21:14:42 +01:00
parent 2eb6292733
commit 57231a1406
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
2 changed files with 74 additions and 12 deletions

View File

@ -4,10 +4,14 @@ import (
"context"
"fmt"
"github.com/rs/zerolog/log"
"gogs.mikescher.com/BlackForestBytes/goext/rext"
"gogs.mikescher.com/BlackForestBytes/goext/sq"
"regexp"
"strings"
)
var rexWhitespaceRun = rext.W(regexp.MustCompile("\\s{2,}"))
type DBLogger struct {
Ident string
}
@ -81,12 +85,29 @@ func (l DBLogger) PostExec(txID *uint16, sqlOriginal string, sqlReal string, par
}
func fmtSQLPrint(sql string) string {
if strings.Contains(sql, ";") && len(sql) > 1024 {
return "(...multi...)"
if strings.Contains(strings.TrimRight(sql, ";\r\n\t "), ";") {
str := "(...multi...)"
for _, v := range strings.Split(sql, ";") {
v = strings.ReplaceAll(v, "\r", "")
v = strings.ReplaceAll(v, "\n", " ")
v = strings.TrimRight(v, ";")
v = strings.TrimSpace(v)
v = rexWhitespaceRun.ReplaceAll(v, " ", true)
str += "\n" + " " + v
}
return str
} else {
sql = strings.ReplaceAll(sql, "\r", "")
sql = strings.ReplaceAll(sql, "\n", " ")
sql = rexWhitespaceRun.ReplaceAll(sql, " ", true)
return sql
}
sql = strings.ReplaceAll(sql, "\r", "")
sql = strings.ReplaceAll(sql, "\n", " ")
return sql
}

View File

@ -269,7 +269,7 @@ func TestSendCompatMessageByFormData(t *testing.T) {
r1x := tt.RequestGet[gin.H](t, baseUrl, fmt.Sprintf("/api/expand.php?user_id=%d&user_key=%s&scn_msg_id=%d", userid, userkey, r1scnid))
tt.AssertEqual(t, "success", true, r1x["success"])
tt.AssertEqual(t, "success", "my title 11 & x", (r1x["data"].(map[string]any))["title"])
tt.AssertEqual(t, "title", "my title 11 & x", (r1x["data"].(map[string]any))["title"])
r2 := tt.RequestPost[gin.H](t, baseUrl, "/send.php", tt.FormData{
"user_id": fmt.Sprintf("%d", userid),
@ -287,7 +287,7 @@ func TestSendCompatMessageByFormData(t *testing.T) {
r2x := tt.RequestGet[gin.H](t, baseUrl, fmt.Sprintf("/api/expand.php?user_id=%d&user_key=%s&scn_msg_id=%d", userid, userkey, r2scnid))
tt.AssertEqual(t, "success", true, r2x["success"])
tt.AssertEqual(t, "success", "my title", (r2x["data"].(map[string]any))["title"])
tt.AssertEqual(t, "title", "my title", (r2x["data"].(map[string]any))["title"])
r3 := tt.RequestPost[gin.H](t, baseUrl, "/send.php", tt.FormData{
"user_id": fmt.Sprintf("%d", userid),
@ -331,9 +331,54 @@ func TestCompatInfo(t *testing.T) {
tt.AssertEqual(t, "unack_count", 0, r1["unack_count"])
tt.AssertEqual(t, "user_id", userid, r1["user_id"])
tt.AssertEqual(t, "user_key", userkey, r1["user_key"])
tt.RequestPost[gin.H](t, baseUrl, "/send.php", tt.FormData{
"user_key": userkey,
"user_id": fmt.Sprintf("%d", userid),
"title": tt.ShortLipsum0(1),
})
r2 := tt.RequestGet[gin.H](t, baseUrl, fmt.Sprintf("/api/info.php?user_id=%d&user_key=%s", userid, userkey))
tt.AssertEqual(t, "success", true, r2["success"])
tt.AssertEqual(t, "fcm_token_set", true, r2["fcm_token_set"])
tt.AssertEqual(t, "is_pro", 0, r2["is_pro"])
tt.AssertEqual(t, "message", "ok", r2["message"])
tt.AssertEqual(t, "quota", 1, r2["quota"])
tt.AssertEqual(t, "quota_max", 50, r2["quota_max"])
tt.AssertEqual(t, "unack_count", 0, r2["unack_count"])
tt.AssertEqual(t, "user_id", userid, r2["user_id"])
tt.AssertEqual(t, "user_key", userkey, r2["user_key"])
}
func TestCompatAck(t *testing.T) {
_, baseUrl, stop := tt.StartSimpleWebserver(t)
defer stop()
r0 := tt.RequestGet[gin.H](t, baseUrl, fmt.Sprintf("/api/register.php?fcm_token=%s&pro=%s&pro_token=%s", "DUMMY_FCM", "0", ""))
tt.AssertEqual(t, "success", true, r0["success"])
userid := int64(r0["user_id"].(float64))
userkey := r0["user_key"].(string)
r1 := tt.RequestPost[gin.H](t, baseUrl, "/send.php", tt.FormData{
"user_id": fmt.Sprintf("%d", userid),
"user_key": userkey,
"title": "my title 11 & x",
})
tt.AssertEqual(t, "success", true, r1["success"])
r1scnid := int64(r1["scn_msg_id"].(float64))
ack := tt.RequestGet[gin.H](t, baseUrl, fmt.Sprintf("/api/ack.php?user_id=%d&user_key=%s&scn_msg_id=%d", userid, userkey, r1scnid))
tt.AssertEqual(t, "success", true, ack["success"])
tt.AssertEqual(t, "prev_ack", 0, ack["prev_ack"])
tt.AssertEqual(t, "new_ack", 1, ack["new_ack"])
tt.AssertEqual(t, "message", "ok", ack["message"])
}
func TestCompatExpand(t *testing.T) {
t.SkipNow() //TODO
}
@ -345,10 +390,6 @@ func TestCompatUpdate(t *testing.T) {
t.SkipNow() //TODO
}
func TestCompatExpand(t *testing.T) {
t.SkipNow() //TODO
}
func TestCompatUpgrade(t *testing.T) {
t.SkipNow() //TODO
}