From 97e988e99eeaefd5703d1ce1b08657dd23a103ac Mon Sep 17 00:00:00 2001 From: kjuulh Date: Tue, 10 Jan 2023 22:54:18 +0100 Subject: [PATCH] fixed tests --- Cargo.lock | 7 +++++++ crates/github/Cargo.toml | 1 + crates/github/src/review.rs | 31 +++++++++++++++++++++++-------- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e1feb56..64df8bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "base64" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" + [[package]] name = "bitflags" version = "1.3.2" @@ -210,6 +216,7 @@ dependencies = [ name = "github" version = "0.1.0" dependencies = [ + "base64", "clap", "comfy-table", "dirs", diff --git a/crates/github/Cargo.toml b/crates/github/Cargo.toml index 2af2caf..1c5d8d6 100644 --- a/crates/github/Cargo.toml +++ b/crates/github/Cargo.toml @@ -16,6 +16,7 @@ serde = { version = "1.0.152", features = ["derive"] } serde_json = "1.0.91" comfy-table = "6.1.4" pretty_assertions = "1.3.0" +base64 = "0.21.0" [dev-dependencies] mockall = "0.11.2" diff --git a/crates/github/src/review.rs b/crates/github/src/review.rs index 5900497..99c5988 100644 --- a/crates/github/src/review.rs +++ b/crates/github/src/review.rs @@ -75,6 +75,7 @@ mod tests { use super::*; + use base64::Engine; use pretty_assertions::{assert_eq, assert_ne}; #[test] @@ -129,16 +130,30 @@ mod tests { }, }, ]; - let expected_table = "───────────────────────────────────────────── - repo title number -═════════════════════════════════════════════ - some-name some-title 0 -───────────────────────────────────────────── - some-other-name some-other-title 1 -─────────────────────────────────────────────"; + let expected_table = "4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSAChtbMW0gcmVwbyAgICAgICAgICAgIBtbMG0gG1sxbSB0aXRsZSAgICAgICAgICAgIBtbMG0gG1sxbSBudW1iZXIgG1swbQrilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZDilZAKG1szODs1OzEwbSBzb21lLW5hbWUgICAgICAgG1szOW0gIHNvbWUtdGl0bGUgICAgICAgICAwICAgICAgCuKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgAobWzM4OzU7MTBtIHNvbWUtb3RoZXItbmFtZSAbWzM5bSAgc29tZS1vdGhlci10aXRsZSAgIDEgICAgICAK4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA4pSA"; let output = Review::generate_prs_table(&prs); - assert_eq!(output, expected_table.to_string()) + compare_tables(output, expected_table) + } + + fn compare_tables(actual: String, snapshot: &str) { + let b64 = base64::engine::general_purpose::STANDARD_NO_PAD; + let snapshot = snapshot.clone().replace("\n", "").replace(" ", ""); + println!("expected"); + println!( + "{}", + std::str::from_utf8( + b64.decode(&snapshot) + .expect("table to be decodeable") + .as_slice() + ) + .expect("to be utf8") + ); + + println!("actual"); + println!("{actual}"); + + assert_eq!(b64.encode(actual), snapshot); } }