Skip to content

Commit 0907771

Browse files
committed
[clone] test ls-remote V2
1 parent 8eea84e commit 0907771

File tree

4 files changed

+91
-25
lines changed

4 files changed

+91
-25
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ Please see _'Development Status'_ for a listing of all crates and their capabili
108108
* [x] ls-ref
109109
* [x] parse V1 refs as provided during handshake
110110
* [x] parse V2 refs
111+
* [x] initialize and validate command arguments and features sanely
111112
* [ ] push
112113
* [ ] shallow clones
113114
* [ ] API documentation with examples

git-protocol/src/fetch/tests/command.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ mod v1 {
6464
&[],
6565
);
6666
}
67+
68+
#[test]
69+
#[should_panic]
70+
fn unknown_argument() {
71+
Command::LsRefs.validate_argument_prefixes_or_panic(
72+
git_transport::Protocol::V1,
73+
&capabilities("do-not-matter"),
74+
&[b"definitely-nothing-we-know".as_bstr().into()],
75+
&[],
76+
);
77+
}
6778
}
6879
mod initial_arguments {
6980
use crate::fetch::Command;
@@ -156,14 +167,25 @@ mod v2 {
156167
use bstr::ByteSlice;
157168

158169
#[test]
159-
fn ref_prefixes_always_be_used() {
170+
fn ref_prefixes_can_always_be_used() {
160171
Command::LsRefs.validate_argument_prefixes_or_panic(
161172
git_transport::Protocol::V2,
162173
&capabilities("something else", "do-not-matter"),
163174
&[b"ref-prefix hello/".as_bstr().into()],
164175
&[],
165176
);
166177
}
178+
179+
#[test]
180+
#[should_panic]
181+
fn unknown_argument() {
182+
Command::LsRefs.validate_argument_prefixes_or_panic(
183+
git_transport::Protocol::V1,
184+
&capabilities("other", "do-not-matter"),
185+
&[b"definitely-nothing-we-know".as_bstr().into()],
186+
&[],
187+
);
188+
}
167189
}
168190
}
169191
}

git-protocol/tests/fetch/mod.rs

Lines changed: 67 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
use crate::fixture_bytes;
2+
use bstr::ByteSlice;
3+
use git_object::owned;
14
use git_protocol::fetch;
25
use git_transport::client::Capabilities;
36

@@ -22,21 +25,37 @@ impl fetch::Delegate for LsRemoteDelegate {
2225
}
2326
}
2427

28+
fn oid(hex_sha: &str) -> owned::Id {
29+
owned::Id::from_40_bytes_in_hex(hex_sha.as_bytes()).expect("valid input")
30+
}
31+
32+
fn transport<'a>(
33+
out: &'a mut Vec<u8>,
34+
path: &str,
35+
version: git_transport::Protocol,
36+
) -> git_transport::client::git::Connection<std::io::Cursor<Vec<u8>>, &'a mut Vec<u8>> {
37+
let response = fixture_bytes(path);
38+
git_transport::client::git::Connection::new(
39+
std::io::Cursor::new(response),
40+
out,
41+
version,
42+
b"does/not/matter".as_bstr().to_owned(),
43+
None::<(&str, _)>,
44+
git_transport::client::git::ConnectMode::Process,
45+
)
46+
}
47+
2548
mod v1 {
26-
use crate::{
27-
fetch::{CloneDelegate, LsRemoteDelegate},
28-
fixture_bytes,
29-
};
30-
use bstr::ByteSlice;
31-
use git_object::owned;
49+
use crate::fetch::{oid, transport, CloneDelegate, LsRemoteDelegate};
3250
use git_protocol::fetch;
51+
use git_transport::Protocol;
3352

3453
#[test]
3554
#[ignore]
3655
fn clone() -> crate::Result {
3756
let mut out = Vec::new();
3857
git_protocol::fetch(
39-
transport(&mut out, "v1/clone.response"),
58+
transport(&mut out, "v1/clone.response", Protocol::V1),
4059
&mut CloneDelegate,
4160
git_protocol::credentials::helper,
4261
)?;
@@ -48,7 +67,7 @@ mod v1 {
4867
let mut out = Vec::new();
4968
let mut delegate = LsRemoteDelegate::default();
5069
git_protocol::fetch(
51-
transport(&mut out, "v1/clone.response"),
70+
transport(&mut out, "v1/clone.response", Protocol::V1),
5271
&mut delegate,
5372
git_protocol::credentials::helper,
5473
)?;
@@ -73,23 +92,47 @@ mod v1 {
7392
);
7493
Ok(())
7594
}
95+
}
7696

77-
fn oid(hex_sha: &str) -> owned::Id {
78-
owned::Id::from_40_bytes_in_hex(hex_sha.as_bytes()).expect("valid input")
79-
}
97+
mod v2 {
98+
use crate::fetch::{oid, transport, LsRemoteDelegate};
99+
use bstr::ByteSlice;
100+
use git_protocol::fetch;
101+
use git_transport::Protocol;
102+
103+
#[test]
104+
fn ls_remote() -> crate::Result {
105+
let mut out = Vec::new();
106+
let mut delegate = LsRemoteDelegate::default();
107+
git_protocol::fetch(
108+
transport(&mut out, "v2/clone.response", Protocol::V2),
109+
&mut delegate,
110+
git_protocol::credentials::helper,
111+
)?;
80112

81-
fn transport<'a>(
82-
out: &'a mut Vec<u8>,
83-
path: &str,
84-
) -> git_transport::client::git::Connection<std::io::Cursor<Vec<u8>>, &'a mut Vec<u8>> {
85-
let response = fixture_bytes(path);
86-
git_transport::client::git::Connection::new(
87-
std::io::Cursor::new(response),
88-
out,
89-
git_transport::Protocol::V1,
90-
b"does/not/matter".as_bstr().to_owned(),
91-
None::<(&str, _)>,
92-
git_transport::client::git::ConnectMode::Process,
93-
)
113+
assert_eq!(
114+
delegate.refs,
115+
vec![
116+
fetch::Ref::Symbolic {
117+
path: "HEAD".into(),
118+
object: oid("808e50d724f604f69ab93c6da2919c014667bedb"),
119+
target: "refs/heads/master".into()
120+
},
121+
fetch::Ref::Direct {
122+
path: "refs/heads/master".into(),
123+
object: oid("808e50d724f604f69ab93c6da2919c014667bedb")
124+
}
125+
]
126+
);
127+
assert_eq!(
128+
out.as_bstr(),
129+
b"0014command=ls-refs
130+
001aagent=git/oxide-0.1.0
131+
0001000csymrefs
132+
0009peel
133+
00000000"
134+
.as_bstr()
135+
);
136+
Ok(())
94137
}
95138
}
1.36 KB
Binary file not shown.

0 commit comments

Comments
 (0)