fix(tests): improve error handling in unit tests and Makefile

- Enhanced the Makefile to include additional checks for test failures, specifically for panic messages and general failure indicators.
- Updated service tests to dynamically retrieve the server port, ensuring accurate request routing.
- Added a clear function call in the dashboard process test setup to ensure a clean state before tests run.
This commit is contained in:
Max 2026-04-06 17:17:11 +08:00
parent 5c1664e882
commit 15a71692a2
3 changed files with 26 additions and 4 deletions

View file

@ -41,6 +41,12 @@ unit-test:
if grep -q "^--- FAIL" tmp.out; then \
rm tmp.out; \
exit 1; \
elif grep -q "^FAIL" tmp.out; then \
rm tmp.out; \
exit 1; \
elif grep -q "^panic:" tmp.out; then \
rm tmp.out; \
exit 1; \
elif grep -q "build failed" tmp.out; then \
rm tmp.out; \
exit 1; \
@ -67,6 +73,12 @@ unit-test-core:
if grep -q "^--- FAIL" tmp.out; then \
rm tmp.out; \
exit 1; \
elif grep -q "^FAIL" tmp.out; then \
rm tmp.out; \
exit 1; \
elif grep -q "^panic:" tmp.out; then \
rm tmp.out; \
exit 1; \
elif grep -q "build failed" tmp.out; then \
rm tmp.out; \
exit 1; \
@ -359,6 +371,12 @@ unit-test-grpc:
if grep -q "^--- FAIL" tmp.out; then \
rm tmp.out; \
exit 1; \
elif grep -q "^FAIL" tmp.out; then \
rm tmp.out; \
exit 1; \
elif grep -q "^panic:" tmp.out; then \
rm tmp.out; \
exit 1; \
elif grep -q "build failed" tmp.out; then \
rm tmp.out; \
exit 1; \

View file

@ -33,10 +33,13 @@ func TestStartStop(t *testing.T) {
}
defer srv.Stop()
<-srv.Event()
port, err := srv.http.Port()
if err != nil {
t.Fatal(err)
}
// API Server
req := test.NewRequest(cfg.Port).Route("/api/__yao/app/setting")
req := test.NewRequest(port).Route("/api/__yao/app/setting")
res, err := req.Get()
if err != nil {
t.Fatal(err)
@ -49,7 +52,7 @@ func TestStartStop(t *testing.T) {
assert.True(t, len(data["name"].(string)) > 0)
// Public
req = test.NewRequest(cfg.Port).Route("/")
req = test.NewRequest(port).Route("/")
res, err = req.Get()
if err != nil {
t.Fatal(err)
@ -58,7 +61,7 @@ func TestStartStop(t *testing.T) {
assert.Equal(t, "Hello World\n", res.Body())
// XGEN
req = test.NewRequest(cfg.Port).Route("/admin/")
req = test.NewRequest(port).Route("/admin/")
res, err = req.Get()
if err != nil {
t.Fatal(err)

View file

@ -32,6 +32,7 @@ func TestProcessComponent(t *testing.T) {
test.Prepare(t, config.Conf)
defer test.Clean()
prepare(t)
clear(t)
testData(t)
args := []interface{}{