Files
lingniu-vehicle-ingest/vehicle-data-platform/apps/api/internal/gzev/serverchan_test.go
T
lingniu d6b957dfc8 feat: sync vehicle monitoring and accumulated platform updates
Add monitoring metrics, numeric sorting, report-time display, vehicle number labels, and map layout fixes. Include accumulated mileage, hydrogen, OneOS authentication, open platform, ingestion, deployment, and UI updates.

Exclude temporary files, generated reports, and credentials. Validate frontend 632 tests and production build, API packages, vehicle-map tests, and release installer tests. Gateway suite has one pre-existing date-sensitive identity throttling test failure reproduced on the parent commit.
2026-10-26 18:05:59 +08:00

60 lines
2.4 KiB
Go

package gzev
import (
"context"
"io"
"net/http"
"net/url"
"path/filepath"
"strings"
"testing"
)
func TestServerChanPushAndAcceptance(t *testing.T) {
for _, response := range []string{`{"code":0,"data":{"errno":0}}`, `{"code":40001}`, `{}`, `{"code":0,"data":{"errno":1}}`} {
t.Run(response, func(t *testing.T) {
calls := 0
s := ServerChan{SendKey: "SCTtest12345678", SessionPath: filepath.Join(t.TempDir(), "session.json"), UploadURL: "https://vehicle.d.lnoneos.com/gzev/session/"}
s.HTTP = &http.Client{Transport: roundTripFunc(func(r *http.Request) (*http.Response, error) {
calls++
if r.Method != "POST" || r.URL.Host != "sctapi.ftqq.com" || r.URL.Path != "/SCTtest12345678.send" {
t.Fatal("wrong endpoint")
}
b, _ := io.ReadAll(r.Body)
form, _ := url.ParseQuery(string(b))
if form.Get("title") != "广州里程采集登录失效" || !strings.Contains(form.Get("desp"), s.UploadURL) || !strings.Contains(form.Get("desp"), "通知恢复码") {
t.Fatal("missing actionable content")
}
return &http.Response{StatusCode: 200, Body: io.NopCloser(strings.NewReader(response)), Header: http.Header{}}, nil
})}
err := s.Send(context.Background())
if (err == nil) != (response == `{"code":0,"data":{"errno":0}}`) || calls != 1 {
t.Fatalf("unexpected acceptance: %v", err)
}
if err != nil && strings.Contains(err.Error(), s.SendKey) {
t.Fatal("key leaked")
}
})
}
}
func TestServerChanMissingKeyDoesNotCreateTicket(t *testing.T) {
s := ServerChan{SessionPath: filepath.Join(t.TempDir(), "session.json")}
if s.Send(context.Background()) == nil {
t.Fatal("unconfigured notification accepted")
}
}
func TestServerChanTestIsClearlyLabeled(t *testing.T) {
s := ServerChan{SendKey: "SCTtest12345678", SessionPath: filepath.Join(t.TempDir(), "session.json"), UploadURL: "https://vehicle.d.lnoneos.com/gzev/session/"}
s.HTTP = &http.Client{Transport: roundTripFunc(func(r *http.Request) (*http.Response, error) {
b, _ := io.ReadAll(r.Body)
f, _ := url.ParseQuery(string(b))
if !strings.Contains(f.Get("title"), "测试") || !strings.Contains(f.Get("desp"), "不表示登录状态已失效") {
t.Fatal("false expiry alert")
}
return &http.Response{StatusCode: 200, Body: io.NopCloser(strings.NewReader(`{"code":0}`)), Header: http.Header{}}, nil
})}
if err := s.SendTest(context.Background()); err != nil {
t.Fatal(err)
}
}