]> git.proxmox.com Git - rustc.git/blob - vendor/gix-protocol/src/command/tests.rs
New upstream version 1.70.0+dfsg2
[rustc.git] / vendor / gix-protocol / src / command / tests.rs
1 mod v1 {
2 fn capabilities(input: &str) -> gix_transport::client::Capabilities {
3 gix_transport::client::Capabilities::from_bytes(format!("\0{input}").as_bytes())
4 .expect("valid input capabilities")
5 .0
6 }
7
8 const GITHUB_CAPABILITIES: &str = "multi_ack thin-pack side-band ofs-delta shallow deepen-since deepen-not deepen-relative no-progress include-tag allow-tip-sha1-in-want allow-reachable-sha1-in-want no-done symref=HEAD:refs/heads/main filter agent=git/github-gdf51a71f0236";
9 mod fetch {
10 mod default_features {
11 use crate::{
12 command::tests::v1::{capabilities, GITHUB_CAPABILITIES},
13 Command,
14 };
15
16 #[test]
17 fn it_chooses_the_best_multi_ack_and_sideband() {
18 assert_eq!(
19 Command::Fetch.default_features(
20 gix_transport::Protocol::V1,
21 &capabilities("multi_ack side-band side-band-64k multi_ack_detailed")
22 ),
23 &[("side-band-64k", None), ("multi_ack_detailed", None),]
24 );
25 }
26
27 #[test]
28 fn it_chooses_all_supported_non_stacking_capabilities_and_leaves_no_progress() {
29 assert_eq!(
30 Command::Fetch.default_features(gix_transport::Protocol::V1, &capabilities(GITHUB_CAPABILITIES)),
31 &[
32 ("multi_ack", None),
33 ("thin-pack", None),
34 ("side-band", None),
35 ("ofs-delta", None),
36 ("shallow", None),
37 ("deepen-since", None),
38 ("deepen-not", None),
39 ("deepen-relative", None),
40 ("include-tag", None),
41 ("allow-tip-sha1-in-want", None),
42 ("allow-reachable-sha1-in-want", None),
43 ("no-done", None),
44 ("filter", None),
45 ],
46 "we don't enforce no-progress"
47 );
48 }
49 }
50 }
51 }
52
53 mod v2 {
54 use gix_transport::client::Capabilities;
55
56 fn capabilities(command: &str, input: &str) -> Capabilities {
57 Capabilities::from_lines(format!("version 2\n{command}={input}").into())
58 .expect("valid input for V2 capabilities")
59 }
60
61 mod fetch {
62 mod default_features {
63 use crate::{command::tests::v2::capabilities, Command};
64
65 #[test]
66 fn all_features() {
67 assert_eq!(
68 Command::Fetch.default_features(
69 gix_transport::Protocol::V2,
70 &capabilities("fetch", "shallow filter ref-in-want sideband-all packfile-uris")
71 ),
72 ["shallow", "filter", "ref-in-want", "sideband-all", "packfile-uris"]
73 .iter()
74 .map(|s| (*s, None))
75 .collect::<Vec<_>>()
76 )
77 }
78 }
79
80 mod initial_arguments {
81 use bstr::ByteSlice;
82
83 use crate::{command::tests::v2::capabilities, Command};
84
85 #[test]
86 fn for_all_features() {
87 assert_eq!(
88 Command::Fetch.initial_arguments(&Command::Fetch.default_features(
89 gix_transport::Protocol::V2,
90 &capabilities("fetch", "shallow filter sideband-all packfile-uris")
91 )),
92 ["thin-pack", "ofs-delta", "sideband-all"]
93 .iter()
94 .map(|s| s.as_bytes().as_bstr().to_owned())
95 .collect::<Vec<_>>(),
96 "packfile-uris isn't really supported that well and we don't support it either yet"
97 )
98 }
99 }
100 }
101
102 mod ls_refs {
103 mod default_features {
104 use crate::{command::tests::v2::capabilities, Command};
105
106 #[test]
107 fn default_as_there_are_no_features() {
108 assert_eq!(
109 Command::LsRefs.default_features(
110 gix_transport::Protocol::V2,
111 &capabilities("something-else", "does not matter as there are none")
112 ),
113 &[]
114 );
115 }
116 }
117
118 mod validate {
119 use bstr::ByteSlice;
120
121 use crate::{command::tests::v2::capabilities, Command};
122
123 #[test]
124 fn ref_prefixes_can_always_be_used() {
125 Command::LsRefs.validate_argument_prefixes_or_panic(
126 gix_transport::Protocol::V2,
127 &capabilities("something else", "do-not-matter"),
128 &[b"ref-prefix hello/".as_bstr().into()],
129 &[],
130 );
131 }
132
133 #[test]
134 #[should_panic]
135 fn unknown_argument() {
136 Command::LsRefs.validate_argument_prefixes_or_panic(
137 gix_transport::Protocol::V2,
138 &capabilities("other", "do-not-matter"),
139 &[b"definitely-nothing-we-know".as_bstr().into()],
140 &[],
141 );
142 }
143
144 #[test]
145 #[should_panic]
146 fn unknown_feature() {
147 Command::LsRefs.validate_argument_prefixes_or_panic(
148 gix_transport::Protocol::V2,
149 &capabilities("other", "do-not-matter"),
150 &[],
151 &[("some-feature-that-does-not-exist", None)],
152 );
153 }
154 }
155 }
156 }