From 8ea564084b3a10eeab5207161cb78f24e49f24fb Mon Sep 17 00:00:00 2001 From: Maxim Lebedev Date: Wed, 8 May 2024 15:44:47 +0500 Subject: [PATCH] :white_check_mark: Refactored client HTTP delivery test --- .../client/delivery/http/client_http_test.go | 31 +++++-------------- .../testdata/TestHandler_ServeHTTP.golden | 1 + 2 files changed, 9 insertions(+), 23 deletions(-) create mode 100755 internal/client/delivery/http/testdata/TestHandler_ServeHTTP.golden diff --git a/internal/client/delivery/http/client_http_test.go b/internal/client/delivery/http/client_http_test.go index f03ecc2..b83023e 100644 --- a/internal/client/delivery/http/client_http_test.go +++ b/internal/client/delivery/http/client_http_test.go @@ -10,26 +10,18 @@ import ( delivery "source.toby3d.me/toby3d/auth/internal/client/delivery/http" "source.toby3d.me/toby3d/auth/internal/domain" - "source.toby3d.me/toby3d/auth/internal/profile" - profilerepo "source.toby3d.me/toby3d/auth/internal/profile/repository/memory" - "source.toby3d.me/toby3d/auth/internal/session" - sessionrepo "source.toby3d.me/toby3d/auth/internal/session/repository/memory" "source.toby3d.me/toby3d/auth/internal/token" - tokenrepo "source.toby3d.me/toby3d/auth/internal/token/repository/memory" - tokenucase "source.toby3d.me/toby3d/auth/internal/token/usecase" + testutil "source.toby3d.me/toby3d/auth/internal/util/testing" ) type Dependencies struct { - profiles profile.Repository client *domain.Client config *domain.Config matcher language.Matcher - sessions session.Repository - tokens token.Repository tokenService token.UseCase } -func TestRead(t *testing.T) { +func TestHandler_ServeHTTP(t *testing.T) { t.Parallel() deps := NewDependencies(t) @@ -43,9 +35,13 @@ func TestRead(t *testing.T) { Tokens: deps.tokenService, }).ServeHTTP(w, req) - if resp := w.Result(); resp.StatusCode != http.StatusOK { + resp := w.Result() + + if resp.StatusCode != http.StatusOK { t.Errorf("%s %s = %d, want %d", req.Method, req.RequestURI, resp.StatusCode, http.StatusOK) } + + testutil.GoldenEqual(t, w.Result().Body) } func NewDependencies(tb testing.TB) Dependencies { @@ -54,23 +50,12 @@ func NewDependencies(tb testing.TB) Dependencies { client := domain.TestClient(tb) config := domain.TestConfig(tb) matcher := language.NewMatcher(message.DefaultCatalog.Languages()) - sessions := sessionrepo.NewMemorySessionRepository(*config) - tokens := tokenrepo.NewMemoryTokenRepository() - profiles := profilerepo.NewMemoryProfileRepository() - tokenService := tokenucase.NewTokenUseCase(tokenucase.Config{ - Config: *config, - Profiles: profiles, - Sessions: sessions, - Tokens: tokens, - }) + tokenService := token.NewDummyTokenUseCase() return Dependencies{ client: client, config: config, matcher: matcher, - sessions: sessions, - profiles: profiles, - tokens: tokens, tokenService: tokenService, } } diff --git a/internal/client/delivery/http/testdata/TestHandler_ServeHTTP.golden b/internal/client/delivery/http/testdata/TestHandler_ServeHTTP.golden new file mode 100755 index 0000000..078fc70 --- /dev/null +++ b/internal/client/delivery/http/testdata/TestHandler_ServeHTTP.golden @@ -0,0 +1 @@ +IndieAuth

Example App

\ No newline at end of file