Browse Source

fix test cases on Windows

SysProcAttr.Credential is not available on Windows we need to move the
WrapCmd test in a separate file to be able to build test cases on Windows,
skipping the test is not enough
Nicola Murino 5 years ago
parent
commit
f49c280a7f
2 changed files with 19 additions and 15 deletions
  1. 0 15
      sftpd/internal_test.go
  2. 19 0
      sftpd/internal_unix_test.go

+ 0 - 15
sftpd/internal_test.go

@@ -7,7 +7,6 @@ import (
 	"io/ioutil"
 	"net"
 	"os"
-	"os/exec"
 	"runtime"
 	"strings"
 	"testing"
@@ -1213,17 +1212,3 @@ func TestSFTPExtensions(t *testing.T) {
 	}
 	sftpExtensions = initialSFTPExtensions
 }
-
-func TestWrapCmd(t *testing.T) {
-	if runtime.GOOS == "windows" {
-		t.Skip("executing a command as another uid/gid is not supported on Windows")
-	}
-	cmd := exec.Command("ls")
-	cmd = wrapCmd(cmd, 1000, 1001)
-	if cmd.SysProcAttr.Credential.Uid != 1000 {
-		t.Errorf("unexpected uid")
-	}
-	if cmd.SysProcAttr.Credential.Gid != 1001 {
-		t.Errorf("unexpected gid")
-	}
-}

+ 19 - 0
sftpd/internal_unix_test.go

@@ -0,0 +1,19 @@
+// +build !windows
+
+package sftpd
+
+import (
+	"os/exec"
+	"testing"
+)
+
+func TestWrapCmd(t *testing.T) {
+	cmd := exec.Command("ls")
+	cmd = wrapCmd(cmd, 1000, 1001)
+	if cmd.SysProcAttr.Credential.Uid != 1000 {
+		t.Errorf("unexpected uid")
+	}
+	if cmd.SysProcAttr.Credential.Gid != 1001 {
+		t.Errorf("unexpected gid")
+	}
+}