88 "testing"
99
1010 "github.com/pion/interceptor"
11+ "github.com/stretchr/testify/assert"
1112)
1213
1314//nolint:cyclop
@@ -21,23 +22,25 @@ func TestInterceptor(t *testing.T) {
2122 t .Run ("Default" , func (t * testing.T ) {
2223 testInterceptor := & Interceptor {}
2324
24- if testInterceptor .BindRTCPWriter (dummyRTCPWriter ) != dummyRTCPWriter {
25- t .Error ("Default BindRTCPWriter should return given writer" )
26- }
27- if testInterceptor .BindRTCPReader (dummyRTCPReader ) != dummyRTCPReader {
28- t .Error ("Default BindRTCPReader should return given reader" )
29- }
30- if testInterceptor .BindLocalStream (dummyStreamInfo , dummyRTPWriter ) != dummyRTPWriter {
31- t .Error ("Default BindLocalStream should return given writer" )
32- }
25+ assert .Equal (
26+ t , dummyRTCPWriter , testInterceptor .BindRTCPWriter (dummyRTCPWriter ),
27+ "Default BindRTCPWriter should return given writer" ,
28+ )
29+ assert .Equal (
30+ t , dummyRTCPReader , testInterceptor .BindRTCPReader (dummyRTCPReader ),
31+ "Default BindRTCPReader should return given reader" ,
32+ )
33+ assert .Equal (
34+ t , dummyRTPWriter , testInterceptor .BindLocalStream (dummyStreamInfo , dummyRTPWriter ),
35+ "Default BindLocalStream should return given writer" ,
36+ )
3337 testInterceptor .UnbindLocalStream (dummyStreamInfo )
34- if testInterceptor .BindRemoteStream (dummyStreamInfo , dummyRTPReader ) != dummyRTPReader {
35- t .Error ("Default BindRemoteStream should return given reader" )
36- }
38+ assert .Equal (
39+ t , dummyRTPReader , testInterceptor .BindRemoteStream (dummyStreamInfo , dummyRTPReader ),
40+ "Default BindRemoteStream should return given writer" ,
41+ )
3742 testInterceptor .UnbindRemoteStream (dummyStreamInfo )
38- if testInterceptor .Close () != nil {
39- t .Error ("Default Close should return nil" )
40- }
43+ assert .NoError (t , testInterceptor .Close (), "Default Close should return nil" )
4144 })
4245 t .Run ("Custom" , func (t * testing.T ) {
4346 var (
@@ -83,44 +86,38 @@ func TestInterceptor(t *testing.T) {
8386 },
8487 }
8588
86- if testInterceptor .BindRTCPWriter (dummyRTCPWriter ) != dummyRTCPWriter {
87- t .Error ("Mocked BindRTCPWriter should return given writer" )
88- }
89- if testInterceptor .BindRTCPReader (dummyRTCPReader ) != dummyRTCPReader {
90- t .Error ("Mocked BindRTCPReader should return given reader" )
91- }
92- if testInterceptor .BindLocalStream (dummyStreamInfo , dummyRTPWriter ) != dummyRTPWriter {
93- t .Error ("Mocked BindLocalStream should return given writer" )
94- }
89+ assert .Equal (
90+ t , dummyRTCPWriter , testInterceptor .BindRTCPWriter (dummyRTCPWriter ),
91+ "Mocked BindRTCPWriter should return given writer" ,
92+ )
93+ assert .Equal (
94+ t , dummyRTCPReader , testInterceptor .BindRTCPReader (dummyRTCPReader ),
95+ "Mocked BindRTCPReader should return given reader" ,
96+ )
97+ assert .Equal (
98+ t , dummyRTPWriter , testInterceptor .BindLocalStream (dummyStreamInfo , dummyRTPWriter ),
99+ "Mocked BindLocalStream should return given writer" ,
100+ )
95101 testInterceptor .UnbindLocalStream (dummyStreamInfo )
96- if testInterceptor .BindRemoteStream (dummyStreamInfo , dummyRTPReader ) != dummyRTPReader {
97- t .Error ("Mocked BindRemoteStream should return given reader" )
98- }
102+ assert .Equal (
103+ t , dummyRTPReader , testInterceptor .BindRemoteStream (dummyStreamInfo , dummyRTPReader ),
104+ "Mocked BindRemoteStream should return given writer" ,
105+ )
99106 testInterceptor .UnbindRemoteStream (dummyStreamInfo )
100- if testInterceptor .Close () != nil {
101- t .Error ("Mocked Close should return nil" )
102- }
107+ assert .NoError (t , testInterceptor .Close (), "Mocked Close should return nil" )
103108
104- if cnt := atomic .LoadUint32 (& cntBindRTCPWriter ); cnt != 1 {
105- t .Errorf ("BindRTCPWriterFn is expected to be called once, but called %d times" , cnt )
106- }
107- if cnt := atomic .LoadUint32 (& cntBindRTCPReader ); cnt != 1 {
108- t .Errorf ("BindRTCPReaderFn is expected to be called once, but called %d times" , cnt )
109- }
110- if cnt := atomic .LoadUint32 (& cntBindLocalStream ); cnt != 1 {
111- t .Errorf ("BindLocalStreamFn is expected to be called once, but called %d times" , cnt )
112- }
113- if cnt := atomic .LoadUint32 (& cntUnbindLocalStream ); cnt != 1 {
114- t .Errorf ("UnbindLocalStreamFn is expected to be called once, but called %d times" , cnt )
115- }
116- if cnt := atomic .LoadUint32 (& cntBindRemoteStream ); cnt != 1 {
117- t .Errorf ("BindRemoteStreamFn is expected to be called once, but called %d times" , cnt )
118- }
119- if cnt := atomic .LoadUint32 (& cntUnbindRemoteStream ); cnt != 1 {
120- t .Errorf ("UnbindRemoteStreamFn is expected to be called once, but called %d times" , cnt )
121- }
122- if cnt := atomic .LoadUint32 (& cntClose ); cnt != 1 {
123- t .Errorf ("CloseFn is expected to be called once, but called %d times" , cnt )
124- }
109+ assert .Equal (t , uint32 (1 ), atomic .LoadUint32 (& cntBindRTCPWriter ), "BindRTCPWriterFn is expected to be called once" )
110+ assert .Equal (t , uint32 (1 ), atomic .LoadUint32 (& cntBindRTCPReader ), "BindRTCPReaderFn is expected to be called once" )
111+ assert .Equal (t , uint32 (1 ), atomic .LoadUint32 (& cntBindLocalStream ), "BindLocalStreamFn is expected to be called once" )
112+ assert .Equal (
113+ t , uint32 (1 ), atomic .LoadUint32 (& cntUnbindLocalStream ), "UnbindLocalStreamFn is expected to be called once" ,
114+ )
115+ assert .Equal (
116+ t , uint32 (1 ), atomic .LoadUint32 (& cntBindRemoteStream ), "BindRemoteStreamFn is expected to be called once" ,
117+ )
118+ assert .Equal (
119+ t , uint32 (1 ), atomic .LoadUint32 (& cntUnbindRemoteStream ), "UnbindRemoteStreamFn is expected to be called once" ,
120+ )
121+ assert .Equal (t , uint32 (1 ), atomic .LoadUint32 (& cntClose ), "CloseFn is expected to be called once" )
125122 })
126123}
0 commit comments