Skip to content
Open
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
2 changes: 1 addition & 1 deletion path_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestGetRealPath(t *testing.T) {
}{
{
"Test Windows Path",
"C:\\Users\\appleboy\\test.txt",
args{"C:\\Users\\appleboy\\test.txt"},
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix: resolve compilation error in path_windows_test.go

Fixed test case structure where string was passed directly instead of
being wrapped in args struct, which caused build failure.

"/C/Users/appleboy/test.txt",
},
}
Expand Down
4 changes: 2 additions & 2 deletions plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (p *Plugin) removeAllDestFile() error {
},
}

_, _, _, err := ssh.Run("ver", p.Config.CommandTimeout)
_, _, _, err := ssh.Run("cmd /c ver 2>$null", p.Config.CommandTimeout)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This command string "cmd /c ver 2>$null" is also used on line 295 and in plugin_test.go. To improve maintainability and avoid magic strings, consider defining it as an exported constant at the package level. This makes the command's purpose clearer and centralizes it for future changes.

For example, you could add:

const WindowsDetectCmd = "cmd /c ver 2>$null"

Then, you can use WindowsDetectCmd in all three locations.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Execute Windows version command through CMD explicitly
This ensures compatibility when PowerShell is the default SSH shell,
as 'ver' command only exists in CMD, not PowerShell

systemType := "unix"
if err == nil {
systemType = "windows"
Expand Down Expand Up @@ -292,7 +292,7 @@ func (p *Plugin) Exec() error {
}

systemType := "unix"
_, _, _, err := ssh.Run("ver", p.Config.CommandTimeout)
_, _, _, err := ssh.Run("cmd /c ver 2>$null", p.Config.CommandTimeout)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

As with line 150, this command string is duplicated. Using a shared constant would improve code clarity and maintainability.

if err == nil {
systemType = "windows"
}
Expand Down
2 changes: 1 addition & 1 deletion plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ func TestRemoveDestFile(t *testing.T) {
DestFile: "/etc/resolv.conf",
}

_, _, _, err := ssh.Run("ver", plugin.Config.CommandTimeout)
_, _, _, err := ssh.Run("cmd /c ver 2>$null", plugin.Config.CommandTimeout)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This command string is also present in plugin.go. To ensure consistency between tests and implementation, it's best to define this as an exported constant in plugin.go and reuse it here.

systemType := "unix"
if err == nil {
systemType = "windows"
Expand Down