Skip to content

Commit

Permalink
refactor: remove duplication in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
josecelano committed Nov 30, 2022
1 parent ee01e7b commit e23d948
Showing 1 changed file with 16 additions and 35 deletions.
51 changes: 16 additions & 35 deletions tests/upgrades/from_v1_0_0_to_v2_0_0/testers/torrent_tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ pub struct TorrentTester {
}

pub struct TestData {
pub torrent_01: TorrentRecordV1,
pub torrent_02: TorrentRecordV1,
pub torrents: Vec<TorrentRecordV1>,
pub user: UserRecordV1,
}

Expand Down Expand Up @@ -71,48 +70,30 @@ impl TorrentTester {
source_database,
destiny_database,
test_data: TestData {
torrent_01,
torrent_02,
torrents: vec![torrent_01, torrent_02],
user: user.clone(),
},
}
}

pub async fn load_data_into_source_db(&self) {
self.source_database
.insert_torrent(&self.test_data.torrent_01)
.await
.unwrap();
self.source_database
.insert_torrent(&self.test_data.torrent_02)
.await
.unwrap();
for torrent in &self.test_data.torrents {
self.source_database.insert_torrent(&torrent).await.unwrap();
}
}

pub async fn assert_data_in_destiny_db(&self, upload_path: &str) {
let filepath_01 = self.torrent_file_path(upload_path, self.test_data.torrent_01.torrent_id);
let filepath_02 = self.torrent_file_path(upload_path, self.test_data.torrent_02.torrent_id);

let torrent_file_01 = read_torrent_from_file(&filepath_01).unwrap();
let torrent_file_02 = read_torrent_from_file(&filepath_02).unwrap();

// Check torrent 01
self.assert_torrent(&self.test_data.torrent_01, &torrent_file_01)
.await;
self.assert_torrent_info(&self.test_data.torrent_01).await;
self.assert_torrent_announce_urls(&self.test_data.torrent_01, &torrent_file_01)
.await;
self.assert_torrent_files(&self.test_data.torrent_01, &torrent_file_01)
.await;

// Check torrent 02
self.assert_torrent(&self.test_data.torrent_02, &torrent_file_02)
.await;
self.assert_torrent_info(&self.test_data.torrent_02).await;
self.assert_torrent_announce_urls(&self.test_data.torrent_02, &torrent_file_02)
.await;
self.assert_torrent_files(&self.test_data.torrent_02, &torrent_file_02)
.await;
for torrent in &self.test_data.torrents {
let filepath = self.torrent_file_path(upload_path, torrent.torrent_id);

let torrent_file = read_torrent_from_file(&filepath).unwrap();

self.assert_torrent(&torrent, &torrent_file).await;
self.assert_torrent_info(&torrent).await;
self.assert_torrent_announce_urls(&torrent, &torrent_file)
.await;
self.assert_torrent_files(&torrent, &torrent_file).await;
}
}

pub fn torrent_file_path(&self, upload_path: &str, torrent_id: i64) -> String {
Expand Down

0 comments on commit e23d948

Please sign in to comment.