-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
sub_factory_vector.rs
51 lines (43 loc) · 1.05 KB
/
sub_factory_vector.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
pub struct Post {
id: u16,
title: String,
approved: bool,
tags: Vec<Tag>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Tag {
id: u16,
name: String,
}
mod factory {
use crate::Post;
use crate::Tag;
beaver::define! {
pub PostFactory (Post) {
id -> |n| n,
title -> |n| format!("post-{}", n),
approved -> |_| true,
// use `build_list`
tags -> |n| TagFactory::build_list(3, n),
}
}
beaver::define! {
TagFactory (Tag) {
id -> |n| beaver::sequence(100, n),
name -> |n| format!("tag-{}", n),
}
}
}
fn main() {
use factory::PostFactory;
let post_factory = PostFactory::new();
let post1 = post_factory.build(|_| {});
let post2 = post_factory.build(|_| {});
println!("{:?}\n{:?}", post1, post2);
let posts = post_factory.build_list(3, |_| {});
for post in posts {
println!("{:?}", post);
}
}