(t *testing.T, in *json.Decoder, successes chan<- jsonSuccessResponse, failures chan<- jsonErrResponse, notifications chan<- jsonNotification, errors chan<- error)
| 165 | } |
| 166 | |
| 167 | func waitForMessages(t *testing.T, in *json.Decoder, successes chan<- jsonSuccessResponse, |
| 168 | failures chan<- jsonErrResponse, notifications chan<- jsonNotification, errors chan<- error) { |
| 169 | |
| 170 | // read and parse server messages |
| 171 | for { |
| 172 | var rmsg json.RawMessage |
| 173 | if err := in.Decode(&rmsg); err != nil { |
| 174 | return |
| 175 | } |
| 176 | |
| 177 | var responses []map[string]interface{} |
| 178 | if rmsg[0] == '[' { |
| 179 | if err := json.Unmarshal(rmsg, &responses); err != nil { |
| 180 | errors <- fmt.Errorf("Received invalid message: %s", rmsg) |
| 181 | return |
| 182 | } |
| 183 | } else { |
| 184 | var msg map[string]interface{} |
| 185 | if err := json.Unmarshal(rmsg, &msg); err != nil { |
| 186 | errors <- fmt.Errorf("Received invalid message: %s", rmsg) |
| 187 | return |
| 188 | } |
| 189 | responses = append(responses, msg) |
| 190 | } |
| 191 | |
| 192 | for _, msg := range responses { |
| 193 | // determine what kind of msg was received and broadcast |
| 194 | // it to over the corresponding channel |
| 195 | if _, found := msg["result"]; found { |
| 196 | successes <- jsonSuccessResponse{ |
| 197 | Version: msg["jsonrpc"].(string), |
| 198 | Id: msg["id"], |
| 199 | Result: msg["result"], |
| 200 | } |
| 201 | continue |
| 202 | } |
| 203 | if _, found := msg["error"]; found { |
| 204 | params := msg["params"].(map[string]interface{}) |
| 205 | failures <- jsonErrResponse{ |
| 206 | Version: msg["jsonrpc"].(string), |
| 207 | Id: msg["id"], |
| 208 | Error: jsonError{int(params["subscription"].(float64)), params["message"].(string), params["data"]}, |
| 209 | } |
| 210 | continue |
| 211 | } |
| 212 | if _, found := msg["params"]; found { |
| 213 | params := msg["params"].(map[string]interface{}) |
| 214 | notifications <- jsonNotification{ |
| 215 | Version: msg["jsonrpc"].(string), |
| 216 | Method: msg["method"].(string), |
| 217 | Params: jsonSubscription{params["subscription"].(string), params["result"]}, |
| 218 | } |
| 219 | continue |
| 220 | } |
| 221 | errors <- fmt.Errorf("Received invalid message: %s", msg) |
| 222 | } |
| 223 | } |
| 224 | } |
no outgoing calls
no test coverage detected