I refactored some of the proxy-go code to use an http.RoundTripper to communicate with the broker. I think it looks a bit cleaner this way in addition to making tests easier.
Looks good so far. The http.RoundTripper makes sense. RoundTrip is slightly different than Do in that it doesn't follow redirects, but I think we want RoundTrip behavior anyway.
I rebased these tests after merging #28942 (moved), but I'm going to put this on hold until we merge #29207 (moved) since that makes significant changes to how the proxies communicate with the broker and will therefore require further changes to the tests.
I modified the proxy-go code a bit in this commit to use an http.RoundTripper as discussed above.
The test coverage is now at 37.2% (up from 2.2%). I don't think the rest of the code makes sense to write tests for in its current form since that would require some larger refactors.
Looks good, thanks. I would suggest moving SDP, sampleSDP, sampleOffer, and sampleAnswer inside TestBrokerInteractions where they are used.
Incidentally, the new tests reveal that some functions are probably logging at too low a level -- I normally wouldn't expect the kind of code dealt with in unit tests to log.
2019/11/09 13:53:45 invalid character 'e' in literal true (expecting 'r').2019/11/09 13:53:45 Cannot deserialize SessionDescription without sdp field..2019/11/09 13:53:45 Cannot deserialize SessionDescription without type field..2019/11/09 13:53:45 Unknown SDP type...2019/11/09 13:53:45 io.Copy inside CopyLoop generated an error: io: read/write on closed pipe2019/11/09 13:53:45 io.Copy inside CopyLoop generated an error: io: read/write on closed pipe
Incidentally, the new tests reveal that some functions are probably logging at too low a level -- I normally wouldn't expect the kind of code dealt with in unit tests to log.
{{{
2019/11/09 13:53:45 invalid character 'e' in literal true (expecting 'r')
.2019/11/09 13:53:45 Cannot deserialize SessionDescription without sdp field.
.2019/11/09 13:53:45 Cannot deserialize SessionDescription without type field.
.2019/11/09 13:53:45 Unknown SDP type
...2019/11/09 13:53:45 io.Copy inside CopyLoop generated an error: io: read/write on closed pipe
2019/11/09 13:53:45 io.Copy inside CopyLoop generated an error: io: read/write on closed pipe
}}}
I agree, I think we should not be logging errors generated by CopyLoop since one loop will always close the pipe and trigger an error in the other loop. I'll make a new ticket for this since there are some errors being logged in the broker after #29207 (moved) that are too much at the moment.