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/tests/command.rs (1 of 12 files). Show all

Unified · Split

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