package main import ( "context" "encoding/json" "net/http" "net/http/httptest" "testing" "chis_osi/config" ) func TestRunJKDAFindCheckUsesConfiguredOSIClient(t *testing.T) { var seenPayload map[string]any server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/osi/api/auto/jkda/find" { t.Fatalf("path = %q", r.URL.Path) } if r.Header.Get("userName") != "dyytgw" { t.Fatalf("userName = %q", r.Header.Get("userName")) } if err := json.NewDecoder(r.Body).Decode(&seenPayload); err != nil { t.Fatalf("decode request: %v", err) } _, _ = w.Write([]byte(`{"code":"01","message":"操作成功","data":[{"healthRecord":{"phrId":"phr-001"}}]}`)) })) defer server.Close() cfg := config.Config{OSI: config.OSIConfig{ BaseURL: server.URL, OrgCode: "12441625456962881G", UserName: "dyytgw", Ask: "secret-key", OperateUser: "712041", TimeoutSec: 5, }} result, err := runJKDAFindCheck(context.Background(), cfg, "440100199001011234") if err != nil { t.Fatalf("runJKDAFindCheck: %v", err) } if result.Code != "01" || result.Message != "操作成功" || result.DataCount != 1 { t.Fatalf("result = %#v", result) } uploadInfo := seenPayload["uploadinfo"].(map[string]any) baseInfo := uploadInfo["baseInfo"].(map[string]any) if baseInfo["idCard"] != "440100199001011234" { t.Fatalf("baseInfo = %#v", baseInfo) } }