From cfac4fc97124b35927f000586bfebdb517bb0950 Mon Sep 17 00:00:00 2001 From: Stadnik Andrii Date: Fri, 6 Oct 2023 22:07:38 +0300 Subject: [PATCH] test: Add assertion for non-empty data and multiple nodes --- .github/workflows/build_and_test_bot.yml | 4 ++-- core/src/model/mod.rs | 5 ++++- core/tests/test_data.rs | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build_and_test_bot.yml b/.github/workflows/build_and_test_bot.yml index 06bbdd9c..5903a615 100644 --- a/.github/workflows/build_and_test_bot.yml +++ b/.github/workflows/build_and_test_bot.yml @@ -27,14 +27,14 @@ jobs: - name: Test and build release if: inputs.release env: - SHEET_ID: ${{ env.SHEET_ID }} + SHEET_ID: ${{ secrets.SHEET_ID }} RUST_LOG: info run: cargo test --release -- --nocapture && cargo build --release - name: Test and build debug if: ${{ !inputs.release }} env: - SHEET_ID: ${{ env.SHEET_ID }} + SHEET_ID: ${{ secrets.SHEET_ID }} RUST_LOG: info run: cargo test -- --nocapture && cargo build diff --git a/core/src/model/mod.rs b/core/src/model/mod.rs index d79a2987..f40c85a0 100644 --- a/core/src/model/mod.rs +++ b/core/src/model/mod.rs @@ -10,7 +10,7 @@ pub mod prelude { } use self::finite_state::{Fs, Row}; -use anyhow::{anyhow, Context}; +use anyhow::{anyhow, bail, Context}; use bytes::Buf; use csv::Reader; use finite_state::MultilangFs; @@ -42,6 +42,9 @@ fn get_finite_state(rdr: Reader, lang: Lang) -> anyhow::Result { .collect::, _>>() .context("Cannot parse csv")?; rows.retain(|record| !record.is_empty()); + if rows.is_empty() { + bail!("No data"); + } for r in rows.iter_mut() { r.key = r.key.trim().to_string(); r.question = r.question.trim().to_string(); diff --git a/core/tests/test_data.rs b/core/tests/test_data.rs index d5bcd39d..3573410a 100644 --- a/core/tests/test_data.rs +++ b/core/tests/test_data.rs @@ -75,6 +75,7 @@ pre-formatted fixed-width code block written in the Python programming language get_data_from_file("../table.csv")? }; assert!(!data.is_empty()); + assert!(data.iter().all(|(_, fs)| fs.num_nodes() > 1)); data.into_iter() .inspect(|(lang, fs)| log::info!("Testing {lang} with {} nodes", fs.num_nodes())) .try_for_each(|(_, fs)| test_fs(fs))?;