const PAGINATION_PROTO: &[u8] = include_bytes!("../proto/bones/v1/pagination.proto");
const QUERIES_PROTO: &[u8] = include_bytes!("../proto/bones/v1/queries.proto");
const ERRORS_PROTO: &[u8] = include_bytes!("../proto/bones/v1/errors.proto");
const RATELIMIT_PROTO: &[u8] = include_bytes!("../proto/bones/v1/ratelimit.proto");
pub fn files() -> impl Iterator<Item = (&'static str, &'static [u8])> {
[
("bones/v1/pagination.proto", PAGINATION_PROTO),
("bones/v1/queries.proto", QUERIES_PROTO),
("bones/v1/errors.proto", ERRORS_PROTO),
("bones/v1/ratelimit.proto", RATELIMIT_PROTO),
]
.into_iter()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn ships_four_files() {
let v: Vec<_> = files().collect();
assert_eq!(v.len(), 4);
}
#[test]
fn relative_paths_are_unique() {
let mut paths: Vec<_> = files().map(|(p, _)| p).collect();
let n = paths.len();
paths.sort_unstable();
paths.dedup();
assert_eq!(paths.len(), n, "duplicate relative paths in files()");
}
#[test]
fn every_file_has_non_empty_bytes() {
for (path, bytes) in files() {
assert!(!bytes.is_empty(), "{path} embeds empty bytes");
}
}
#[test]
fn pagination_proto_declares_expected_messages() {
let body = std::str::from_utf8(PAGINATION_PROTO).expect("utf8");
for msg in [
"message PageRequest",
"message PageResponse",
"message OffsetPageRequest",
"message OffsetPageResponse",
] {
assert!(body.contains(msg), "pagination.proto missing `{msg}`");
}
}
#[test]
fn queries_proto_declares_filter_op_enum() {
let body = std::str::from_utf8(QUERIES_PROTO).expect("utf8");
assert!(
body.contains("enum FilterOp"),
"queries.proto missing FilterOp enum"
);
assert!(
body.contains("FILTER_OP_EQ"),
"queries.proto missing FILTER_OP_EQ"
);
}
}