Skip to content

Commit 34641f1

Browse files
deadnewsj178
authored andcommitted
fix(golang): use GOTOOLCHAIN=local when probing system go
1 parent d1f84d5 commit 34641f1

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

crates/prek/src/languages/golang/installer.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ impl GoResult {
8080
let output = self
8181
.cmd("go version")
8282
.arg("version")
83+
.env(EnvVars::GOTOOLCHAIN, "local")
8384
.check(true)
8485
.output()
8586
.await?;
@@ -283,3 +284,43 @@ impl GoInstaller {
283284
Ok(None)
284285
}
285286
}
287+
288+
#[cfg(all(test, unix))]
289+
mod tests {
290+
use std::os::unix::fs::PermissionsExt;
291+
292+
use super::*;
293+
294+
#[tokio::test]
295+
async fn fill_version_uses_local_gotoolchain() -> anyhow::Result<()> {
296+
let temp_dir = tempfile::tempdir()?;
297+
let fake_go = temp_dir.path().join("go");
298+
fs_err::write(
299+
&fake_go,
300+
indoc::indoc! {r#"#!/bin/sh
301+
if [ "$1" = "version" ]; then
302+
if [ "${GOTOOLCHAIN:-}" = "local" ]; then
303+
printf 'go version go1.24.13 linux/amd64\n'
304+
else
305+
printf 'go version go1.26.0 linux/amd64\n'
306+
fi
307+
exit 0
308+
fi
309+
310+
printf 'unexpected args: %s\n' "$*" >&2
311+
exit 1
312+
"#},
313+
)?;
314+
315+
let mut permissions = fs_err::metadata(&fake_go)?.permissions();
316+
permissions.set_mode(0o755);
317+
fs_err::set_permissions(&fake_go, permissions)?;
318+
319+
let go = GoResult::from_executable(fake_go, true)
320+
.fill_version()
321+
.await?;
322+
323+
assert_eq!(go.version().to_string(), "1.24.13");
324+
Ok(())
325+
}
326+
}

0 commit comments

Comments
 (0)