1const PAGINATION_PROTO: &[u8] = include_bytes!("../proto/bones/v1/pagination.proto");
43const QUERIES_PROTO: &[u8] = include_bytes!("../proto/bones/v1/queries.proto");
44const ERRORS_PROTO: &[u8] = include_bytes!("../proto/bones/v1/errors.proto");
45const RATELIMIT_PROTO: &[u8] = include_bytes!("../proto/bones/v1/ratelimit.proto");
46const ANNOTATIONS_PROTO: &[u8] = include_bytes!("../proto/bones/v1/annotations.proto");
47
48pub fn files() -> impl Iterator<Item = (&'static str, &'static [u8])> {
55 [
56 ("bones/v1/pagination.proto", PAGINATION_PROTO),
57 ("bones/v1/queries.proto", QUERIES_PROTO),
58 ("bones/v1/errors.proto", ERRORS_PROTO),
59 ("bones/v1/ratelimit.proto", RATELIMIT_PROTO),
60 ("bones/v1/annotations.proto", ANNOTATIONS_PROTO),
61 ]
62 .into_iter()
63}
64
65#[cfg(test)]
66mod tests {
67 use super::*;
68
69 #[test]
70 fn ships_five_files() {
71 let v: Vec<_> = files().collect();
72 assert_eq!(v.len(), 5);
73 }
74
75 #[test]
76 fn relative_paths_are_unique() {
77 let mut paths: Vec<_> = files().map(|(p, _)| p).collect();
78 let n = paths.len();
79 paths.sort_unstable();
80 paths.dedup();
81 assert_eq!(paths.len(), n, "duplicate relative paths in files()");
82 }
83
84 #[test]
85 fn every_file_has_non_empty_bytes() {
86 for (path, bytes) in files() {
87 assert!(!bytes.is_empty(), "{path} embeds empty bytes");
88 }
89 }
90
91 #[test]
92 fn pagination_proto_declares_expected_messages() {
93 let body = std::str::from_utf8(PAGINATION_PROTO).expect("utf8");
94 for msg in [
95 "message PageRequest",
96 "message PageResponse",
97 "message OffsetPageRequest",
98 "message OffsetPageResponse",
99 ] {
100 assert!(body.contains(msg), "pagination.proto missing `{msg}`");
101 }
102 }
103
104 #[test]
105 fn annotations_proto_declares_authz_option() {
106 let body = std::str::from_utf8(ANNOTATIONS_PROTO).expect("utf8");
107 assert!(
108 body.contains("AuthzRule authz = 5102348;"),
109 "annotations.proto missing the authz method option"
110 );
111 for value in [
112 "AUTHZ_KIND_UNSPECIFIED",
113 "AUTHZ_KIND_SERVICE",
114 "AUTHZ_KIND_USER",
115 "AUTHZ_KIND_PUBLIC",
116 ] {
117 assert!(body.contains(value), "annotations.proto missing `{value}`");
118 }
119 }
120
121 #[test]
122 fn queries_proto_declares_filter_op_enum() {
123 let body = std::str::from_utf8(QUERIES_PROTO).expect("utf8");
124 assert!(
125 body.contains("enum FilterOp"),
126 "queries.proto missing FilterOp enum"
127 );
128 assert!(
129 body.contains("FILTER_OP_EQ"),
130 "queries.proto missing FILTER_OP_EQ"
131 );
132 }
133}