Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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 }}
Expand Down
41 changes: 31 additions & 10 deletions crates/integration-tests/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,14 @@ impl TestEnvironment {
&["config", "user.email", "[email protected]"],
)?;

// 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"],
Expand Down Expand Up @@ -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.
Expand All @@ -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 {}",
Expand All @@ -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())
}

Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions crates/integration-tests/tests/integration/versioned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand All @@ -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();
Expand All @@ -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(())
}
Expand Down