From 2fa52bc8b4e30e0e7be9cd58f12fc2e7671ddc76 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 13 Nov 2025 19:56:13 +0000 Subject: [PATCH] fix: Address various issues in compile, run, and matrix tests This commit addresses three separate issues: 1. **cmd/compile.go**: The `Borgfile` parsing now returns an error for unknown instructions instead of silently ignoring them. 2. **cmd/run_test.go**: The `execCommand` mock is now properly cleaned up after the test, preventing it from leaking into other tests. 3. **pkg/matrix/matrix_test.go**: The EOF check in the tar reader loop now uses a direct error comparison (`io.EOF`) instead of a string comparison. --- cmd/compile.go | 2 ++ cmd/run_test.go | 4 ++++ pkg/matrix/matrix_test.go | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/compile.go b/cmd/compile.go index 62308e9..c30e643 100644 --- a/cmd/compile.go +++ b/cmd/compile.go @@ -44,6 +44,8 @@ var compileCmd = &cobra.Command{ return err } m.RootFS.AddData(dest, data) + default: + return fmt.Errorf("unknown instruction: %s", parts[0]) } } diff --git a/cmd/run_test.go b/cmd/run_test.go index 4b93c09..7357ecf 100644 --- a/cmd/run_test.go +++ b/cmd/run_test.go @@ -65,7 +65,11 @@ func TestRunCmd_Good(t *testing.T) { } // Mock the exec.Command function. + origExecCommand := execCommand execCommand = helperProcess + t.Cleanup(func() { + execCommand = origExecCommand + }) // Run the run command. rootCmd := NewRootCmd() diff --git a/pkg/matrix/matrix_test.go b/pkg/matrix/matrix_test.go index 6c6567c..25013f4 100644 --- a/pkg/matrix/matrix_test.go +++ b/pkg/matrix/matrix_test.go @@ -3,6 +3,7 @@ package matrix import ( "archive/tar" "bytes" + "io" "testing" "github.com/Snider/Borg/pkg/datanode" @@ -60,7 +61,7 @@ func TestToTar(t *testing.T) { for { header, err := tr.Next() if err != nil { - if err.Error() == "EOF" { + if err == io.EOF { break } t.Fatalf("failed to read tar header: %v", err)