summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-07-23 19:00:48 -0400
committerGitHub <noreply@github.com>2024-07-23 19:00:48 -0400
commit9114a2df69da9318c4e10887553b7daf77b0fa16 (patch)
tree2309817e74485f9fe8f7b79238afa026070b79df /tests
parent6055629ee7f48a4e887392ccac13788aa4008249 (diff)
fix(upgrade): do not error if config in cwd invalid (#24689)
``` > deno upgrade error: Unsupported lockfile version 'invalid'. Try upgrading Deno or recreating the lockfile. V:\scratch > V:\deno\target\debug\deno upgrade Looking up latest version Local deno version 1.45.3 is the most recent release ``` Closes #24517 Closes #20729
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/upgrade_tests.rs69
-rw-r--r--tests/util/server/src/fs.rs7
2 files changed, 59 insertions, 17 deletions
diff --git a/tests/integration/upgrade_tests.rs b/tests/integration/upgrade_tests.rs
index c016b61fc..54408907e 100644
--- a/tests/integration/upgrade_tests.rs
+++ b/tests/integration/upgrade_tests.rs
@@ -5,6 +5,7 @@ use std::process::Stdio;
use std::time::Instant;
use test_util as util;
use test_util::TempDir;
+use test_util::TestContext;
use util::TestContextBuilder;
// Warning: this test requires internet access.
@@ -144,15 +145,14 @@ fn upgrade_with_out_in_tmpdir() {
assert!(v.contains("1.11.5"));
}
-// Warning: this test requires internet access.
-// TODO(#7412): reenable. test is flaky
#[test]
-#[ignore]
fn upgrade_invalid_stable_version() {
- let temp_dir = TempDir::new();
+ let context = upgrade_context();
+ let temp_dir = context.temp_dir();
let exe_path = temp_dir.path().join("deno");
util::deno_exe_path().copy(&exe_path);
assert!(exe_path.exists());
+ exe_path.mark_executable();
let output = Command::new(&exe_path)
.arg("upgrade")
.arg("--version")
@@ -164,20 +164,19 @@ fn upgrade_invalid_stable_version() {
.unwrap();
assert!(!output.status.success());
assert_eq!(
- "error: Invalid semver passed\n",
+ "error: Invalid version passed\n",
util::strip_ansi_codes(&String::from_utf8(output.stderr).unwrap())
);
}
-// Warning: this test requires internet access.
-// TODO(#7412): reenable. test is flaky
#[test]
-#[ignore]
fn upgrade_invalid_canary_version() {
- let temp_dir = TempDir::new();
+ let context = upgrade_context();
+ let temp_dir = context.temp_dir();
let exe_path = temp_dir.path().join("deno");
util::deno_exe_path().copy(&exe_path);
assert!(exe_path.exists());
+ exe_path.mark_executable();
let output = Command::new(&exe_path)
.arg("upgrade")
.arg("--canary")
@@ -196,15 +195,40 @@ fn upgrade_invalid_canary_version() {
}
#[test]
+fn upgrade_invalid_lockfile() {
+ let context = upgrade_context();
+ let temp_dir = context.temp_dir();
+ temp_dir.write("deno.deno", r#"{ \"lock\": true }"#);
+ temp_dir.write(
+ "deno.lock",
+ r#"{
+ "version": "invalid",
+}"#,
+ );
+ let exe_path = temp_dir.path().join("deno");
+ util::deno_exe_path().copy(&exe_path);
+ assert!(exe_path.exists());
+ exe_path.mark_executable();
+ let output = Command::new(&exe_path)
+ .arg("upgrade")
+ .arg("--version")
+ .arg("foobar")
+ .stderr(Stdio::piped())
+ .spawn()
+ .unwrap()
+ .wait_with_output()
+ .unwrap();
+ assert!(!output.status.success());
+ // should make it here instead of erroring on an invalid lockfile
+ assert_eq!(
+ "error: Invalid version passed\n",
+ util::strip_ansi_codes(&String::from_utf8(output.stderr).unwrap())
+ );
+}
+
+#[test]
fn upgrade_prompt() {
- let context = TestContextBuilder::new()
- .use_http_server()
- .use_temp_cwd()
- .env(
- "DENO_DONT_USE_INTERNAL_BASE_UPGRADE_URL",
- "http://localhost:4545",
- )
- .build();
+ let context = upgrade_context();
let temp_dir = context.temp_dir();
// start a task that goes indefinitely in order to allow
// the upgrade check to occur
@@ -257,3 +281,14 @@ fn upgrade_lsp_repl_sleeps() {
let elapsed_secs = start_instant.elapsed().as_secs();
assert!(elapsed_secs < 94, "elapsed_secs: {}", elapsed_secs);
}
+
+fn upgrade_context() -> TestContext {
+ TestContextBuilder::new()
+ .use_http_server()
+ .use_temp_cwd()
+ .env(
+ "DENO_DONT_USE_INTERNAL_BASE_UPGRADE_URL",
+ "http://localhost:4545",
+ )
+ .build()
+}
diff --git a/tests/util/server/src/fs.rs b/tests/util/server/src/fs.rs
index 558d25ffb..fc27e4485 100644
--- a/tests/util/server/src/fs.rs
+++ b/tests/util/server/src/fs.rs
@@ -256,6 +256,13 @@ impl PathRef {
}
#[track_caller]
+ pub fn mark_executable(&self) {
+ if cfg!(unix) {
+ Command::new("chmod").arg("+x").arg(self).output().unwrap();
+ }
+ }
+
+ #[track_caller]
pub fn make_dir_readonly(&self) {
self.create_dir_all();
if cfg!(windows) {