34 lines
992 B
Go
34 lines
992 B
Go
package http_test
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"source.toby3d.me/toby3d/home/internal/domain"
|
|
delivery "source.toby3d.me/toby3d/home/internal/static/delivery/http"
|
|
repository "source.toby3d.me/toby3d/home/internal/static/repository/stub"
|
|
"source.toby3d.me/toby3d/home/internal/static/usecase"
|
|
"source.toby3d.me/toby3d/home/internal/testutil"
|
|
)
|
|
|
|
func TestHandler_ServeHTTP(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/robots.txt", nil)
|
|
w := httptest.NewRecorder()
|
|
|
|
testStatic := domain.NewStatic(strings.NewReader("User-agent: *\nAllow: /"), time.Now().UTC(), "robots.txt")
|
|
delivery.NewHandler(usecase.NewStaticUseCase(repository.NewStubStaticRepository(nil, testStatic, false))).
|
|
ServeHTTP(w, req)
|
|
|
|
resp := w.Result()
|
|
if expect := http.StatusOK; resp.StatusCode != expect {
|
|
t.Errorf("%s %s = %d, want %d", req.Method, req.RequestURI, resp.StatusCode, expect)
|
|
}
|
|
|
|
testutil.GoldenEqual(t, resp.Body)
|
|
}
|