mirror of
https://github.com/appleboy/drone-scp.git
synced 2026-06-04 18:23:59 +08:00
test: support windows testing. (#21)
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
|
||||
|
||||
package main
|
||||
|
||||
func getRealPath(path string) string {
|
||||
return path
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// +build windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func getRealPath(path string) string {
|
||||
return "/" + strings.Replace(strings.Replace(path, ":", "", -1), "\\", "/", -1)
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestGetRealPath(t *testing.T) {
|
||||
type args struct {
|
||||
path string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want string
|
||||
}{
|
||||
{
|
||||
"Test Windows Path",
|
||||
"C:\\Users\\appleboy\\test.txt",
|
||||
"/C/Users/appleboy/test.txt"
|
||||
}
|
||||
}
|
||||
for _, tt := range tests {
|
||||
if got := getRealPath(tt.args.path); got != tt.want {
|
||||
t.Errorf("%q. getRealPath() = %v, want %v", tt.name, got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
@@ -100,13 +99,7 @@ func (p Plugin) Exec() error {
|
||||
|
||||
// run archive command
|
||||
log.Println("tar all files into " + tar)
|
||||
var args []string
|
||||
if runtime.GOOS == "windows" {
|
||||
newTar := "/" + strings.Replace(strings.Replace(tar, ":", "", -1), "\\", "/", -1)
|
||||
args = append(append([]string{}, "-cf", newTar), files...)
|
||||
} else {
|
||||
args = append(append([]string{}, "-cf", tar), files...)
|
||||
}
|
||||
args := append(append([]string{}, "-cf", getRealPath(tar)), files...)
|
||||
|
||||
cmd := exec.Command("tar", args...)
|
||||
cmd.Stdout = os.Stdout
|
||||
|
||||
Reference in New Issue
Block a user