Skip to content

Commit

Permalink
Fix unit tests and run in CI
Browse files Browse the repository at this point in the history
All tests for private repositories have been removed. They were broken
due to account rot, which also shows their fundamentally flawed nature.
A more proper solution would be to eventually spin up local servers in a
VM test.
  • Loading branch information
piegamesde committed Feb 25, 2025
1 parent 9d43294 commit f6cee04
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 255 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
run: nix-build
- name: Run pre-commit hooks
run: nix-shell --run "pre-commit run --all"
- name: Cargo test
run: nix-shell --run "cargo test"
- name: Test dev shell
# Simple check that the pins in the current repository are still working.
# Importantly, this will fail on any version mismatch, indicating that versions need to be upgraded.
Expand Down
76 changes: 0 additions & 76 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,3 @@ reqwest = { version = "^0.12.0", features = [ "rustls-tls" ], default-features =
async-trait = "0.1.52"
lenient_semver_parser = { version = "0.4.2", default-features = false }
lenient_version = { version = "0.4.2" }

[dev-dependencies]
envtestkit = "1.1.2"
176 changes: 0 additions & 176 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,9 +776,6 @@ fn latest_release<'a>(
#[cfg(test)]
mod test {
use super::*;
use envtestkit::lock::lock_test;
use envtestkit::set_env;
use std::ffi::OsString;

#[tokio::test]
async fn test_latest_release() {
Expand Down Expand Up @@ -1204,177 +1201,4 @@ mod test {
);
Ok(())
}

#[tokio::test]
async fn test_gitlab_private_update() -> Result<()> {
let _lock = lock_test();
let _test = set_env(OsString::from("GITLAB_TOKEN"), "some-invalid-value");
let pin = GitPin {
repository: Repository::GitLab {
repo_path: "npins-test/npins-private-test".into(),
server: "https://gitlab.com/".parse().unwrap(),
private_token: Some("glpat-MSsRZG1SNdJU1MzBNosV".into()),
},
branch: "main".into(),
submodules: false,
};
let version = pin.update(None).await?;
assert_eq!(
version,
git::GitRevision {
revision: "122f7072f026644fbed6abc17c5c2ab3ae107046".into(),
}
);
assert_eq!(
pin.fetch(&version).await?,
OptionalUrlHashes {
url: Some("https://gitlab.com/api/v4/projects/npins-test%2Fnpins-private-test/repository/archive.tar.gz?private_token=glpat-MSsRZG1SNdJU1MzBNosV".parse().unwrap()),
hash: "0vdhx429r1w6yffh8gqhyj5g7zkp5dab2jgc630wllplziyfqg7z".into(),
}
);
Ok(())
}

#[tokio::test]
async fn test_gitlab_private_release_update() -> Result<()> {
let _lock = lock_test();
let _test = set_env(OsString::from("GITLAB_TOKEN"), "some-invalid-value");
let mut pin = GitReleasePin {
repository: Repository::GitLab {
repo_path: "npins-test/npins-private-test".into(),
server: "https://gitlab.com/".parse().unwrap(),
private_token: Some("glpat-MSsRZG1SNdJU1MzBNosV".into()),
},
pre_releases: false,
version_upper_bound: Some("1.0.1".into()),
release_prefix: None,
submodules: false,
};
let version = pin.update(None).await?;
assert_eq!(
version,
GenericVersion {
version: "v1.0.0".into(),
}
);
// Test whether updating works
pin.version_upper_bound = None;
let version = pin.update(None).await?;
assert_eq!(
version,
GenericVersion {
version: "v1.0.1".into(),
}
);
// Test fetching
assert_eq!(
pin.fetch(&version).await?,
ReleasePinHashes {
revision: "122f7072f026644fbed6abc17c5c2ab3ae107046".into(),
url: Some("https://gitlab.com/api/v4/projects/npins-test%2Fnpins-private-test/repository/archive.tar.gz?private_token=glpat-MSsRZG1SNdJU1MzBNosV".parse().unwrap()),
hash: "0vdhx429r1w6yffh8gqhyj5g7zkp5dab2jgc630wllplziyfqg7z".into(),
}
);
Ok(())
}

#[tokio::test]
async fn test_gitlab_selfhosted_private_update() -> Result<()> {
let _lock = lock_test();
let _test = set_env(OsString::from("GITLAB_TOKEN"), "some-invalid-value");
let pin = GitPin {
repository: Repository::GitLab {
repo_path: "npins-test/npins-private-test".into(),
server: "https://git.helsinki.tools/".parse().unwrap(),
private_token: Some("xqgHNxVNdzvMy6cDvreJ".into()),
},
branch: "main".into(),
submodules: false,
};
let version = pin.update(None).await?;
assert_eq!(
version,
git::GitRevision {
revision: "122f7072f026644fbed6abc17c5c2ab3ae107046".into(),
}
);
assert_eq!(
pin.fetch(&version).await?,
OptionalUrlHashes {
url: Some("https://git.helsinki.tools/api/v4/projects/npins-test%2Fnpins-private-test/repository/archive.tar.gz?private_token=xqgHNxVNdzvMy6cDvreJ".parse().unwrap()),
hash: "0vdhx429r1w6yffh8gqhyj5g7zkp5dab2jgc630wllplziyfqg7z".into(),
}
);
Ok(())
}

#[tokio::test]
async fn test_gitlab_selfhosted_private_release_update() -> Result<()> {
let _lock = lock_test();
let _test = set_env(OsString::from("GITLAB_TOKEN"), "some-invalid-value");
let mut pin = GitReleasePin {
repository: Repository::GitLab {
repo_path: "npins-test/npins-private-test".into(),
server: "https://git.helsinki.tools/".parse().unwrap(),
private_token: Some("xqgHNxVNdzvMy6cDvreJ".into()),
},
pre_releases: false,
version_upper_bound: Some("1.0.1".into()),
release_prefix: None,
submodules: false,
};
let version = pin.update(None).await?;
assert_eq!(
version,
GenericVersion {
version: "v1.0.0".into(),
}
);
// Test whether updating works
pin.version_upper_bound = None;
let version = pin.update(None).await?;
assert_eq!(
version,
GenericVersion {
version: "v1.0.1".into(),
}
);
// Test fetching
assert_eq!(
pin.fetch(&version).await?,
ReleasePinHashes {
revision: "122f7072f026644fbed6abc17c5c2ab3ae107046".into(),
url: Some("https://git.helsinki.tools/api/v4/projects/npins-test%2Fnpins-private-test/repository/archive.tar.gz?private_token=xqgHNxVNdzvMy6cDvreJ".parse().unwrap()),
hash: "0vdhx429r1w6yffh8gqhyj5g7zkp5dab2jgc630wllplziyfqg7z".into(),
}
);
Ok(())
}

#[tokio::test]
async fn test_gitlab_private_update_from_env() -> Result<()> {
let _lock = lock_test();
let _test = set_env(OsString::from("GITLAB_TOKEN"), "glpat-MSsRZG1SNdJU1MzBNosV");
let pin = GitPin {
repository: Repository::GitLab {
repo_path: "npins-test/npins-private-test".into(),
server: "https://gitlab.com/".parse().unwrap(),
private_token: None,
},
branch: "main".into(),
submodules: false,
};
let version = pin.update(None).await?;
assert_eq!(
version,
git::GitRevision {
revision: "122f7072f026644fbed6abc17c5c2ab3ae107046".into(),
}
);
// The token was not written to the URL
assert_eq!(pin.repository.url(&version.revision)?.expect("no url returned"),
"https://gitlab.com/api/v4/projects/npins-test%2Fnpins-private-test/repository/archive.tar.gz?sha=122f7072f026644fbed6abc17c5c2ab3ae107046".parse().unwrap()
);
Ok(())
}
}

0 comments on commit f6cee04

Please sign in to comment.