Add more migration tests (#17710)

* Add migration tests for hide_network settings migration

* Add tests about suspended/suspended_at

* Add more tests regarding the results of migrations

* Fix migration test regarding stale conflicting remote account

* Add migration tests about AccountConversation
main
Claire 3 years ago committed by GitHub
parent dba4be1038
commit 61ae6b3535
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -127,9 +127,18 @@ jobs:
- run:
command: ./bin/rails tests:migrations:populate_v2
name: Populate database with test data
- run:
command: ./bin/rails db:migrate VERSION=20180514140000
name: Run migrations up to v2.4.0
- run:
command: ./bin/rails tests:migrations:populate_v2_4
name: Populate database with test data
- run:
command: ./bin/rails db:migrate
name: Run all remaining migrations
- run:
command: ./bin/rails tests:migrations:check_database
name: Check migration result
test-two-step-migrations:
executor:
@ -150,6 +159,14 @@ jobs:
- run:
command: ./bin/rails tests:migrations:populate_v2
name: Populate database with test data
- run:
command: ./bin/rails db:migrate VERSION=20180514140000
name: Run pre-deployment migrations up to v2.4.0
environment:
SKIP_POST_DEPLOYMENT_MIGRATIONS: true
- run:
command: ./bin/rails tests:migrations:populate_v2_4
name: Populate database with test data
- run:
command: ./bin/rails db:migrate
name: Run all pre-deployment migrations
@ -158,6 +175,9 @@ jobs:
- run:
command: ./bin/rails db:migrate
name: Run all post-deployment remaining migrations
- run:
command: ./bin/rails tests:migrations:check_database
name: Check migration result
workflows:
version: 2

@ -2,6 +2,50 @@
namespace :tests do
namespace :migrations do
desc 'Check that database state is consistent with a successful migration from populated data'
task check_database: :environment do
unless Account.find_by(username: 'admin', domain: nil)&.hide_collections? == false
puts 'Unexpected value for Account#hide_collections? for user @admin'
exit(1)
end
unless Account.find_by(username: 'user', domain: nil)&.hide_collections? == true
puts 'Unexpected value for Account#hide_collections? for user @user'
exit(1)
end
unless Account.find_by(username: 'evil', domain: 'activitypub.com')&.suspended?
puts 'Unexpected value for Account#suspended? for user @evil@activitypub.com'
exit(1)
end
unless Status.find(6).account_id == Status.find(7).account_id
puts 'Users @remote@remote.com and @Remote@remote.com not properly merged'
exit(1)
end
if Account.where(domain: Rails.configuration.x.local_domain).exists?
puts 'Faux remote accounts not properly claned up'
exit(1)
end
unless AccountConversation.first&.last_status_id == 11
puts 'AccountConversation records not created as expected'
exit(1)
end
end
desc 'Populate the database with test data for 2.4.0'
task populate_v2_4: :environment do
ActiveRecord::Base.connection.execute(<<~SQL)
INSERT INTO "settings"
(id, thing_type, thing_id, var, value, created_at, updated_at)
VALUES
(1, 'User', 1, 'hide_network', E'--- false\n', now(), now()),
(2, 'User', 2, 'hide_network', E'--- true\n', now(), now());
SQL
end
desc 'Populate the database with test data for 2.0.0'
task populate_v2: :environment do
admin_key = OpenSSL::PKey::RSA.new(2048)
@ -34,7 +78,7 @@ namespace :tests do
'https://remote.com/@remote', 'https://remote.com/salmon/1'),
(4, 'Remote', 'remote.com', NULL, #{remote_public_key}, now(), now(),
'https://remote.com/@Remote', 'https://remote.com/salmon/1'),
(5, 'REMOTE', 'Remote.com', NULL, #{remote_public_key2}, now(), now(),
(5, 'REMOTE', 'Remote.com', NULL, #{remote_public_key2}, now() - interval '1 year', now() - interval '1 year',
'https://remote.com/stale/@REMOTE', 'https://remote.com/stale/salmon/1');
INSERT INTO "accounts"
@ -49,6 +93,13 @@ namespace :tests do
(7, 'user', #{local_domain}, #{user_private_key}, #{user_public_key}, now(), now()),
(8, 'pt_user', NULL, #{user_private_key}, #{user_public_key}, now(), now());
INSERT INTO "accounts"
(id, username, domain, private_key, public_key, created_at, updated_at, protocol, inbox_url, outbox_url, followers_url, suspended)
VALUES
(9, 'evil', 'activitypub.com', NULL, #{remote_public_key_ap}, now(), now(),
1, 'https://activitypub.com/users/evil/inbox', 'https://activitypub.com/users/evil/outbox',
'https://activitypub.com/users/evil/followers', true);
-- users
INSERT INTO "users"
@ -62,6 +113,9 @@ namespace :tests do
VALUES
(3, 7, 'ptuser@localhost', now(), now(), false, 'pt');
-- conversations
INSERT INTO "conversations" (id, created_at, updated_at) VALUES (1, now(), now());
-- statuses
INSERT INTO "statuses"
@ -97,14 +151,22 @@ namespace :tests do
VALUES
(9, 1, 2, now(), now());
INSERT INTO "statuses"
(id, account_id, text, in_reply_to_id, conversation_id, visibility, created_at, updated_at)
VALUES
(10, 2, '@admin hey!', NULL, 1, 3, now(), now()),
(11, 1, '@user hey!', 10, 1, 3, now(), now());
-- mentions (from previous statuses)
INSERT INTO "mentions"
(status_id, account_id, created_at, updated_at)
(id, status_id, account_id, created_at, updated_at)
VALUES
(2, 3, now(), now()),
(3, 4, now(), now()),
(4, 5, now(), now());
(1, 2, 3, now(), now()),
(2, 3, 4, now(), now()),
(3, 4, 5, now(), now()),
(4, 10, 1, now(), now()),
(5, 11, 2, now(), now());
-- stream entries
@ -121,7 +183,6 @@ namespace :tests do
(8, 5, 'status', now(), now()),
(9, 1, 'status', now(), now());
-- custom emoji
INSERT INTO "custom_emojis"
@ -161,12 +222,12 @@ namespace :tests do
-- follows
INSERT INTO "follows"
(account_id, target_account_id, created_at, updated_at)
(id, account_id, target_account_id, created_at, updated_at)
VALUES
(1, 5, now(), now()),
(6, 2, now(), now()),
(5, 2, now(), now()),
(6, 1, now(), now());
(1, 1, 5, now(), now()),
(2, 6, 2, now(), now()),
(3, 5, 2, now(), now()),
(4, 6, 1, now(), now());
-- follow requests
@ -175,6 +236,15 @@ namespace :tests do
VALUES
(2, 5, now(), now()),
(5, 1, now(), now());
-- notifications
INSERT INTO "notifications"
(id, from_account_id, account_id, activity_type, activity_id, created_at, updated_at)
VALUES
(1, 6, 2, 'Follow', 2, now(), now()),
(2, 2, 1, 'Mention', 4, now(), now()),
(3, 1, 2, 'Mention', 5, now(), now());
SQL
end
end

Loading…
Cancel
Save