From 884e390b79a62c531eb433919fd81a81d8cf6a14 Mon Sep 17 00:00:00 2001 From: Maxim Lebedev Date: Wed, 15 Mar 2023 04:10:05 +0600 Subject: [PATCH] :white_check_mark: Fixed broken tests --- internal/hub/delivery/http/hub_http_test.go | 4 +-- .../usecase/subscription_ucase_test.go | 30 +++++++++++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/internal/hub/delivery/http/hub_http_test.go b/internal/hub/delivery/http/hub_http_test.go index cfdd00d..fcdd410 100644 --- a/internal/hub/delivery/http/hub_http_test.go +++ b/internal/hub/delivery/http/hub_http_test.go @@ -48,7 +48,7 @@ func TestHandler_ServeHTTP_Subscribe(t *testing.T) { w := httptest.NewRecorder() delivery.NewHandler(delivery.NewHandlerParams{ Hub: hub, - Subscriptions: subscriptionucase.NewSubscriptionUseCase(subscriptions, topics), + Subscriptions: subscriptionucase.NewSubscriptionUseCase(subscriptions, topics, srv.Client()), Topics: topicucase.NewTopicUseCase(topics, srv.Client()), Matcher: language.NewMatcher([]language.Tag{language.English}), Name: "WebSub", @@ -94,7 +94,7 @@ func TestHandler_ServeHTTP_Unsubscribe(t *testing.T) { w := httptest.NewRecorder() delivery.NewHandler(delivery.NewHandlerParams{ Hub: hub, - Subscriptions: subscriptionucase.NewSubscriptionUseCase(subscriptions, topics), + Subscriptions: subscriptionucase.NewSubscriptionUseCase(subscriptions, topics, srv.Client()), Topics: topicucase.NewTopicUseCase(topics, srv.Client()), Matcher: language.NewMatcher([]language.Tag{language.English}), Name: "WebSub", diff --git a/internal/subscription/usecase/subscription_ucase_test.go b/internal/subscription/usecase/subscription_ucase_test.go index 8e7c42e..09a5f7e 100644 --- a/internal/subscription/usecase/subscription_ucase_test.go +++ b/internal/subscription/usecase/subscription_ucase_test.go @@ -2,8 +2,13 @@ package usecase_test import ( "context" + "fmt" + "net/http" + "net/http/httptest" + "net/url" "testing" + "source.toby3d.me/toby3d/hub/internal/common" "source.toby3d.me/toby3d/hub/internal/domain" subscriptionmemoryrepo "source.toby3d.me/toby3d/hub/internal/subscription/repository/memory" "source.toby3d.me/toby3d/hub/internal/subscription/usecase" @@ -13,11 +18,24 @@ import ( func TestSubscriptionUseCase_Subscribe(t *testing.T) { t.Parallel() - subscription := domain.TestSubscription(t, "https://example.com/") + topic := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set(common.HeaderContentType, common.MIMETextPlainCharsetUTF8) + fmt.Fprint(w, "hello, world") + })) + t.Cleanup(topic.Close) + + callback := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set(common.HeaderContentType, common.MIMETextPlainCharsetUTF8) + fmt.Fprint(w, "hello, world") + })) + t.Cleanup(callback.Close) + + subscription := domain.TestSubscription(t, callback.URL) + subscription.Topic, _ = url.Parse(topic.URL + "/") topics := topicmemoryrepo.NewMemoryTopicRepository() subscriptions := subscriptionmemoryrepo.NewMemorySubscriptionRepository() - ucase := usecase.NewSubscriptionUseCase(subscriptions, topics) + ucase := usecase.NewSubscriptionUseCase(subscriptions, topics, callback.Client()) ok, err := ucase.Subscribe(context.Background(), *subscription) if err != nil { @@ -49,6 +67,12 @@ func TestSubscriptionUseCase_Subscribe(t *testing.T) { func TestSubscriptionUseCase_Unsubscribe(t *testing.T) { t.Parallel() + srv := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set(common.HeaderContentType, common.MIMETextPlainCharsetUTF8) + fmt.Fprint(w, "hello, world") + })) + t.Cleanup(srv.Close) + subscription := domain.TestSubscription(t, "https://example.com/") topics := topicmemoryrepo.NewMemoryTopicRepository() subscriptions := subscriptionmemoryrepo.NewMemorySubscriptionRepository() @@ -57,7 +81,7 @@ func TestSubscriptionUseCase_Unsubscribe(t *testing.T) { t.Fatal(err) } - ok, err := usecase.NewSubscriptionUseCase(subscriptions, topics). + ok, err := usecase.NewSubscriptionUseCase(subscriptions, topics, srv.Client()). Unsubscribe(context.Background(), *subscription) if err != nil { t.Fatal(err)