@@ -158,13 +158,10 @@ func TestService_handlePostAuthorization(t *testing.T) {
158158 router .Mount (handler .Prefix (), handler )
159159
160160 req , err := newPostAuthorizationRequest (tt .args .authorization )
161- if err != nil {
162- t .Fatalf ("failed to create new authorization request: %v" , err )
163- }
161+ require .NoError (t , err )
162+
164163 b , err := json .Marshal (req )
165- if err != nil {
166- t .Fatalf ("failed to unmarshal authorization: %v" , err )
167- }
164+ require .NoError (t , err )
168165
169166 r := httptest .NewRequest ("GET" , "http://any.url" , bytes .NewReader (b ))
170167 r = r .WithContext (context .WithValue (
@@ -185,21 +182,16 @@ func TestService_handlePostAuthorization(t *testing.T) {
185182 handler .handlePostAuthorization (w , r )
186183
187184 res := w .Result ()
188- content := res .Header .Get ("Content-Type" )
185+ contentType := res .Header .Get ("Content-Type" )
189186 body , _ := io .ReadAll (res .Body )
190187
191- if res .StatusCode != tt .wants .statusCode {
192- t .Logf ("headers: %v body: %s" , res .Header , body )
193- t .Errorf ("%q. handlePostAuthorization() = %v, want %v" , tt .name , res .StatusCode , tt .wants .statusCode )
194- }
195- if tt .wants .contentType != "" && content != tt .wants .contentType {
196- t .Errorf ("%q. handlePostAuthorization() = %v, want %v" , tt .name , content , tt .wants .contentType )
197- }
198- if diff , err := jsonDiff (string (body ), tt .wants .body ); diff != "" {
199- t .Errorf ("%q. handlePostAuthorization() = ***%s***" , tt .name , diff )
200- } else if err != nil {
201- t .Errorf ("%q, handlePostAuthorization() error: %v" , tt .name , err )
188+ require .Equalf (t , tt .wants .statusCode , res .StatusCode , "headers: %v body: %s" , res .Header , body )
189+ if tt .wants .contentType != "" {
190+ require .Equal (t , tt .wants .contentType , contentType )
202191 }
192+ diff , err := jsonDiff (string (body ), tt .wants .body )
193+ require .NoError (t , err )
194+ require .Empty (t , diff )
203195 })
204196 }
205197 }
@@ -353,21 +345,16 @@ func TestService_handleGetAuthorization(t *testing.T) {
353345 handler .handleGetAuthorization (w , r )
354346
355347 res := w .Result ()
356- content := res .Header .Get ("Content-Type" )
348+ contentType := res .Header .Get ("Content-Type" )
357349 body , _ := io .ReadAll (res .Body )
358350
359- if res .StatusCode != tt .wants .statusCode {
360- t .Logf ("headers: %v body: %s" , res .Header , body )
361- t .Errorf ("%q. handleGetAuthorization() = %v, want %v" , tt .name , res .StatusCode , tt .wants .statusCode )
362- }
363- if tt .wants .contentType != "" && content != tt .wants .contentType {
364- t .Errorf ("%q. handleGetAuthorization() = %v, want %v" , tt .name , content , tt .wants .contentType )
365- }
366- if diff , err := jsonDiff (string (body ), tt .wants .body ); err != nil {
367- t .Errorf ("%q, handleGetAuthorization. error unmarshalling json %v" , tt .name , err )
368- } else if tt .wants .body != "" && diff != "" {
369- t .Errorf ("%q. handleGetAuthorization() = -got/+want %s**" , tt .name , diff )
351+ require .Equalf (t , tt .wants .statusCode , res .StatusCode , "headers: %v body: %s" , res .Header , body )
352+ if tt .wants .contentType != "" {
353+ require .Equal (t , tt .wants .contentType , contentType )
370354 }
355+ diff , err := jsonDiff (string (body ), tt .wants .body )
356+ require .NoError (t , err )
357+ require .Empty (t , diff )
371358 })
372359 }
373360}
@@ -719,9 +706,7 @@ func TestService_handleGetAuthorizations(t *testing.T) {
719706 s := itesting .NewTestInmemStore (t )
720707
721708 storage , err := NewStore (context .Background (), s , useHashedTokens )
722- if err != nil {
723- t .Fatal (err )
724- }
709+ require .NoError (t , err )
725710
726711 svc := NewService (storage , tt .fields .TenantService )
727712
@@ -744,21 +729,16 @@ func TestService_handleGetAuthorizations(t *testing.T) {
744729 handler .handleGetAuthorizations (w , r )
745730
746731 res := w .Result ()
747- content := res .Header .Get ("Content-Type" )
732+ contentType := res .Header .Get ("Content-Type" )
748733 body , _ := io .ReadAll (res .Body )
749734
750- if res .StatusCode != tt .wants .statusCode {
751- t .Errorf ("%q. handleGetAuthorizations() = %v, want %v" , tt .name , res .StatusCode , tt .wants .statusCode )
752- }
753- if tt .wants .contentType != "" && content != tt .wants .contentType {
754- t .Errorf ("%q. handleGetAuthorizations() = %v, want %v" , tt .name , content , tt .wants .contentType )
735+ require .Equal (t , tt .wants .statusCode , res .StatusCode )
736+ if tt .wants .contentType != "" {
737+ require .Equal (t , tt .wants .contentType , contentType )
755738 }
756- if diff , err := jsonDiff (string (body ), tt .wants .body ); diff != "" {
757- t .Errorf ("%q. handleGetAuthorizations() = ***%s***" , tt .name , diff )
758- } else if err != nil {
759- t .Errorf ("%q, handleGetAuthorizations() error: %v" , tt .name , err )
760- }
761-
739+ diff , err := jsonDiff (string (body ), tt .wants .body )
740+ require .NoError (t , err )
741+ require .Empty (t , diff )
762742 })
763743 }
764744 }
@@ -846,22 +826,18 @@ func TestService_handleDeleteAuthorization(t *testing.T) {
846826 handler .handleDeleteAuthorization (w , r )
847827
848828 res := w .Result ()
849- content := res .Header .Get ("Content-Type" )
829+ contentType := res .Header .Get ("Content-Type" )
850830 body , _ := io .ReadAll (res .Body )
851831
852- if res .StatusCode != tt .wants .statusCode {
853- t .Errorf ("%q. handleDeleteAuthorization() = %v, want %v" , tt .name , res .StatusCode , tt .wants .statusCode )
854- }
855- if tt .wants .contentType != "" && content != tt .wants .contentType {
856- t .Errorf ("%q. handleDeleteAuthorization() = %v, want %v" , tt .name , content , tt .wants .contentType )
832+ require .Equal (t , tt .wants .statusCode , res .StatusCode )
833+ if tt .wants .contentType != "" {
834+ require .Equal (t , tt .wants .contentType , contentType )
857835 }
858836
859837 if tt .wants .body != "" {
860- if diff , err := jsonDiff (string (body ), tt .wants .body ); err != nil {
861- t .Errorf ("%q, handleDeleteAuthorization(). error unmarshalling json %v" , tt .name , err )
862- } else if diff != "" {
863- t .Errorf ("%q. handleDeleteAuthorization() = ***%s***" , tt .name , diff )
864- }
838+ diff , err := jsonDiff (string (body ), tt .wants .body )
839+ require .NoError (t , err )
840+ require .Empty (t , diff )
865841 }
866842 })
867843 }
0 commit comments