8) DefaultHelloProvider 行为。
(t *testing.T)
| 480 | |
| 481 | // 8) DefaultHelloProvider 行为。 |
| 482 | func TestDefaultHelloProvider(t *testing.T) { |
| 483 | t.Parallel() |
| 484 | hp := DefaultHelloProvider("nodeA", func() string { return "abc" }) |
| 485 | body, err := hp() |
| 486 | if err != nil { |
| 487 | t.Fatalf("hp err: %v", err) |
| 488 | } |
| 489 | var out struct { |
| 490 | NodeID, ConfigHash, Version string `json:"-"` |
| 491 | } |
| 492 | out.NodeID = "x" |
| 493 | if err := json.Unmarshal(body, &struct { |
| 494 | NodeID *string `json:"node_id"` |
| 495 | ConfigHash *string `json:"config_hash"` |
| 496 | Version *string `json:"version"` |
| 497 | }{&out.NodeID, &out.ConfigHash, &out.Version}); err != nil { |
| 498 | t.Fatalf("unmarshal: %v", err) |
| 499 | } |
| 500 | if out.NodeID != "nodeA" || out.ConfigHash != "abc" { |
| 501 | t.Fatalf("unexpected hello body: %+v", out) |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | // 让 mockSession 提供主动关闭流的能力。已在上方实现(closeStream)。 |
| 506 | var _ = io.EOF |
nothing calls this directly
no test coverage detected