Skip to content

Commit

Permalink
fix: use rstest in generate command tests (vs wrong usage of `pro…
Browse files Browse the repository at this point in the history
…ptest`) (#18365)

* fix: wrong usage of proptest, replace with rstest

* add rstest to the dictionary
  • Loading branch information
pront authored Aug 28, 2023
1 parent a3a1ef0 commit 4359c9a
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 23 deletions.
1 change: 1 addition & 0 deletions .github/actions/spelling/allow.txt
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ rootfs
roundrobin
rpmbuild
rpms
rstest
rsyslog
rsyslogd
servlet
Expand Down
36 changes: 36 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ proptest = "1.2"
quickcheck = "1.0.3"
lookup = { package = "vector-lookup", path = "lib/vector-lookup", features = ["test"] }
reqwest = { version = "0.11", features = ["json"] }
rstest = {version = "0.18.2"}
tempfile = "3.6.0"
test-generator = "0.3.1"
tokio = { version = "1.32.0", features = ["test-util"] }
Expand Down
10 changes: 0 additions & 10 deletions src/config/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,6 @@ where
#[cfg(test)]
mod tests {
use super::*;
use proptest::prelude::*;

impl Arbitrary for Format {
type Parameters = ();
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
prop_oneof![Just(Format::Toml), Just(Format::Json), Just(Format::Yaml),].boxed()
}

type Strategy = BoxedStrategy<Self>;
}

/// This test ensures the logic to guess file format from the file path
/// works correctly.
Expand Down
28 changes: 15 additions & 13 deletions src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ fn write_config(filepath: &Path, body: &str) -> Result<(), crate::Error> {
mod tests {
use super::*;
use crate::config::ConfigBuilder;
use proptest::prelude::*;
use rstest::rstest;

fn generate_and_deserialize(expression: String, format: Format) {
let opts = Opts {
Expand All @@ -410,20 +410,22 @@ mod tests {
}
}

proptest! {
#[test]
fn generate_all(format in any::<Format>()) {
for name in SourceDescription::types() {
generate_and_deserialize(format!("{}//", name), format);
}
#[rstest]
#[case(Format::Toml)]
#[case(Format::Json)]
#[case(Format::Yaml)]
#[test]
fn generate_all(#[case] format: Format) {
for name in SourceDescription::types() {
generate_and_deserialize(format!("{}//", name), format);
}

for name in TransformDescription::types() {
generate_and_deserialize(format!("/{}/", name), format);
}
for name in TransformDescription::types() {
generate_and_deserialize(format!("/{}/", name), format);
}

for name in SinkDescription::types() {
generate_and_deserialize(format!("//{}", name), format);
}
for name in SinkDescription::types() {
generate_and_deserialize(format!("//{}", name), format);
}
}

Expand Down

0 comments on commit 4359c9a

Please sign in to comment.