Skip to content

Commit c184da8

Browse files
committed
test: add smart-default values tests
1 parent dc9cf8c commit c184da8

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

examples/lock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rs_consul::{Config, Consul, CreateACLTokenPayload, types::*};
1+
use rs_consul::{Config, Consul, types::*};
22

33
#[tokio::main] // Enables async main
44
async fn main() {

src/types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,15 @@ pub struct LockRequest<'a> {
241241
/// When locks are forcibly expired, such as when following the leader election pattern in an application, sessions may not be reaped for up to double this TTL, so long TTL values (> 1 hour) should be avoided.
242242
/// Defaults to 10 seconds.
243243
#[default(_code = "Duration::from_secs(10)")]
244-
#[builder(default)]
244+
#[builder(default = Duration::from_secs(10))]
245245
pub timeout: Duration,
246246
/// Controls the behavior to take when a session is invalidated. See also [LockExpirationBehavior](consul::types::LockExpirationBehavior)
247247
#[builder(default)]
248248
pub behavior: LockExpirationBehavior,
249249
/// Specifies the duration for the lock delay.
250250
/// Defaults to 1 second.
251251
#[default(_code = "Duration::from_secs(1)")]
252-
#[builder(default)]
252+
#[builder(default = Duration::from_secs(1))]
253253
pub lock_delay: Duration,
254254
}
255255

@@ -294,7 +294,7 @@ pub(crate) struct SessionResponse {
294294
pub(crate) id: String,
295295
}
296296

297-
#[derive(Clone, Debug, SmartDefault, Serialize, Deserialize, PartialEq, bon::Builder)]
297+
#[derive(Clone, Debug, SmartDefault, Serialize, Deserialize, PartialEq)]
298298
#[serde(rename_all = "PascalCase")]
299299
pub(crate) struct CreateSessionRequest {
300300
#[default(_code = "Duration::from_secs(0)")]

tests/test_runner.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,14 +576,16 @@ mod tests {
576576

577577
/// tests to ensure that Bon the builder can Build with minimal fields set
578578
mod minimal_setters_build_test {
579+
use std::time::Duration;
580+
579581
use rs_consul::{
580582
ACLTokenPolicyLink, CreateACLPolicyRequest, CreateACLTokenPayload, DeleteKeyRequest,
581583
DeregisterEntityPayload, GetNodesRequest, GetServiceNodesRequest, LockRequest,
582584
ReadKeyRequest, RegisterEntityCheck, RegisterEntityPayload, RegisterEntityService,
583585
};
584586

585587
#[test]
586-
fn test() {
588+
fn test_builder_default() {
587589
let _ = ACLTokenPolicyLink::builder().build();
588590
let _ = CreateACLTokenPayload::builder()
589591
.policies(vec![
@@ -601,7 +603,11 @@ mod minimal_setters_build_test {
601603
let _ = CreateACLPolicyRequest::builder()
602604
.name("hehe".to_owned())
603605
.build();
604-
let _ = LockRequest::builder().key("key-test").build();
606+
607+
let l_req = LockRequest::builder().key("key-test").build();
608+
assert_eq!(l_req.timeout, Duration::from_secs(10));
609+
assert_eq!(l_req.lock_delay, Duration::from_secs(1));
610+
605611
let _ = RegisterEntityPayload::builder()
606612
.Node("node-ddd".to_owned())
607613
.Address("2.2.2.2".to_owned())

0 commit comments

Comments
 (0)