2022-08-30 02:30:36 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_Respond_NoContent(t *testing.T) {
|
|
|
|
recorder := httptest.NewRecorder()
|
|
|
|
dummystruct := struct {
|
|
|
|
Name string
|
|
|
|
}{
|
|
|
|
Name: "dummy",
|
|
|
|
}
|
|
|
|
|
2022-10-30 02:15:35 +00:00
|
|
|
err := Respond(recorder, http.StatusNoContent, dummystruct)
|
|
|
|
assert.NoError(t, err)
|
2022-08-30 02:30:36 +00:00
|
|
|
|
|
|
|
assert.Equal(t, http.StatusNoContent, recorder.Code)
|
|
|
|
assert.Empty(t, recorder.Body.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_Respond_JSON(t *testing.T) {
|
|
|
|
recorder := httptest.NewRecorder()
|
|
|
|
dummystruct := struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
}{
|
|
|
|
Name: "dummy",
|
|
|
|
}
|
|
|
|
|
2022-10-30 02:15:35 +00:00
|
|
|
err := Respond(recorder, http.StatusCreated, dummystruct)
|
|
|
|
assert.NoError(t, err)
|
2022-08-30 02:30:36 +00:00
|
|
|
|
|
|
|
assert.Equal(t, http.StatusCreated, recorder.Code)
|
|
|
|
assert.JSONEq(t, recorder.Body.String(), `{"name":"dummy"}`)
|
|
|
|
assert.Equal(t, "application/json", recorder.Header().Get("Content-Type"))
|
|
|
|
|
|
|
|
}
|