From f49c280a7f258931a37375ecc91d2252752ad21d Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Thu, 26 Dec 2019 08:29:38 +0100 Subject: [PATCH] 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 --- sftpd/internal_test.go | 15 --------------- sftpd/internal_unix_test.go | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 15 deletions(-) create mode 100644 sftpd/internal_unix_test.go diff --git a/sftpd/internal_test.go b/sftpd/internal_test.go index 70379acf..e000be1c 100644 --- a/sftpd/internal_test.go +++ b/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") - } -} diff --git a/sftpd/internal_unix_test.go b/sftpd/internal_unix_test.go new file mode 100644 index 00000000..6ccf87be --- /dev/null +++ b/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") + } +}