diff --git a/internal/webpush/realsender_test.go b/internal/webpush/realsender_test.go index 167e198c9..8446fc47d 100644 --- a/internal/webpush/realsender_test.go +++ b/internal/webpush/realsender_test.go @@ -15,7 +15,7 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -package webpush +package webpush_test import ( "context" @@ -24,6 +24,9 @@ import ( "testing" "time" + // for go:linkname + _ "unsafe" + "github.com/stretchr/testify/suite" "github.com/superseriousbusiness/gotosocial/internal/cleaner" "github.com/superseriousbusiness/gotosocial/internal/db" @@ -40,6 +43,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/subscriptions" "github.com/superseriousbusiness/gotosocial/internal/transport" "github.com/superseriousbusiness/gotosocial/internal/typeutils" + "github.com/superseriousbusiness/gotosocial/internal/webpush" "github.com/superseriousbusiness/gotosocial/testrig" ) @@ -55,7 +59,7 @@ type RealSenderStandardTestSuite struct { federator *federation.Federator oauthServer oauth.Server emailSender email.Sender - webPushSender Sender + webPushSender webpush.Sender // standard suite models testTokens map[string]*gtsmodel.Token @@ -119,13 +123,13 @@ func (suite *RealSenderStandardTestSuite) SetupTest() { suite.oauthServer = testrig.NewTestOauthServer(suite.db) suite.emailSender = testrig.NewEmailSender("../../web/template/", nil) - suite.webPushSender = &realSender{ + suite.webPushSender = newSenderWith( &http.Client{ Transport: suite, }, &suite.state, suite.typeconverter, - } + ) suite.processor = processing.NewProcessor( cleaner.New(&suite.state), @@ -260,3 +264,6 @@ func (suite *RealSenderStandardTestSuite) TestServerError() { func TestRealSenderStandardTestSuite(t *testing.T) { suite.Run(t, &RealSenderStandardTestSuite{}) } + +//go:linkname newSenderWith github.com/superseriousbusiness/gotosocial/internal/webpush.newSenderWith +func newSenderWith(*http.Client, *state.State, *typeutils.Converter) webpush.Sender diff --git a/internal/webpush/sender.go b/internal/webpush/sender.go index ad3a48f82..32931561a 100644 --- a/internal/webpush/sender.go +++ b/internal/webpush/sender.go @@ -30,7 +30,9 @@ import ( // Sender can send Web Push notifications. type Sender interface { - // Send queues up a notification for delivery to all of an account's Web Push subscriptions. + + // Send queues up a notification for delivery to + // all of an account's Web Push subscriptions. Send( ctx context.Context, notification *gtsmodel.Notification, @@ -55,3 +57,12 @@ func NewSender(httpClient *httpclient.Client, state *state.State, converter *typ converter: converter, } } + +// an internal function purely existing for the webpush test package to link to and use a custom http.Client{}. +func newSenderWith(client *http.Client, state *state.State, converter *typeutils.Converter) Sender { + return &realSender{ + httpClient: client, + state: state, + converter: converter, + } +}