mirror of
https://github.com/hay-kot/homebox.git
synced 2024-11-28 19:45:41 +00:00
bd321af29f
* new PR tasks * add homebox to know words * formatting * bump deps * generate db models * ts errors * drop id * fix accessor * drop unused time field * change CI * add expected error * add type check * resolve serveral type errors * hoise in CI
40 lines
868 B
Go
40 lines
868 B
Go
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",
|
|
}
|
|
|
|
err := Respond(recorder, http.StatusNoContent, dummystruct)
|
|
assert.NoError(t, err)
|
|
|
|
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",
|
|
}
|
|
|
|
err := Respond(recorder, http.StatusCreated, dummystruct)
|
|
assert.NoError(t, err)
|
|
|
|
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"))
|
|
}
|