diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9ef70dd..0eaa237 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,7 +32,7 @@ jobs: run: just rustdoc - name: Check for differences run: git diff --exit-code - + build-and-test: name: Build and test runs-on: ${{ matrix.os }} @@ -45,11 +45,11 @@ jobs: env: RUSTFLAGS: -D warnings steps: - - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - # The e2e-example tests require origin/main to be present. - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 with: - ref: main + # We need to fetch the entire history so the tests can run merge-base + # operations. + fetch-depth: 0 - uses: dtolnay/rust-toolchain@master with: toolchain: ${{ matrix.rust-version }} diff --git a/crates/integration-tests/src/common/mod.rs b/crates/integration-tests/src/common/mod.rs index f23d19b..7c8a2a1 100644 --- a/crates/integration-tests/src/common/mod.rs +++ b/crates/integration-tests/src/common/mod.rs @@ -53,9 +53,14 @@ impl TestEnvironment { &["config", "user.email", "test@example.com"], )?; - // Create initial commit to establish git history. + // Create initial commit to establish git history, including disabling + // Windows line endings. + workspace_root.child(".gitattributes").write_str("* -text\n")?; workspace_root.child("README.md").write_str("# Test workspace\n")?; - Self::run_git_command(&workspace_root, &["add", "README.md"])?; + Self::run_git_command( + &workspace_root, + &["add", ".gitattributes", "README.md"], + )?; Self::run_git_command( &workspace_root, &["commit", "-m", "initial commit"], @@ -126,14 +131,16 @@ impl TestEnvironment { api_ident: &str, version: &str, ) -> bool { - // Versioned documents are stored in subdirectories like: documents/api/api-version-hash.json + // Versioned documents are stored in subdirectories like: + // documents/api/api-version-hash.json. let pattern = format!("documents/{}/{}-{}-", api_ident, api_ident, version); - if let Ok(files) = self.list_document_files() { - files.iter().any(|f| f.to_string().starts_with(&pattern)) - } else { - false - } + let files = self + .list_document_files() + .expect("reading document files succeeded"); + files + .iter() + .any(|f| rel_path_forward_slashes(f.as_ref()).starts_with(&pattern)) } /// Read the content of a versioned API document for a specific version. @@ -149,7 +156,9 @@ impl TestEnvironment { let matching_file = files .iter() - .find(|f| f.to_string().starts_with(&pattern)) + .find(|f| { + rel_path_forward_slashes(f.as_ref()).starts_with(&pattern) + }) .ok_or_else(|| { anyhow!( "No versioned document found for {} version {}", @@ -171,7 +180,9 @@ impl TestEnvironment { Ok(files .into_iter() - .filter(|f| f.to_string().starts_with(&prefix)) + .filter(|f| { + rel_path_forward_slashes(f.as_ref()).starts_with(&prefix) + }) .collect()) } @@ -307,6 +318,16 @@ impl TestEnvironment { } } +#[cfg(windows)] +pub fn rel_path_forward_slashes(path: &str) -> String { + path.replace('\\', "/") +} + +#[cfg(not(windows))] +pub fn rel_path_forward_slashes(path: &str) -> String { + path.to_string() +} + /// Create a versioned health API test configuration. pub fn versioned_health_test_api() -> ManagedApiConfig { ManagedApiConfig { diff --git a/crates/integration-tests/tests/integration/versioned.rs b/crates/integration-tests/tests/integration/versioned.rs index d682941..4a0475f 100644 --- a/crates/integration-tests/tests/integration/versioned.rs +++ b/crates/integration-tests/tests/integration/versioned.rs @@ -177,7 +177,7 @@ fn test_mixed_lockstep_and_versioned_apis() -> Result<()> { let lockstep_files: Vec<_> = all_files .iter() .filter(|f| { - let path_str = f.to_string(); + let path_str = rel_path_forward_slashes(f.as_ref()); f.extension() == Some("json") && path_str.starts_with("documents/") && !path_str[10..].contains('/') // No subdirectories after "documents/" @@ -186,7 +186,7 @@ fn test_mixed_lockstep_and_versioned_apis() -> Result<()> { let versioned_files: Vec<_> = all_files .iter() .filter(|f| { - let path_str = f.to_string(); + let path_str = rel_path_forward_slashes(f.as_ref()); path_str.starts_with("documents/") && path_str[10..].contains('/') // Has subdirectories }) .collect(); @@ -195,7 +195,7 @@ fn test_mixed_lockstep_and_versioned_apis() -> Result<()> { assert_eq!(lockstep_files.len(), 2); // Should have versioned files (each API has 4 files: 3 versions + latest). - assert!(versioned_files.len() >= 8); + assert_eq!(versioned_files.len(), 8); Ok(()) }