Skip to content

Commit

Permalink
fix test case TestProxy_reloadHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
xiantang committed Jan 19, 2025
1 parent 2e44c58 commit 80206aa
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions runner/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,14 @@ func TestProxy_reloadHandler(t *testing.T) {
proxy.reloadHandler(rec, req)
}()

// wait for subscriber to be added
// 等待订阅者被添加
<-reloader.subCh

// send a reload event and wait for http response
reloader.reloadCh <- StreamMessage{Type: StreamMessageReload}
// 发送一个 reload 事件并等待 http 响应
reloader.reloadCh <- StreamMessage{
Type: StreamMessageReload,
Data: nil,
}
close(reloader.reloadCh)
wg.Wait()

Expand All @@ -273,7 +276,24 @@ func TestProxy_reloadHandler(t *testing.T) {
if err != nil {
t.Errorf("reading body: %v", err)
}
if got, exp := string(bodyBytes), "data: reload\n\n"; got != exp {
t.Errorf("expected %q but got %q", exp, got)

// 更新期望的格式以匹配新的 SSE 消息结构
expected := "event: reload\ndata: null\n\n"
if got := string(bodyBytes); got != expected {
t.Errorf("expected %q but got %q", expected, got)
}

// 验证响应头
expectedHeaders := map[string]string{
"Access-Control-Allow-Origin": "*",
"Content-Type": "text/event-stream",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
}

for key, value := range expectedHeaders {
if got := resp.Header.Get(key); got != value {
t.Errorf("expected header %s to be %q but got %q", key, value, got)
}
}
}

0 comments on commit 80206aa

Please sign in to comment.