test improvements and some refactor
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
package testhelpers
|
||||
|
||||
import (
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func CheckSlicesEquality(a []any, b []any) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
@@ -31,3 +36,29 @@ func StringSliceToAnySlice(s []string) []any {
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
type ExpectedResponse struct {
|
||||
Code int
|
||||
Header string
|
||||
Body string
|
||||
}
|
||||
|
||||
func VerifyResponse(t *testing.T, rr *httptest.ResponseRecorder, expectedResponse ExpectedResponse) {
|
||||
t.Helper()
|
||||
|
||||
expectedCode := expectedResponse.Code
|
||||
expectedHeader := expectedResponse.Header
|
||||
expectedBody := expectedResponse.Body
|
||||
|
||||
if status := rr.Code; status != expectedCode {
|
||||
t.Errorf("Expected status code: %d, Actual: %d", expectedCode, status)
|
||||
}
|
||||
|
||||
if header := rr.Header().Get("Content-Type"); header != expectedHeader {
|
||||
t.Errorf("Expected Content-Type: %s, Actual: %s", expectedHeader, header)
|
||||
}
|
||||
|
||||
if body := rr.Body.String(); body != expectedBody {
|
||||
t.Errorf("Expected body: %q, Actual: %q", expectedBody, body)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user