Skip to content

Commit

Permalink
add unit tests for merge right
Browse files Browse the repository at this point in the history
  • Loading branch information
meskill committed Apr 15, 2024
1 parent 0a5181f commit 51f4dc6
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions src/config/config_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,93 @@ impl From<Config> for ConfigModule {
ConfigModule { config, input_types, output_types, ..Default::default() }
}
}

#[cfg(test)]
mod tests {
mod extensions {
mod merge_right {
use std::path::Path;

use prost_reflect::prost_types::FileDescriptorSet;

use crate::config::Extensions;
use crate::merge_right::MergeRight;

#[test]
fn grpc_file_descriptor_set_none() {
let extensions1 = Extensions::default();
let extensions2 = Extensions::default();

assert_eq!(
extensions1
.merge_right(extensions2)
.grpc_file_descriptor_set,
None
);
}

#[test]
fn grpc_file_descriptor_set_single() {
let greetings_path = Path::new("src/grpc/tests/proto/greetings.proto");

let file_descriptor_set = protox::compile([greetings_path], ["."]).unwrap();
let extensions1 = Extensions {
grpc_file_descriptor_set: Some(file_descriptor_set.clone()),
..Default::default()
};
let extensions2 = Extensions::default();

assert_eq!(
extensions1
.merge_right(extensions2)
.grpc_file_descriptor_set,
Some(file_descriptor_set.clone())
);

let extensions1 = Extensions::default();
let extensions2 = Extensions {
grpc_file_descriptor_set: Some(file_descriptor_set.clone()),
..Default::default()
};

assert_eq!(
extensions1
.merge_right(extensions2)
.grpc_file_descriptor_set,
Some(file_descriptor_set)
);
}

#[test]
fn grpc_file_descriptor_set_both() {
let greetings_path = Path::new("src/grpc/tests/proto/greetings.proto");
let news_path = Path::new("src/grpc/tests/proto/news.proto");

let file_descriptor_set_greetings =
protox::compile([greetings_path], ["."]).unwrap();
let file_descriptor_set_news = protox::compile([news_path], ["."]).unwrap();
let extensions1 = Extensions {
grpc_file_descriptor_set: Some(file_descriptor_set_greetings.clone()),
..Default::default()
};
let extensions2 = Extensions {
grpc_file_descriptor_set: Some(file_descriptor_set_news.clone()),
..Default::default()
};

assert_eq!(
extensions1
.merge_right(extensions2)
.grpc_file_descriptor_set,
Some(FileDescriptorSet {
file: file_descriptor_set_greetings
.file
.into_iter()
.chain(file_descriptor_set_news.file)
.collect()
})
);
}
}
}
}

0 comments on commit 51f4dc6

Please sign in to comment.