Skip to content

Commit 7eb6337

Browse files
authored
Windows fixes (#6)
1 parent 62a9ae0 commit 7eb6337

File tree

3 files changed

+38
-17
lines changed

3 files changed

+38
-17
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
run: just rustdoc
3333
- name: Check for differences
3434
run: git diff --exit-code
35-
35+
3636
build-and-test:
3737
name: Build and test
3838
runs-on: ${{ matrix.os }}
@@ -45,11 +45,11 @@ jobs:
4545
env:
4646
RUSTFLAGS: -D warnings
4747
steps:
48-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
49-
# The e2e-example tests require origin/main to be present.
5048
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
5149
with:
52-
ref: main
50+
# We need to fetch the entire history so the tests can run merge-base
51+
# operations.
52+
fetch-depth: 0
5353
- uses: dtolnay/rust-toolchain@master
5454
with:
5555
toolchain: ${{ matrix.rust-version }}

crates/integration-tests/src/common/mod.rs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,14 @@ impl TestEnvironment {
5353
&["config", "user.email", "[email protected]"],
5454
)?;
5555

56-
// Create initial commit to establish git history.
56+
// Create initial commit to establish git history, including disabling
57+
// Windows line endings.
58+
workspace_root.child(".gitattributes").write_str("* -text\n")?;
5759
workspace_root.child("README.md").write_str("# Test workspace\n")?;
58-
Self::run_git_command(&workspace_root, &["add", "README.md"])?;
60+
Self::run_git_command(
61+
&workspace_root,
62+
&["add", ".gitattributes", "README.md"],
63+
)?;
5964
Self::run_git_command(
6065
&workspace_root,
6166
&["commit", "-m", "initial commit"],
@@ -126,14 +131,16 @@ impl TestEnvironment {
126131
api_ident: &str,
127132
version: &str,
128133
) -> bool {
129-
// Versioned documents are stored in subdirectories like: documents/api/api-version-hash.json
134+
// Versioned documents are stored in subdirectories like:
135+
// documents/api/api-version-hash.json.
130136
let pattern =
131137
format!("documents/{}/{}-{}-", api_ident, api_ident, version);
132-
if let Ok(files) = self.list_document_files() {
133-
files.iter().any(|f| f.to_string().starts_with(&pattern))
134-
} else {
135-
false
136-
}
138+
let files = self
139+
.list_document_files()
140+
.expect("reading document files succeeded");
141+
files
142+
.iter()
143+
.any(|f| rel_path_forward_slashes(f.as_ref()).starts_with(&pattern))
137144
}
138145

139146
/// Read the content of a versioned API document for a specific version.
@@ -149,7 +156,9 @@ impl TestEnvironment {
149156

150157
let matching_file = files
151158
.iter()
152-
.find(|f| f.to_string().starts_with(&pattern))
159+
.find(|f| {
160+
rel_path_forward_slashes(f.as_ref()).starts_with(&pattern)
161+
})
153162
.ok_or_else(|| {
154163
anyhow!(
155164
"No versioned document found for {} version {}",
@@ -171,7 +180,9 @@ impl TestEnvironment {
171180

172181
Ok(files
173182
.into_iter()
174-
.filter(|f| f.to_string().starts_with(&prefix))
183+
.filter(|f| {
184+
rel_path_forward_slashes(f.as_ref()).starts_with(&prefix)
185+
})
175186
.collect())
176187
}
177188

@@ -307,6 +318,16 @@ impl TestEnvironment {
307318
}
308319
}
309320

321+
#[cfg(windows)]
322+
pub fn rel_path_forward_slashes(path: &str) -> String {
323+
path.replace('\\', "/")
324+
}
325+
326+
#[cfg(not(windows))]
327+
pub fn rel_path_forward_slashes(path: &str) -> String {
328+
path.to_string()
329+
}
330+
310331
/// Create a versioned health API test configuration.
311332
pub fn versioned_health_test_api() -> ManagedApiConfig {
312333
ManagedApiConfig {

crates/integration-tests/tests/integration/versioned.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ fn test_mixed_lockstep_and_versioned_apis() -> Result<()> {
177177
let lockstep_files: Vec<_> = all_files
178178
.iter()
179179
.filter(|f| {
180-
let path_str = f.to_string();
180+
let path_str = rel_path_forward_slashes(f.as_ref());
181181
f.extension() == Some("json")
182182
&& path_str.starts_with("documents/")
183183
&& !path_str[10..].contains('/') // No subdirectories after "documents/"
@@ -186,7 +186,7 @@ fn test_mixed_lockstep_and_versioned_apis() -> Result<()> {
186186
let versioned_files: Vec<_> = all_files
187187
.iter()
188188
.filter(|f| {
189-
let path_str = f.to_string();
189+
let path_str = rel_path_forward_slashes(f.as_ref());
190190
path_str.starts_with("documents/") && path_str[10..].contains('/') // Has subdirectories
191191
})
192192
.collect();
@@ -195,7 +195,7 @@ fn test_mixed_lockstep_and_versioned_apis() -> Result<()> {
195195
assert_eq!(lockstep_files.len(), 2);
196196

197197
// Should have versioned files (each API has 4 files: 3 versions + latest).
198-
assert!(versioned_files.len() >= 8);
198+
assert_eq!(versioned_files.len(), 8);
199199

200200
Ok(())
201201
}

0 commit comments

Comments
 (0)