diff --git a/commands_test.go b/commands_test.go index 8efe05b3..f9a71b8d 100644 --- a/commands_test.go +++ b/commands_test.go @@ -3,6 +3,7 @@ package main import ( "fmt" "os" + "runtime" "strings" "testing" @@ -279,7 +280,12 @@ func TestReadCmd_ErrorUnreadableFile(t *testing.T) { if result.Error == nil { t.Error("Expected command to fail due to unknown file") } - expectedOutput := `open fake-unknown: no such file or directory` + var expectedOutput string + if runtime.GOOS == "windows" { + expectedOutput = `open fake-unknown: The system cannot find the file specified.` + } else { + expectedOutput = `open fake-unknown: no such file or directory` + } assertResult(t, expectedOutput, result.Error.Error()) } @@ -493,7 +499,12 @@ func TestPrefixCmd_ErrorUnreadableFile(t *testing.T) { if result.Error == nil { t.Error("Expected command to fail due to unknown file") } - expectedOutput := `open fake-unknown: no such file or directory` + var expectedOutput string + if runtime.GOOS == "windows" { + expectedOutput = `open fake-unknown: The system cannot find the file specified.` + } else { + expectedOutput = `open fake-unknown: no such file or directory` + } assertResult(t, expectedOutput, result.Error.Error()) } @@ -693,7 +704,12 @@ func TestWriteCmd_ErrorUnreadableFile(t *testing.T) { if result.Error == nil { t.Error("Expected command to fail due to unknown file") } - expectedOutput := `open fake-unknown: no such file or directory` + var expectedOutput string + if runtime.GOOS == "windows" { + expectedOutput = `open fake-unknown: The system cannot find the file specified.` + } else { + expectedOutput = `open fake-unknown: no such file or directory` + } assertResult(t, expectedOutput, result.Error.Error()) } @@ -1019,7 +1035,12 @@ func TestMergeCmd_ErrorUnreadableFile(t *testing.T) { if result.Error == nil { t.Error("Expected command to fail due to unknown file") } - expectedOutput := `Error updating document at index 0: open fake-unknown: no such file or directory` + var expectedOutput string + if runtime.GOOS == "windows" { + expectedOutput = `Error updating document at index 0: open fake-unknown: The system cannot find the file specified.` + } else { + expectedOutput = `Error updating document at index 0: open fake-unknown: no such file or directory` + } assertResult(t, expectedOutput, result.Error.Error()) } diff --git a/yq.go b/yq.go index eca4e0a0..59adb652 100644 --- a/yq.go +++ b/yq.go @@ -462,11 +462,11 @@ func readAndUpdate(stdOut io.Writer, inputFile string, updateData updateDataFn) if err != nil { return err } - err = tempFile.Chmod(info.Mode()) + destinationName = tempFile.Name() + err = os.Chmod(destinationName, info.Mode()) if err != nil { return err } - destinationName = tempFile.Name() destination = tempFile defer func() { safelyCloseFile(tempFile) diff --git a/yq_test.go b/yq_test.go index 72d672e1..0701c8e0 100644 --- a/yq_test.go +++ b/yq_test.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "runtime" "testing" ) @@ -64,6 +65,11 @@ func TestNewYaml_WithUnknownScript(t *testing.T) { if err == nil { t.Error("Expected error due to unknown file") } - expectedOutput := `open fake-unknown: no such file or directory` + var expectedOutput string + if runtime.GOOS == "windows" { + expectedOutput = `open fake-unknown: The system cannot find the file specified.` + } else { + expectedOutput = `open fake-unknown: no such file or directory` + } assertResult(t, expectedOutput, err.Error()) }