Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mastodon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pierre Boudes
mastodon
Commits
70cd2d60
Unverified
Commit
70cd2d60
authored
1 year ago
by
Daniel M Brasil
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Add test coverage for `Mastodon::CLI::Accounts#cull` (#25250)
parent
a6c898f5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
spec/lib/mastodon/cli/accounts_spec.rb
+139
-0
139 additions, 0 deletions
spec/lib/mastodon/cli/accounts_spec.rb
with
139 additions
and
0 deletions
spec/lib/mastodon/cli/accounts_spec.rb
+
139
−
0
View file @
70cd2d60
...
...
@@ -1109,4 +1109,143 @@ describe Mastodon::CLI::Accounts do
end
end
end
describe
'#cull'
do
let
(
:delete_account_service
)
{
instance_double
(
DeleteAccountService
,
call:
nil
)
}
let!
(
:tom
)
{
Fabricate
(
:account
,
updated_at:
30
.
days
.
ago
,
username:
'tom'
,
uri:
'https://example.com/users/tom'
,
domain:
'example.com'
)
}
let!
(
:bob
)
{
Fabricate
(
:account
,
updated_at:
30
.
days
.
ago
,
last_webfingered_at:
nil
,
username:
'bob'
,
uri:
'https://example.org/users/bob'
,
domain:
'example.org'
)
}
let!
(
:gon
)
{
Fabricate
(
:account
,
updated_at:
15
.
days
.
ago
,
last_webfingered_at:
15
.
days
.
ago
,
username:
'gon'
,
uri:
'https://example.net/users/gon'
,
domain:
'example.net'
)
}
let!
(
:ana
)
{
Fabricate
(
:account
,
username:
'ana'
,
uri:
'https://example.com/users/ana'
,
domain:
'example.com'
)
}
let!
(
:tales
)
{
Fabricate
(
:account
,
updated_at:
10
.
days
.
ago
,
last_webfingered_at:
nil
,
username:
'tales'
,
uri:
'https://example.net/users/tales'
,
domain:
'example.net'
)
}
before
do
allow
(
DeleteAccountService
).
to
receive
(
:new
).
and_return
(
delete_account_service
)
end
context
'when no domain is specified'
do
let
(
:scope
)
{
Account
.
remote
.
where
(
protocol: :activitypub
).
partitioned
}
before
do
allow
(
cli
).
to
receive
(
:parallelize_with_progress
).
and_yield
(
tom
)
.
and_yield
(
bob
)
.
and_yield
(
gon
)
.
and_yield
(
ana
)
.
and_yield
(
tales
)
.
and_return
([
5
,
3
])
stub_request
(
:head
,
'https://example.org/users/bob'
).
to_return
(
status:
404
)
stub_request
(
:head
,
'https://example.net/users/gon'
).
to_return
(
status:
410
)
stub_request
(
:head
,
'https://example.net/users/tales'
).
to_return
(
status:
200
)
end
it
'deletes all inactive remote accounts that longer exist in the origin server'
do
cli
.
cull
expect
(
cli
).
to
have_received
(
:parallelize_with_progress
).
with
(
scope
).
once
expect
(
delete_account_service
).
to
have_received
(
:call
).
with
(
bob
,
reserve_username:
false
).
once
expect
(
delete_account_service
).
to
have_received
(
:call
).
with
(
gon
,
reserve_username:
false
).
once
end
it
'does not delete any active remote account that still exists in the origin server'
do
cli
.
cull
expect
(
cli
).
to
have_received
(
:parallelize_with_progress
).
with
(
scope
).
once
expect
(
delete_account_service
).
to_not
have_received
(
:call
).
with
(
tom
,
reserve_username:
false
)
expect
(
delete_account_service
).
to_not
have_received
(
:call
).
with
(
ana
,
reserve_username:
false
)
expect
(
delete_account_service
).
to_not
have_received
(
:call
).
with
(
tales
,
reserve_username:
false
)
end
it
'touches inactive remote accounts that have not been deleted'
do
allow
(
tales
).
to
receive
(
:touch
)
cli
.
cull
expect
(
tales
).
to
have_received
(
:touch
).
once
end
it
'displays the summary correctly'
do
expect
{
cli
.
cull
}.
to
output
(
a_string_including
(
'Visited 5 accounts, removed 3'
)
).
to_stdout
end
end
context
'when a domain is specified'
do
let
(
:domain
)
{
'example.net'
}
let
(
:scope
)
{
Account
.
remote
.
where
(
protocol: :activitypub
,
domain:
domain
).
partitioned
}
before
do
allow
(
cli
).
to
receive
(
:parallelize_with_progress
).
and_yield
(
gon
)
.
and_yield
(
tales
)
.
and_return
([
2
,
2
])
stub_request
(
:head
,
'https://example.net/users/gon'
).
to_return
(
status:
410
)
stub_request
(
:head
,
'https://example.net/users/tales'
).
to_return
(
status:
404
)
end
it
'deletes inactive remote accounts that longer exist in the specified domain'
do
cli
.
cull
(
domain
)
expect
(
cli
).
to
have_received
(
:parallelize_with_progress
).
with
(
scope
).
once
expect
(
delete_account_service
).
to
have_received
(
:call
).
with
(
gon
,
reserve_username:
false
).
once
expect
(
delete_account_service
).
to
have_received
(
:call
).
with
(
tales
,
reserve_username:
false
).
once
end
it
'displays the summary correctly'
do
expect
{
cli
.
cull
}.
to
output
(
a_string_including
(
'Visited 2 accounts, removed 2'
)
).
to_stdout
end
end
context
'when a domain is unavailable'
do
shared_examples
'an unavailable domain'
do
before
do
allow
(
cli
).
to
receive
(
:parallelize_with_progress
).
and_yield
(
tales
).
and_return
([
1
,
0
])
end
it
'skips accounts from the unavailable domain'
do
cli
.
cull
expect
(
delete_account_service
).
to_not
have_received
(
:call
).
with
(
tales
,
reserve_username:
false
)
end
it
'displays the summary correctly'
do
expect
{
cli
.
cull
}.
to
output
(
a_string_including
(
"Visited 1 accounts, removed 0
\n
The following domains were not available during the check:
\n
example.net"
)
).
to_stdout
end
end
context
'when a connection timeout occurs'
do
before
do
stub_request
(
:head
,
'https://example.net/users/tales'
).
to_timeout
end
it_behaves_like
'an unavailable domain'
end
context
'when a connection error occurs'
do
before
do
stub_request
(
:head
,
'https://example.net/users/tales'
).
to_raise
(
HTTP
::
ConnectionError
)
end
it_behaves_like
'an unavailable domain'
end
context
'when an ssl error occurs'
do
before
do
stub_request
(
:head
,
'https://example.net/users/tales'
).
to_raise
(
OpenSSL
::
SSL
::
SSLError
)
end
it_behaves_like
'an unavailable domain'
end
context
'when a private network address error occurs'
do
before
do
stub_request
(
:head
,
'https://example.net/users/tales'
).
to_raise
(
Mastodon
::
PrivateNetworkAddressError
)
end
it_behaves_like
'an unavailable domain'
end
end
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment