test: support windows testing. (#21)

This commit is contained in:
Bo-Yi Wu
2017-01-03 16:59:00 +08:00
committed by GitHub
parent b69d758088
commit 77dbb22aed
4 changed files with 44 additions and 8 deletions
+7
View File
@@ -0,0 +1,7 @@
// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
package main
func getRealPath(path string) string {
return path
}
+11
View File
@@ -0,0 +1,11 @@
// +build windows
package main
import (
"strings"
)
func getRealPath(path string) string {
return "/" + strings.Replace(strings.Replace(path, ":", "", -1), "\\", "/", -1)
}
+25
View File
@@ -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)
}
}
}
+1 -8
View File
@@ -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