Skip to content

Commit

Permalink
Merge pull request #7 from Overmuse/SR/fix_deserialization
Browse files Browse the repository at this point in the history
fix deserialization
  • Loading branch information
SebRollen authored Jun 22, 2021
2 parents 248af2a + 50db69b commit d1bee35
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "kafka-settings"
version = "0.3.2"
version = "0.3.3"
authors = ["Sebastian Rollen <[email protected]>"]
edition = "2018"

Expand Down
5 changes: 3 additions & 2 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub enum SecurityProtocol {
#[derive(Debug, Clone, Deserialize)]
pub struct ConsumerSettings {
pub group_id: String,
#[serde(default)]
#[serde(default, deserialize_with = "from_str")]
pub unique_id: bool,
#[serde(deserialize_with = "vec_from_str")]
pub input_topics: Vec<String>,
Expand Down Expand Up @@ -136,12 +136,13 @@ mod test {
std::env::set_var("KAFKA__SECURITY_PROTOCOL", "PLAINTEXT");
std::env::set_var("KAFKA__GROUP_ID", "group");
std::env::set_var("KAFKA__INPUT_TOPICS", "A,B,C");
std::env::set_var("KAFKA__UNIQUE_ID", "true");
let mut s = Config::new();
s.merge(Environment::new().separator("__")).unwrap();
let settings: Test = s.try_into().unwrap();
let consumer_settings = settings.kafka.consumer.unwrap();
assert_eq!(consumer_settings.group_id, "group".to_string());
assert!(!consumer_settings.unique_id);
assert!(consumer_settings.unique_id);
assert_eq!(
consumer_settings.input_topics,
vec!["A".to_string(), "B".to_string(), "C".to_string()]
Expand Down

0 comments on commit d1bee35

Please sign in to comment.