Commit
+13 -6 +/-3 browse
1 | diff --git a/tests/common/mod.rs b/tests/common/mod.rs |
2 | index 1f32a64..8c4faf9 100644 |
3 | --- a/tests/common/mod.rs |
4 | +++ b/tests/common/mod.rs |
5 | @@ -20,12 +20,19 @@ |
6 | #![allow(unused)] |
7 | use std::fs::{self, File}; |
8 | use std::io; |
9 | + use std::net::IpAddr; |
10 | + use std::net::Ipv4Addr; |
11 | use std::net::SocketAddr; |
12 | use std::path::Path; |
13 | |
14 | use duct::cmd; |
15 | use rand::Rng; |
16 | |
17 | + /// Bind test server to localhost port 0. We don't want this server to be |
18 | + /// externally visible. |
19 | + pub const SERVER_ADDR: SocketAddr = |
20 | + SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 0); |
21 | + |
22 | /// A temporary git repository. |
23 | pub struct GitRepo { |
24 | repo: tempfile::TempDir, |
25 | diff --git a/tests/test_local.rs b/tests/test_local.rs |
26 | index 5c9a51e..c10560a 100644 |
27 | --- a/tests/test_local.rs |
28 | +++ b/tests/test_local.rs |
29 | @@ -30,7 +30,7 @@ use rand::SeedableRng; |
30 | use rudolfs::LocalServerBuilder; |
31 | use tokio::sync::oneshot; |
32 | |
33 | - use common::{init_logger, GitRepo}; |
34 | + use common::{init_logger, GitRepo, SERVER_ADDR}; |
35 | |
36 | #[tokio::test(flavor = "multi_thread")] |
37 | async fn local_smoke_test_encrypted() -> Result<(), Box<dyn std::error::Error>> |
38 | @@ -46,7 +46,7 @@ async fn local_smoke_test_encrypted() -> Result<(), Box<dyn std::error::Error>> |
39 | |
40 | let mut server = LocalServerBuilder::new(data.path().into()); |
41 | server.key(key); |
42 | - let server = server.spawn(SocketAddr::from(([0, 0, 0, 0], 0))).await?; |
43 | + let server = server.spawn(SERVER_ADDR).await?; |
44 | let addr = server.addr(); |
45 | |
46 | let (shutdown_tx, shutdown_rx) = oneshot::channel(); |
47 | @@ -77,7 +77,7 @@ async fn local_smoke_test_unencrypted() -> Result<(), Box<dyn std::error::Error> |
48 | let data = tempfile::TempDir::new()?; |
49 | |
50 | let server = LocalServerBuilder::new(data.path().into()); |
51 | - let server = server.spawn(SocketAddr::from(([0, 0, 0, 0], 0))).await?; |
52 | + let server = server.spawn(SERVER_ADDR).await?; |
53 | let addr = server.addr(); |
54 | |
55 | let (shutdown_tx, shutdown_rx) = oneshot::channel(); |
56 | diff --git a/tests/test_s3.rs b/tests/test_s3.rs |
57 | index 2cf9a8c..4479f63 100644 |
58 | --- a/tests/test_s3.rs |
59 | +++ b/tests/test_s3.rs |
60 | @@ -50,7 +50,7 @@ use rudolfs::S3ServerBuilder; |
61 | use serde::{Deserialize, Serialize}; |
62 | use tokio::sync::oneshot; |
63 | |
64 | - use common::{init_logger, GitRepo}; |
65 | + use common::{init_logger, GitRepo, SERVER_ADDR}; |
66 | |
67 | #[derive(Debug, Serialize, Deserialize)] |
68 | struct Credentials { |
69 | @@ -98,7 +98,7 @@ async fn s3_smoke_test_encrypted() -> Result<(), Box<dyn std::error::Error>> { |
70 | server.key(key); |
71 | server.prefix("test_lfs".into()); |
72 | |
73 | - let server = server.spawn(SocketAddr::from(([0, 0, 0, 0], 0))).await?; |
74 | + let server = server.spawn(SERVER_ADDR).await?; |
75 | let addr = server.addr(); |
76 | |
77 | let (shutdown_tx, shutdown_rx) = oneshot::channel(); |
78 | @@ -137,7 +137,7 @@ async fn s3_smoke_test_unencrypted() -> Result<(), Box<dyn std::error::Error>> { |
79 | let mut server = S3ServerBuilder::new(creds.bucket); |
80 | server.prefix("test_lfs".into()); |
81 | |
82 | - let server = server.spawn(SocketAddr::from(([0, 0, 0, 0], 0))).await?; |
83 | + let server = server.spawn(SERVER_ADDR).await?; |
84 | let addr = server.addr(); |
85 | |
86 | let (shutdown_tx, shutdown_rx) = oneshot::channel(); |