Skip to content

Commit

Permalink
ci(test): cache leetcode db
Browse files Browse the repository at this point in the history
test: tweak
  • Loading branch information
saying121 committed May 20, 2024
1 parent ceb4e36 commit fa18d98
Show file tree
Hide file tree
Showing 9 changed files with 245 additions and 199 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly

- name: Install cargo-binstall
uses: taiki-e/install-action@v2
with:
Expand Down
57 changes: 55 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,62 @@ jobs:
rust: [nightly]
steps:
- uses: actions/checkout/@v4
- uses: dtolnay/rust-toolchain@master

- name: Linux Cache leetcode
if: startsWith(matrix.os, 'ubuntu-')
id: linux-leetcode-cache
uses: actions/cache@v4
with:
path: |
~/.cache/lcode/
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}

- name: Windows Cache leetcode
if: startsWith(matrix.os, 'windows-')
id: windows-leetcode-cache
uses: actions/cache@v4
with:
path: |
~/AppData/Local/lcode/
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}

- name: Macos Cache leetcode
if: startsWith(matrix.os, 'macos-')
id: macos-leetcode-cache
uses: actions/cache@v4
with:
path: |
~/Library/Caches/lcode/
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}

- name: Restore cached Primes
id: cache-primes-restore
uses: actions/cache/restore@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}

- name: Rust Toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly

- name: Install Dependencies
if: startsWith(matrix.os, 'ubuntu-')
run: |
Expand All @@ -57,5 +110,5 @@ jobs:

- name: Run Test
run: |
time cargo nextest run get_all_pbs_works new_get_index # generate database
cargo nextest run --all-features
# cargo test --all-features
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,3 @@ You can checkout the infos/tab3 in tui for ensure cookies is valid.
## Todo

- Cache cookies.
- Cache info in ci.
4 changes: 0 additions & 4 deletions crates/leetcode-api/tests/get_img_work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ use leetcode_api::{glob_leetcode, leetcode::IdSlug};
use miette::Result;
use scraper::{Html, Selector};

#[ignore]
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn get_img_url() -> Result<()> {
// tracing_subscriber::fmt()
// .with_max_level(tracing::Level::DEBUG)
// .with_test_writer()
// .init();

// let question = glob_leetcode()
// .get_qs_detail(IdSlug::Id(113), true)
// .await?;
let question = glob_leetcode()
.await
.get_qs_detail(IdSlug::Id(1008), true)
Expand Down
123 changes: 123 additions & 0 deletions crates/leetcode-api/tests/lc_manual.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
use leetcode_api::{glob_leetcode, leetcode::IdSlug, render::Render};
use miette::Result;

#[ignore = "manual"]
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn test_work() -> Result<()> {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::DEBUG)
.with_test_writer()
.init();

match glob_leetcode()
.await
.test_code(IdSlug::Id(435))
.await
{
Ok((_, res)) => {
dbg!(&res);
println!(r##"(| res |) -> {} "##, res.to_md_str(false));
// res.render_with_mdcat();
// dbg!(res.to_tui_vec());
},
Err(e) => eprintln!("{e}"),
}

Ok(())
}

#[ignore = "need realy environment"]
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn submit_work() {
// tracing_subscriber::fmt()
// .with_max_level(tracing::Level::DEBUG)
// .with_test_writer()
// .init();

let (_, res) = glob_leetcode()
.await
.submit_code(IdSlug::Id(27))
.await
.unwrap();
dbg!(res.to_tui_vec());
println!(r##"(| res |) -> {} "##, res.to_md_str(false));
res.render_with_mdcat();
}

#[ignore = "manual"]
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn get_submit_list() -> Result<()> {
// tracing_subscriber::fmt()
// .with_max_level(tracing::Level::DEBUG)
// .with_test_writer()
// .init();

let a = glob_leetcode().await;
let res = a.all_submit_res(IdSlug::Id(32)).await?;
println!("{}", res);
// render_str(res.to_string())?;
// let res = get_rendered_str(res.to_string(), 30, 10)?;
// println!("{}", res);

Ok(())
}
#[ignore = "manual"]
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn daily_checkin() -> Result<()> {
// tracing_subscriber::fmt()
// .with_max_level(tracing::Level::DEBUG)
// .with_test_writer()
// .init();

let a = glob_leetcode().await;
let res = a.daily_checkin().await;
println!("{:#?}", res);

Ok(())
}
#[ignore = "manual"]
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn user_points() -> Result<()> {
// tracing_subscriber::fmt()
// .with_max_level(tracing::Level::DEBUG)
// .with_test_writer()
// .init();

let a = glob_leetcode().await;
let res = a.get_points().await?;
println!("{:#?}", res);

Ok(())
}
#[ignore = "manual"]
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn user_global_data() -> Result<()> {
// tracing_subscriber::fmt()
// .with_max_level(tracing::Level::DEBUG)
// .with_test_writer()
// .init();

let a = glob_leetcode().await;
let res = a.get_user_info().await?;
println!("{:#?}", res);

Ok(())
}

#[ignore = "manual"]
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn user_pass_data() -> Result<()> {
// tracing_subscriber::fmt()
// .with_max_level(tracing::Level::DEBUG)
// .with_test_writer()
// .init();

let a = glob_leetcode().await;
let temp = a.get_user_info().await?;
let res = a
.pass_qs_status(&temp.user_slug.unwrap_or_default())
.await?;
println!("{:#?}", res);

Ok(())
}
Loading

0 comments on commit fa18d98

Please sign in to comment.