Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for runtime.txt containing invalid unicode #147

Merged
merged 1 commit into from
Nov 27, 2023
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
4 changes: 2 additions & 2 deletions src/layers/pip_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ mod tests {

assert_eq!(
utils::environment_as_sorted_vector(&layer_env.apply(Scope::Build, &base_env)),
vec![("PYTHONUSERBASE", "/layers/dependencies")]
[("PYTHONUSERBASE", "/layers/dependencies")]
);
assert_eq!(
utils::environment_as_sorted_vector(&layer_env.apply(Scope::Launch, &base_env)),
vec![("PYTHONUSERBASE", "/layers/dependencies")]
[("PYTHONUSERBASE", "/layers/dependencies")]
);
}
}
12 changes: 6 additions & 6 deletions src/layers/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ mod tests {
};
assert_eq!(
cache_invalidation_reasons(&cached_metadata, &new_metadata),
vec!["The Python version has changed from 3.11.0 to 3.11.1"]
["The Python version has changed from 3.11.0 to 3.11.1"]
);
}

Expand All @@ -503,7 +503,7 @@ mod tests {
};
assert_eq!(
cache_invalidation_reasons(&cached_metadata, &new_metadata),
vec![
[
"The stack has changed from heroku-20 to heroku-22",
"The Python version has changed from 3.9.0 to 3.11.1",
"The pip version has changed from A.B.C to A.B.C-new",
Expand All @@ -527,7 +527,7 @@ mod tests {
// Remember to force invalidation of the cached layer if these env vars ever change.
assert_eq!(
utils::environment_as_sorted_vector(&layer_env.apply_to_empty(Scope::Build)),
vec![
[
("CPATH", "/layers/python/include/python3.9"),
("LANG", "C.UTF-8"),
("PIP_DISABLE_PIP_VERSION_CHECK", "1"),
Expand All @@ -539,7 +539,7 @@ mod tests {
);
assert_eq!(
utils::environment_as_sorted_vector(&layer_env.apply_to_empty(Scope::Launch)),
vec![
[
("CPATH", "/layers/python/include/python3.9"),
("LANG", "C.UTF-8"),
("PIP_DISABLE_PIP_VERSION_CHECK", "1"),
Expand Down Expand Up @@ -573,7 +573,7 @@ mod tests {
// Remember to force invalidation of the cached layer if these env vars ever change.
assert_eq!(
utils::environment_as_sorted_vector(&layer_env.apply(Scope::Build, &base_env)),
vec![
[
("CPATH", "/layers/python/include/python3.11:/base"),
("LANG", "C.UTF-8"),
("PIP_DISABLE_PIP_VERSION_CHECK", "1"),
Expand All @@ -585,7 +585,7 @@ mod tests {
);
assert_eq!(
utils::environment_as_sorted_vector(&layer_env.apply(Scope::Launch, &base_env)),
vec![
[
("CPATH", "/layers/python/include/python3.11:/base"),
("LANG", "C.UTF-8"),
("PIP_DISABLE_PIP_VERSION_CHECK", "1"),
Expand Down
4 changes: 4 additions & 0 deletions src/runtime_txt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ mod tests {
read_version(Path::new("tests/fixtures/empty/.gitkeep")).unwrap_err(),
RuntimeTxtError::Read(_)
));
assert!(matches!(
read_version(Path::new("tests/fixtures/runtime_txt_invalid_unicode")).unwrap_err(),
RuntimeTxtError::Read(_)
));
}

#[test]
Expand Down
Empty file.
1 change: 1 addition & 0 deletions tests/fixtures/runtime_txt_invalid_unicode/runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
��
2 changes: 1 addition & 1 deletion tests/pip_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ fn pip_cache_invalidation_and_metadata_compatibility() {
let config = BuildConfig::new(builder(), "tests/fixtures/pip_basic");

TestRunner::default().build(
config.clone().buildpacks(vec![BuildpackReference::Other(
config.clone().buildpacks([BuildpackReference::Other(
"docker://docker.io/heroku/buildpack-python:0.1.0".to_string(),
)]),
|context| {
Expand Down
20 changes: 20 additions & 0 deletions tests/python_version_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,26 @@ fn builds_with_python_version(fixture_path: &str, python_version: &str) {
});
}

#[test]
#[ignore = "integration test"]
fn runtime_txt_io_error() {
TestRunner::default().build(
BuildConfig::new(builder(), "tests/fixtures/runtime_txt_invalid_unicode")
.expected_pack_result(PackResult::Failure),
|context| {
assert_contains!(
context.pack_stderr,
&formatdoc! {"
[Error: Unable to read runtime.txt]
An unexpected error occurred whilst reading the (optional) runtime.txt file.

Details: I/O Error: stream did not contain valid UTF-8
"}
);
},
);
}

#[test]
#[ignore = "integration test"]
fn runtime_txt_invalid_version() {
Expand Down