Files
gitks/tests/refs_test.rs
T
zhenyi ab32e8826e feat(pack): add raw advertise refs and stateless protocol support
- Add raw flag to AdvertiseRefsRequest to enable raw pkt-line output
- Implement advertise_refs_raw function that calls git upload-pack/receive-pack with --advertise-refs
- Add stateless flag to GitProtocolFeatures for HTTP smart protocol support
- Modify upload_pack and receive_pack to accept stateless parameter
- Update command construction to include --stateless-rpc flag when enabled
- Add raw_data field to AdvertiseRefsResponse for raw output
- Update pack cache key computation to include raw service differentiation
- Initialize raw field to false in all request creation calls
2026-06-08 21:46:31 +08:00

66 lines
2.0 KiB
Rust

mod common;
fn hdr() -> gitks::pb::RepositoryHeader {
gitks::pb::RepositoryHeader {
relative_path: "test-repo".into(),
..Default::default()
}
}
#[tokio::test]
async fn test_list_refs_via_service() {
let (dir, _gb) = common::setup_bare_repo();
let svc = common::setup_service(dir.path());
// list_refs is called internally by advertise_refs
// We test it indirectly through the service
use gitks::pb::pack_service_server::PackService;
let result = svc
.advertise_refs(tonic::Request::new(gitks::pb::AdvertiseRefsRequest {
repository: Some(hdr()),
protocol: None,
service: String::new(),
raw: false,
}))
.await
.unwrap()
.into_inner();
assert!(!result.references.is_empty(), "should have refs");
let names: Vec<&str> = result.references.iter().map(|r| r.name.as_str()).collect();
assert!(
names.iter().any(|n| n.contains("refs/heads/main")),
"should have main branch, got: {:?}",
names
);
assert!(
names.iter().any(|n| n.contains("refs/heads/feature")),
"should have feature branch, got: {:?}",
names
);
assert!(
names.iter().any(|n| n.contains("refs/tags/v0.1.0")),
"should have tag, got: {:?}",
names
);
}
#[test]
fn test_list_refs_direct() {
let (_dir, gb) = common::setup_bare_repo();
let refs = gb.list_refs().expect("list_refs");
assert!(!refs.is_empty());
let names: Vec<&str> = refs.iter().map(|r| r.name.as_str()).collect();
assert!(names.iter().any(|n| n.contains("refs/heads/main")));
assert!(names.iter().any(|n| n.contains("refs/heads/feature")));
assert!(names.iter().any(|n| n.contains("refs/tags/v0.1.0")));
// Each ref should have a valid target OID
for r in &refs {
let oid = r.target_oid.as_ref().expect("ref should have target_oid");
assert!(!oid.hex.is_empty(), "OID hex should not be empty");
assert_eq!(oid.hex.len(), 40, "SHA-1 hex should be 40 chars");
}
}