sendA2AMessage sends a message/send JSON-RPC request and returns the parsed response.
(t *testing.T, url, requestID, messageID, text string)
| 131 | |
| 132 | // sendA2AMessage sends a message/send JSON-RPC request and returns the parsed response. |
| 133 | func sendA2AMessage(t *testing.T, url, requestID, messageID, text string) a2aResponse { |
| 134 | t.Helper() |
| 135 | |
| 136 | body, err := json.Marshal(map[string]any{ |
| 137 | "jsonrpc": "2.0", |
| 138 | "id": requestID, |
| 139 | "method": "message/send", |
| 140 | "params": map[string]any{ |
| 141 | "message": map[string]any{ |
| 142 | "messageId": messageID, |
| 143 | "role": "user", |
| 144 | "parts": []map[string]any{{"kind": "text", "text": text}}, |
| 145 | }, |
| 146 | }, |
| 147 | }) |
| 148 | require.NoError(t, err) |
| 149 | |
| 150 | req, err := http.NewRequestWithContext(t.Context(), http.MethodPost, url, bytes.NewReader(body)) |
| 151 | require.NoError(t, err) |
| 152 | req.Header.Set("Content-Type", "application/json") |
| 153 | |
| 154 | resp, err := http.DefaultClient.Do(req) |
| 155 | require.NoError(t, err) |
| 156 | defer resp.Body.Close() |
| 157 | |
| 158 | require.Equal(t, http.StatusOK, resp.StatusCode) |
| 159 | |
| 160 | data, err := io.ReadAll(resp.Body) |
| 161 | require.NoError(t, err) |
| 162 | |
| 163 | var parsed a2aResponse |
| 164 | require.NoError(t, json.Unmarshal(data, &parsed)) |
| 165 | |
| 166 | return parsed |
| 167 | } |
| 168 | |
| 169 | func startA2AServer(t *testing.T, agentFile string, runConfig *config.RuntimeConfig) a2a.AgentCard { |
| 170 | t.Helper() |
no test coverage detected