You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
//go:build integration
|
|
|
|
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"git.runcible.io/learning/pulley/internal/assert"
|
|
"git.runcible.io/learning/pulley/internal/data"
|
|
"git.runcible.io/learning/pulley/internal/testutil"
|
|
)
|
|
|
|
func TestHttpListHandlers(t *testing.T) {
|
|
pool := testutil.SetupTestDB(t)
|
|
|
|
movies := []data.Movie{
|
|
{
|
|
ID: 1337,
|
|
Title: "Immortals",
|
|
Runtime: data.Runtime(110),
|
|
Genres: []string{"action", "adventure"},
|
|
Year: 2011,
|
|
Version: 1,
|
|
},
|
|
}
|
|
|
|
testutil.SeedMovies(t, pool, movies)
|
|
|
|
app := newTestApplication(pool)
|
|
|
|
t.Run("test list movies", func(t *testing.T) {
|
|
rec := httptest.NewRecorder()
|
|
r, err := http.NewRequest(http.MethodGet, "/v1/movies", nil)
|
|
assert.NilError(t, err)
|
|
|
|
app.routes().ServeHTTP(rec, r)
|
|
|
|
resp := rec.Result()
|
|
assert.Equal(t, resp.StatusCode, http.StatusOK)
|
|
|
|
defer resp.Body.Close()
|
|
body, err := io.ReadAll(resp.Body)
|
|
assert.NilError(t, err)
|
|
|
|
content := make(map[string][]data.Movie)
|
|
err = json.Unmarshal(body, &content)
|
|
assert.NilError(t, err)
|
|
|
|
assert.Equal(t, len(content["movies"]), 1)
|
|
assert.MovieEqual(t, content["movies"][0], movies[0])
|
|
})
|
|
|
|
}
|