diff options
author | 2022-11-29 10:24:55 +0100 | |
---|---|---|
committer | 2022-11-29 09:24:55 +0000 | |
commit | 97f54533781139407f7d33aa0bdb80d0bf3264f6 (patch) | |
tree | b10e3dace88f843c9965c50140b682503cc201a7 /internal/federation/dereferencing/account_test.go | |
parent | [chore] Bump database dependencies (#1164) (diff) | |
download | gotosocial-97f54533781139407f7d33aa0bdb80d0bf3264f6.tar.xz |
[chore] Tidy up some of the search logic (#1082)v0.6.0-rc1
* start refactoring some of the search + deref logic
* add tests for search api
* rename GetRemoteAccount + GetRemoteStatus
* make search function a bit simpler + clearer
* fix little fucky wucky uwu owo i'm just a little guy
* update faulty switch statements
* update test to use storage struct
* redo switches for clarity
* reduce repeated logic in search tests
* fastfail getstatus by uri
* debug log + trace log better
* add implementation note
* return early if no result for namestring search
* return + check on dereferencing error types
* errors hah what errors
* remove unneeded error type alias, add custom error text during stringification itself
* fix a woops recursion :see_no_evil:
Signed-off-by: kim <grufwub@gmail.com>
Co-authored-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/federation/dereferencing/account_test.go')
-rw-r--r-- | internal/federation/dereferencing/account_test.go | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/internal/federation/dereferencing/account_test.go b/internal/federation/dereferencing/account_test.go index 38dc615d5..c5541209f 100644 --- a/internal/federation/dereferencing/account_test.go +++ b/internal/federation/dereferencing/account_test.go @@ -39,7 +39,7 @@ func (suite *AccountTestSuite) TestDereferenceGroup() { fetchingAccount := suite.testAccounts["local_account_1"] groupURL := testrig.URLMustParse("https://unknown-instance.com/groups/some_group") - group, err := suite.dereferencer.GetRemoteAccount(context.Background(), dereferencing.GetRemoteAccountParams{ + group, err := suite.dereferencer.GetAccount(context.Background(), dereferencing.GetAccountParams{ RequestingUsername: fetchingAccount.Username, RemoteAccountID: groupURL, }) @@ -62,7 +62,7 @@ func (suite *AccountTestSuite) TestDereferenceService() { fetchingAccount := suite.testAccounts["local_account_1"] serviceURL := testrig.URLMustParse("https://owncast.example.org/federation/user/rgh") - service, err := suite.dereferencer.GetRemoteAccount(context.Background(), dereferencing.GetRemoteAccountParams{ + service, err := suite.dereferencer.GetAccount(context.Background(), dereferencing.GetAccountParams{ RequestingUsername: fetchingAccount.Username, RemoteAccountID: serviceURL, }) @@ -93,7 +93,7 @@ func (suite *AccountTestSuite) TestDereferenceLocalAccountAsRemoteURL() { fetchingAccount := suite.testAccounts["local_account_1"] targetAccount := suite.testAccounts["local_account_2"] - fetchedAccount, err := suite.dereferencer.GetRemoteAccount(context.Background(), dereferencing.GetRemoteAccountParams{ + fetchedAccount, err := suite.dereferencer.GetAccount(context.Background(), dereferencing.GetAccountParams{ RequestingUsername: fetchingAccount.Username, RemoteAccountID: testrig.URLMustParse(targetAccount.URI), }) @@ -111,7 +111,7 @@ func (suite *AccountTestSuite) TestDereferenceLocalAccountAsRemoteURLNoSharedInb suite.FailNow(err.Error()) } - fetchedAccount, err := suite.dereferencer.GetRemoteAccount(context.Background(), dereferencing.GetRemoteAccountParams{ + fetchedAccount, err := suite.dereferencer.GetAccount(context.Background(), dereferencing.GetAccountParams{ RequestingUsername: fetchingAccount.Username, RemoteAccountID: testrig.URLMustParse(targetAccount.URI), }) @@ -124,7 +124,7 @@ func (suite *AccountTestSuite) TestDereferenceLocalAccountAsUsername() { fetchingAccount := suite.testAccounts["local_account_1"] targetAccount := suite.testAccounts["local_account_2"] - fetchedAccount, err := suite.dereferencer.GetRemoteAccount(context.Background(), dereferencing.GetRemoteAccountParams{ + fetchedAccount, err := suite.dereferencer.GetAccount(context.Background(), dereferencing.GetAccountParams{ RequestingUsername: fetchingAccount.Username, RemoteAccountUsername: targetAccount.Username, }) @@ -137,7 +137,7 @@ func (suite *AccountTestSuite) TestDereferenceLocalAccountAsUsernameDomain() { fetchingAccount := suite.testAccounts["local_account_1"] targetAccount := suite.testAccounts["local_account_2"] - fetchedAccount, err := suite.dereferencer.GetRemoteAccount(context.Background(), dereferencing.GetRemoteAccountParams{ + fetchedAccount, err := suite.dereferencer.GetAccount(context.Background(), dereferencing.GetAccountParams{ RequestingUsername: fetchingAccount.Username, RemoteAccountUsername: targetAccount.Username, RemoteAccountHost: config.GetHost(), @@ -151,7 +151,7 @@ func (suite *AccountTestSuite) TestDereferenceLocalAccountAsUsernameDomainAndURL fetchingAccount := suite.testAccounts["local_account_1"] targetAccount := suite.testAccounts["local_account_2"] - fetchedAccount, err := suite.dereferencer.GetRemoteAccount(context.Background(), dereferencing.GetRemoteAccountParams{ + fetchedAccount, err := suite.dereferencer.GetAccount(context.Background(), dereferencing.GetAccountParams{ RequestingUsername: fetchingAccount.Username, RemoteAccountID: testrig.URLMustParse(targetAccount.URI), RemoteAccountUsername: targetAccount.Username, @@ -165,34 +165,40 @@ func (suite *AccountTestSuite) TestDereferenceLocalAccountAsUsernameDomainAndURL func (suite *AccountTestSuite) TestDereferenceLocalAccountWithUnknownUsername() { fetchingAccount := suite.testAccounts["local_account_1"] - fetchedAccount, err := suite.dereferencer.GetRemoteAccount(context.Background(), dereferencing.GetRemoteAccountParams{ + fetchedAccount, err := suite.dereferencer.GetAccount(context.Background(), dereferencing.GetAccountParams{ RequestingUsername: fetchingAccount.Username, RemoteAccountUsername: "thisaccountdoesnotexist", }) - suite.EqualError(err, "GetRemoteAccount: couldn't retrieve account locally and won't try to resolve it") + var errNotRetrievable *dereferencing.ErrNotRetrievable + suite.ErrorAs(err, &errNotRetrievable) + suite.EqualError(err, "item could not be retrieved: GetRemoteAccount: couldn't retrieve account locally and not allowed to resolve it") suite.Nil(fetchedAccount) } func (suite *AccountTestSuite) TestDereferenceLocalAccountWithUnknownUsernameDomain() { fetchingAccount := suite.testAccounts["local_account_1"] - fetchedAccount, err := suite.dereferencer.GetRemoteAccount(context.Background(), dereferencing.GetRemoteAccountParams{ + fetchedAccount, err := suite.dereferencer.GetAccount(context.Background(), dereferencing.GetAccountParams{ RequestingUsername: fetchingAccount.Username, RemoteAccountUsername: "thisaccountdoesnotexist", RemoteAccountHost: "localhost:8080", }) - suite.EqualError(err, "GetRemoteAccount: couldn't retrieve account locally and won't try to resolve it") + var errNotRetrievable *dereferencing.ErrNotRetrievable + suite.ErrorAs(err, &errNotRetrievable) + suite.EqualError(err, "item could not be retrieved: GetRemoteAccount: couldn't retrieve account locally and not allowed to resolve it") suite.Nil(fetchedAccount) } func (suite *AccountTestSuite) TestDereferenceLocalAccountWithUnknownUserURI() { fetchingAccount := suite.testAccounts["local_account_1"] - fetchedAccount, err := suite.dereferencer.GetRemoteAccount(context.Background(), dereferencing.GetRemoteAccountParams{ + fetchedAccount, err := suite.dereferencer.GetAccount(context.Background(), dereferencing.GetAccountParams{ RequestingUsername: fetchingAccount.Username, RemoteAccountID: testrig.URLMustParse("http://localhost:8080/users/thisaccountdoesnotexist"), }) - suite.EqualError(err, "GetRemoteAccount: couldn't retrieve account locally and won't try to resolve it") + var errNotRetrievable *dereferencing.ErrNotRetrievable + suite.ErrorAs(err, &errNotRetrievable) + suite.EqualError(err, "item could not be retrieved: GetRemoteAccount: couldn't retrieve account locally and not allowed to resolve it") suite.Nil(fetchedAccount) } @@ -233,7 +239,7 @@ func (suite *AccountTestSuite) TestDereferenceRemoteAccountWithPartial() { }, } - fetchedAccount, err := suite.dereferencer.GetRemoteAccount(context.Background(), dereferencing.GetRemoteAccountParams{ + fetchedAccount, err := suite.dereferencer.GetAccount(context.Background(), dereferencing.GetAccountParams{ RequestingUsername: fetchingAccount.Username, RemoteAccountID: testrig.URLMustParse(remoteAccount.URI), RemoteAccountHost: remoteAccount.Domain, @@ -286,7 +292,7 @@ func (suite *AccountTestSuite) TestDereferenceRemoteAccountWithPartial2() { }, } - fetchedAccount, err := suite.dereferencer.GetRemoteAccount(context.Background(), dereferencing.GetRemoteAccountParams{ + fetchedAccount, err := suite.dereferencer.GetAccount(context.Background(), dereferencing.GetAccountParams{ RequestingUsername: fetchingAccount.Username, RemoteAccountID: testrig.URLMustParse(remoteAccount.URI), RemoteAccountHost: remoteAccount.Domain, @@ -339,7 +345,7 @@ func (suite *AccountTestSuite) TestDereferenceRemoteAccountWithPartial3() { }, } - fetchedAccount, err := suite.dereferencer.GetRemoteAccount(context.Background(), dereferencing.GetRemoteAccountParams{ + fetchedAccount, err := suite.dereferencer.GetAccount(context.Background(), dereferencing.GetAccountParams{ RequestingUsername: fetchingAccount.Username, RemoteAccountID: testrig.URLMustParse(remoteAccount.URI), RemoteAccountHost: remoteAccount.Domain, @@ -386,7 +392,7 @@ func (suite *AccountTestSuite) TestDereferenceRemoteAccountWithPartial3() { }, } - fetchedAccount2, err := suite.dereferencer.GetRemoteAccount(context.Background(), dereferencing.GetRemoteAccountParams{ + fetchedAccount2, err := suite.dereferencer.GetAccount(context.Background(), dereferencing.GetAccountParams{ RequestingUsername: fetchingAccount.Username, RemoteAccountID: testrig.URLMustParse(remoteAccount.URI), RemoteAccountHost: remoteAccount.Domain, |