Refactored client HTTP delivery test
/ docker (push) Successful in 1m24s Details

This commit is contained in:
Maxim Lebedev 2024-05-08 15:44:47 +05:00
parent 04b7135f7e
commit 8ea564084b
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
2 changed files with 9 additions and 23 deletions

View File

@ -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,
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><html class="page" lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="icon" href="/favicon.ico" sizes="any"><link rel="icon" href="/icon.svg" type="image/svg+xml"><link rel="apple-touch-icon" href="/apple-touch-icon.png"><link rel="manifest" href="/manifest.webmanifest"><link rel="redirect_uri" href="https://app.example.com/redirect"><link rel="redirect_uri" href="https://app.example.net/redirect"><title>IndieAuth</title></head><body class="page__body body"><header class="h-app h-x-app"><img class="u-logo" src="https://app.example.com/logo.png" alt="Example App" crossorigin="anonymous" decoding="async" height="140" importance="high" referrerpolicy="no-referrer-when-downgrade" width="140"><h1><a class="p-name u-url" href="https://app.example.com/">Example App</a></h1></header><main><form class="" method="get" action="/authorize" enctype="application/x-www-form-urlencoded" accept-charset="utf-8" target="_self"><input type="hidden" name="client_id" value="https://127.0.0.1/"><input type="hidden" name="redirect_uri" value="https://app.example.com/redirect"><input type="hidden" name="response_type" value="code"><input type="hidden" name="scope" value="email profile"><input type="hidden" name="state" value="hackme"><input type="url" name="me" placeholder="https://example.com/" inputmode="url" autocomplete="url" required><button type="submit">Sign In</button></form></main></body></html>