Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Arbitrary support #101

Merged
merged 3 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 86 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ serde_dynamo = { version = "4.2.2", features = [
], optional = true }
uuid = { version = "1", features = ["serde", "v4"], optional = true }
lambda_sqs = "0.2.4"
proptest-derive = { version = "0.4", optional = true }
proptest = { version = "1", optional = true }


[dev-dependencies]
anyhow = "1"
Expand All @@ -112,6 +115,7 @@ serde_json = { version = "1" }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

[features]
arbitrary = ["dep:proptest-derive", "dep:proptest"]
aws_lambda_utils = [
"dep:tower-service",
"dep:lambda_runtime",
Expand Down Expand Up @@ -212,26 +216,67 @@ services_eventbridge = [
"aws-types",
"cached",
]
services_iam = ["aws-config", "aws-sdk-iam", "aws-types", "aws-credential-types", "cached"]
services_iot = ["aws-config", "aws-sdk-iot", "aws-types", "aws-credential-types", "cached"]
services_iam = [
"aws-config",
"aws-sdk-iam",
"aws-types",
"aws-credential-types",
"cached",
]
services_iot = [
"aws-config",
"aws-sdk-iot",
"aws-types",
"aws-credential-types",
"cached",
]
services_iotdataplane = [
"aws-config",
"aws-credential-types",
"aws-sdk-iotdataplane",
"aws-types",
"cached",
]
services_lambda = ["aws-config", "aws-sdk-lambda", "aws-types", "aws-credential-types", "cached"]
services_mqtt = ["aws-smithy-http", "rumqttc", "tokio-rustls", "aws-sig-auth", "dep:anyhow", "dep:http", "aws-credential-types", "rustls-native-certs", "aws-sdk-iot", "cached"]
services_lambda = [
"aws-config",
"aws-sdk-lambda",
"aws-types",
"aws-credential-types",
"cached",
]
services_mqtt = [
"aws-smithy-http",
"rumqttc",
"tokio-rustls",
"aws-sig-auth",
"dep:anyhow",
"dep:http",
"aws-credential-types",
"rustls-native-certs",
"aws-sdk-iot",
"cached",
]
services_organizations = [
"aws-config",
"aws-credential-types",
"aws-sdk-organizations",
"aws-types",
"cached",
]
services_route53 = ["aws-config", "aws-sdk-route53", "aws-types", "aws-credential-types", "cached"]
services_s3 = ["aws-config", "aws-sdk-s3", "aws-types", "aws-credential-types", "cached"]
services_route53 = [
"aws-config",
"aws-sdk-route53",
"aws-types",
"aws-credential-types",
"cached",
]
services_s3 = [
"aws-config",
"aws-sdk-s3",
"aws-types",
"aws-credential-types",
"cached",
]
services_secretsmanager = [
"aws-config",
"aws-sdk-secretsmanager",
Expand All @@ -246,11 +291,41 @@ services_servicecatalog = [
"aws-credential-types",
"cached",
]
services_ssoadmin = ["aws-config", "aws-sdk-ssoadmin", "aws-types", "aws-credential-types", "cached"]
services_ssm = ["aws-config", "aws-sdk-ssm", "aws-types", "aws-credential-types", "cached"]
services_sts = ["aws-config", "aws-sdk-sts", "aws-types", "aws-credential-types", "cached"]
services_ses = ["aws-config", "aws-sdk-ses", "aws-types", "aws-credential-types", "cached"]
services_sqs = ["aws-config", "aws-sdk-sqs", "aws-types", "aws-credential-types", "cached"]
services_ssoadmin = [
"aws-config",
"aws-sdk-ssoadmin",
"aws-types",
"aws-credential-types",
"cached",
]
services_ssm = [
"aws-config",
"aws-sdk-ssm",
"aws-types",
"aws-credential-types",
"cached",
]
services_sts = [
"aws-config",
"aws-sdk-sts",
"aws-types",
"aws-credential-types",
"cached",
]
services_ses = [
"aws-config",
"aws-sdk-ses",
"aws-types",
"aws-credential-types",
"cached",
]
services_sqs = [
"aws-config",
"aws-sdk-sqs",
"aws-types",
"aws-credential-types",
"cached",
]
# Enable this feature to get support for the Valuable crate in tracing.
# Valuable is experimental, so this will need RUSTFLAGS="--cfg tracing_unstable".
# See https://github.com/tokio-rs/tracing/discussions/1906
Expand Down
20 changes: 16 additions & 4 deletions src/types/line_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,20 @@ use std::fmt::Display;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

#[cfg(feature = "arbitrary")]
use proptest_derive::Arbitrary;

#[derive(Clone, Debug, PartialEq, Eq, Hash, Deserialize, Serialize, PartialOrd, Ord)]
pub struct LineId(String);
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
pub struct LineId(#[proptest(strategy = "line_id_strategy()")] String);

#[cfg(feature = "arbitrary")]
fn line_id_strategy() -> impl proptest::strategy::Strategy<Value = String> {
use proptest::prelude::*;
any::<[u8; 16]>()
.prop_map(Uuid::from_bytes)
.prop_map(|x| x.to_string())
}

impl LineId {
pub fn new() -> Self {
Expand Down Expand Up @@ -34,9 +46,9 @@ impl From<&str> for LineId {
}
}

impl Into<String> for LineId {
fn into(self) -> String {
self.0
impl From<LineId> for String {
fn from(val: LineId) -> Self {
val.0
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/types/peripheral_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ use std::{fmt::Display, str::FromStr};
use serde::de::{Error as SerdeError, Visitor};
use thiserror::Error;

#[cfg(feature = "arbitrary")]
use proptest_derive::Arbitrary;

macro_rules! mk_peripheral_id {
($name:ident) => {
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Deserialize, serde::Serialize, PartialOrd, Ord)]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
#[serde(transparent)]
pub struct $name(RawPeripheralId);

Expand Down Expand Up @@ -65,8 +69,11 @@ mk_peripheral_id!(HardwarePeripheralId);
mk_peripheral_id!(SoftwarePeripheralId);

#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
struct RawPeripheralId {
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
pub struct RawPeripheralId {
#[proptest(regex = "[a-z0-9]+")]
uuid: String,
#[proptest(regex = "[a-z0-9]+")]
index: String,
}

Expand Down
4 changes: 4 additions & 0 deletions src/types/user_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ use std::fmt::Display;

use serde::{Deserialize, Serialize};

#[cfg(feature = "arbitrary")]
use proptest_derive::Arbitrary;

#[derive(Clone, Debug, PartialEq, Eq, Hash, Deserialize, Serialize, PartialOrd, Ord)]
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
pub struct UserPool(pub String);

impl Display for UserPool {
Expand Down
Loading