-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/output_json
- Loading branch information
Showing
12 changed files
with
884 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Constant provider | ||
------- | ||
|
||
### string | ||
#### unique value | ||
```yaml | ||
- name: constant_as_string | ||
provider: Constant.string | ||
data: trout | ||
``` | ||
#### list of values | ||
```yaml | ||
- name: list_of_constants_as_string | ||
provider: Constant.string | ||
data: [trout, salmon, carp] | ||
``` | ||
#### list of weighted values | ||
```yaml | ||
- name: list_of_weighted_constants_as_string | ||
provider: Constant.string | ||
data: | ||
- value: trout | ||
- value: salmon | ||
weight: 8 | ||
- value: carp | ||
``` | ||
Data value can be unique value, a list of values or a dictionnary. | ||
Integer, float or string can be specify into the configuration but the result will be stored as a string. | ||
If a unique value is specified, all lines will have this value. | ||
If a list of values is specified, value will randomly assigned for each line. | ||
If a weighted list of values is specified, value will weighted randomly assigned for each line: for example is useful to generate data skewing. | ||
[Options](../options.md) are also possible. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use yaml_rust::Yaml; | ||
|
||
use crate::{errors::FakeLakeError, providers::provider::Provider}; | ||
|
||
use super::string; | ||
|
||
pub fn get_corresponding_provider( | ||
mut provider_split: std::str::Split<'_, char>, | ||
column: &Yaml, | ||
) -> Result<Box<dyn Provider>, FakeLakeError> { | ||
match provider_split.next() { | ||
Some("string") => Ok(string::new_from_yaml(column)), | ||
_ => Err(FakeLakeError::BadYAMLFormat("".to_string())), | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::get_corresponding_provider; | ||
|
||
use yaml_rust::YamlLoader; | ||
|
||
#[test] | ||
fn given_string_should_return_provider() { | ||
let provider_name = "string"; | ||
let yaml_str = format!("name: is_suscribed{}provider: {}", '\n', provider_name); | ||
let column = &YamlLoader::load_from_str(yaml_str.as_str()).unwrap()[0]; | ||
|
||
let provider_split = provider_name.split('.'); | ||
match get_corresponding_provider(provider_split, column) { | ||
Ok(_) => (), | ||
_ => panic!(), | ||
} | ||
} | ||
|
||
#[test] | ||
fn given_wrong_provider_should_return_error() { | ||
let provider_name = "not_a_provider"; | ||
let yaml_str = format!("name: email{}provider: {}", '\n', provider_name); | ||
let column = &YamlLoader::load_from_str(yaml_str.as_str()).unwrap()[0]; | ||
|
||
let provider_split = provider_name.split('.'); | ||
match get_corresponding_provider(provider_split, column) { | ||
Err(_) => (), | ||
_ => panic!(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod builder; | ||
|
||
pub mod string; |
Oops, something went wrong.