History

[git-protocol] move everything into `blocking_io` for later translation…

…into async-io, as usual.

Sebastian Thiel committed 5 years ago

Commit fa033741 parent 0d39b5d12 files · +295 −254Browse files

Showing the changes to git-protocol/src/fetch/blocking_io/tests/command.rs (1 of 12 files). Show all

Unified · Split

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