jokes-bapak2/api/app/v1/handler/joke/joke_total_test.go

40 lines
813 B
Go
Raw Normal View History

package joke_test
import (
"io/ioutil"
"net/http"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestTotalJokes(t *testing.T) {
2021-08-04 05:56:14 +00:00
err := setup()
if err != nil {
t.Fatal(err)
}
2021-08-04 05:56:14 +00:00
defer cleanup()
2021-08-04 05:56:14 +00:00
req, _ := http.NewRequest("GET", "/total", nil)
res, err := app.Test(req, int(time.Minute * 2))
if err != nil {
t.Fatal(err)
}
2021-08-04 05:56:14 +00:00
assert.Equalf(t, false, err != nil, "joke total")
assert.Equalf(t, 200, res.StatusCode, "joke total")
assert.NotEqualf(t, 0, res.ContentLength, "joke total")
body, err := ioutil.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}
defer res.Body.Close()
2021-08-04 05:56:14 +00:00
assert.Nilf(t, err, "joke total")
// FIXME: This should be "message": "3", not one. I don't know what's wrong as it's 1 AM.
assert.Equalf(t, "{\"message\":\"3\"}", string(body), "joke total")
}