diff --git a/helper/response_test.go b/helper/response_test.go index ce32f11..bb35459 100644 --- a/helper/response_test.go +++ b/helper/response_test.go @@ -5,6 +5,8 @@ import ( "net/http" "net/http/httptest" "testing" + + sabat "github.com/cespares/response" ) func TestRespondWithError(t *testing.T) { @@ -44,7 +46,7 @@ func TestRespondWithError(t *testing.T) { t.Run(tt.name, func(t *testing.T) { w := httptest.NewRecorder() - RespondWithError(w, tt.statusCode, tt.message) + sabat.RespondWithError(w, tt.statusCode, tt.message) resp := w.Result() defer resp.Body.Close() @@ -92,7 +94,7 @@ func TestRespondWithMessage(t *testing.T) { t.Run(tt.name, func(t *testing.T) { w := httptest.NewRecorder() - RespondWithMessage(w, tt.message) + sabat.RespondWithMessage(w, tt.message) resp := w.Result() defer resp.Body.Close() @@ -156,7 +158,7 @@ func TestRespondWithJSON(t *testing.T) { t.Run(tt.name, func(t *testing.T) { w := httptest.NewRecorder() - RespondWithJSON(w, tt.statusCode, tt.data) + sabat.RespondWithJSON(w, tt.statusCode, tt.data) resp := w.Result() defer resp.Body.Close() @@ -211,7 +213,7 @@ func TestRespondWithJSON_StatusCodes(t *testing.T) { w := httptest.NewRecorder() data := map[string]string{"status": http.StatusText(code)} - RespondWithJSON(w, code, data) + sabat.RespondWithJSON(w, code, data) resp := w.Result() defer resp.Body.Close() @@ -226,7 +228,7 @@ func TestRespondWithJSON_StatusCodes(t *testing.T) { func TestRespondWithError_EmptyMessage(t *testing.T) { w := httptest.NewRecorder() - RespondWithError(w, http.StatusBadRequest, "") + sabat.RespondWithError(w, http.StatusBadRequest, "") resp := w.Result() defer resp.Body.Close() @@ -244,7 +246,7 @@ func TestRespondWithError_EmptyMessage(t *testing.T) { func TestRespondWithMessage_EmptyMessage(t *testing.T) { w := httptest.NewRecorder() - RespondWithMessage(w, "") + sabat.RespondWithMessage(w, "") resp := w.Result() defer resp.Body.Close() @@ -262,7 +264,7 @@ func TestRespondWithMessage_EmptyMessage(t *testing.T) { func TestRespondWithJSON_NilData(t *testing.T) { w := httptest.NewRecorder() - RespondWithJSON(w, http.StatusOK, nil) + sabat.RespondWithJSON(w, http.StatusOK, nil) resp := w.Result() defer resp.Body.Close() @@ -286,7 +288,7 @@ func TestRespondWithJSON_NilData(t *testing.T) { func TestRespondWithError_EmptyMessage2(t *testing.T) { w := httptest.NewRecorder() - RespondWithError(w, http.StatusBadRequest, "") + sabat.RespondWithError(w, http.StatusBadRequest, "") resp := w.Result() defer resp.Body.Close() @@ -322,7 +324,7 @@ func TestRespondWithError_SpecialCharacters(t *testing.T) { t.Run(tc.name, func(t *testing.T) { w := httptest.NewRecorder() - RespondWithError(w, http.StatusBadRequest, tc.message) + sabat.RespondWithError(w, http.StatusBadRequest, tc.message) resp := w.Result() defer resp.Body.Close() @@ -342,7 +344,7 @@ func TestRespondWithError_SpecialCharacters(t *testing.T) { func TestRespondWithMessage_EmptyMessage2(t *testing.T) { w := httptest.NewRecorder() - RespondWithMessage(w, "") + sabat.RespondWithMessage(w, "") resp := w.Result() defer resp.Body.Close() @@ -365,7 +367,7 @@ func TestRespondWithMessage_VeryLongMessage(t *testing.T) { longMessage = longMessage[:i] + "a" + longMessage[i+1:] } - RespondWithMessage(w, longMessage) + sabat.RespondWithMessage(w, longMessage) resp := w.Result() defer resp.Body.Close() @@ -397,7 +399,7 @@ func TestRespondWithJSON_ComplexStructure(t *testing.T) { w := httptest.NewRecorder() - RespondWithJSON(w, http.StatusOK, data) + sabat.RespondWithJSON(w, http.StatusOK, data) resp := w.Result() defer resp.Body.Close() @@ -422,7 +424,7 @@ func TestRespondWithJSON_UnserializableData(t *testing.T) { Ch: make(chan int), } - RespondWithJSON(w, http.StatusOK, data) + sabat.RespondWithJSON(w, http.StatusOK, data) resp := w.Result() defer resp.Body.Close() @@ -456,7 +458,7 @@ func TestRespondWithError_AllHTTPStatusCodes(t *testing.T) { t.Run(http.StatusText(code), func(t *testing.T) { w := httptest.NewRecorder() - RespondWithError(w, code, "test error") + sabat.RespondWithError(w, code, "test error") resp := w.Result() defer resp.Body.Close() @@ -477,7 +479,7 @@ func TestRespondWithJSON_ConcurrentWrites(t *testing.T) { w := httptest.NewRecorder() data := map[string]int{"index": idx} - RespondWithJSON(w, http.StatusOK, data) + sabat.RespondWithJSON(w, http.StatusOK, data) resp := w.Result() defer resp.Body.Close() @@ -508,7 +510,7 @@ func TestRespondWithError_HeadersAlreadyWritten(t *testing.T) { w.Write([]byte("already written")) // Try to respond with error - RespondWithError(w, http.StatusBadRequest, "error") + sabat.RespondWithError(w, http.StatusBadRequest, "error") // Status code shouldn't change after first write if w.Code == http.StatusBadRequest { @@ -522,7 +524,7 @@ func TestRespondWithJSON_EmptyStruct(t *testing.T) { type EmptyStruct struct{} data := EmptyStruct{} - RespondWithJSON(w, http.StatusOK, data) + sabat.RespondWithJSON(w, http.StatusOK, data) resp := w.Result() defer resp.Body.Close() @@ -541,7 +543,7 @@ func TestRespondWithMessage_ConcurrentCalls(t *testing.T) { go func(idx int) { w := httptest.NewRecorder() - RespondWithMessage(w, "test message") + sabat.RespondWithMessage(w, "test message") resp := w.Result() defer resp.Body.Close()