Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Sep 4, 2020
1 parent 202383a commit b38290e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 52 deletions.
2 changes: 1 addition & 1 deletion git-transport/src/client/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
net::{TcpStream, ToSocketAddrs},
};

pub mod message {
pub(crate) mod message {
use crate::{Protocol, Service};
use bstr::{BString, ByteVec};

Expand Down
16 changes: 9 additions & 7 deletions git-transport/src/client/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use crate::{Protocol, Service};
use std::io;
use bstr::BString;
use std::{io, io::Write};

#[cfg(test)]
mod tests;

pub mod connect;
pub mod file;
Expand All @@ -10,17 +14,15 @@ pub mod ssh;
#[doc(inline)]
pub use connect::connect;

pub mod capabilities;
#[doc(inline)]
pub use capabilities::Capabilities;

#[cfg(feature = "http-client-curl")]
type HttpError = http::Error;
#[cfg(not(feature = "http-client-curl"))]
type HttpError = std::convert::Infallible;

pub mod capabilities;
use bstr::BString;
#[doc(inline)]
pub use capabilities::Capabilities;
use std::io::Write;

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error("An IO error occurred when talking to the server")]
Expand Down
42 changes: 42 additions & 0 deletions git-transport/src/client/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
mod connect_message {
use crate::{client::git, Protocol, Service};

#[test]
fn version_1_without_host_and_version() {
assert_eq!(
git::message::connect(Service::UploadPack, Protocol::V1, b"hello/world", None),
"git-upload-pack hello/world\0"
)
}
#[test]
fn version_2_without_host_and_version() {
assert_eq!(
git::message::connect(Service::UploadPack, Protocol::V2, b"hello\\world", None),
"git-upload-pack hello\\world\0\0version=2\0"
)
}
#[test]
fn with_host_without_port() {
assert_eq!(
git::message::connect(
Service::UploadPack,
Protocol::V1,
b"hello\\world",
Some(&("host".into(), None))
),
"git-upload-pack hello\\world\0host=host\0"
)
}
#[test]
fn with_host_with_port() {
assert_eq!(
git::message::connect(
Service::UploadPack,
Protocol::V1,
b"hello\\world",
Some(&("host".into(), Some(404)))
),
"git-upload-pack hello\\world\0host=host:404\0"
)
}
}
43 changes: 0 additions & 43 deletions git-transport/tests/client/git.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,3 @@
mod connect_message {
use git_transport::{client::git, Protocol, Service};

#[test]
fn version_1_without_host_and_version() {
assert_eq!(
git::message::connect(Service::UploadPack, Protocol::V1, b"hello/world", None),
"git-upload-pack hello/world\0"
)
}
#[test]
fn version_2_without_host_and_version() {
assert_eq!(
git::message::connect(Service::UploadPack, Protocol::V2, b"hello\\world", None),
"git-upload-pack hello\\world\0\0version=2\0"
)
}
#[test]
fn with_host_without_port() {
assert_eq!(
git::message::connect(
Service::UploadPack,
Protocol::V1,
b"hello\\world",
Some(&("host".into(), None))
),
"git-upload-pack hello\\world\0host=host\0"
)
}
#[test]
fn with_host_with_port() {
assert_eq!(
git::message::connect(
Service::UploadPack,
Protocol::V1,
b"hello\\world",
Some(&("host".into(), Some(404)))
),
"git-upload-pack hello\\world\0host=host:404\0"
)
}
}

use crate::fixture_bytes;
use bstr::ByteSlice;
use git_transport::{
Expand Down
2 changes: 1 addition & 1 deletion src/plumbing/lean/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::io::{self, stderr, stdout};

#[cfg(not(any(feature = "prodash-render-line-crossterm", feature = "prodash-render-line-termion")))]
fn prepare(verbose: bool, name: &str, _: impl Into<Option<ProgressRange>>) -> ((), Option<prodash::progress::Log>) {
super::init_env_logger(verbose);
crate::plumbing::init_env_logger(verbose);
((), Some(prodash::progress::Log::new(name, Some(1))))
}

Expand Down

0 comments on commit b38290e

Please sign in to comment.