Skip to content

Commit

Permalink
Merge pull request #104 from andyzhangx/win-ut
Browse files Browse the repository at this point in the history
test: fix windows unit test
  • Loading branch information
andyzhangx committed Sep 7, 2020
2 parents cf25556 + bfc941f commit ac86adb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
1 change: 0 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ https://git.k8s.io/community/contributors/devel/release.md#issue-kind-label
<!--
Add one of the following kinds:
/kind bug
/kind test
/kind cleanup
/kind documentation
/kind feature
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,4 @@ jobs:
go build -a -o _output/smbplugin.exe ./pkg/smbplugin
- name: Run Windows Unit Tests
run: |
go test -v -race ./pkg/smb/...
go test -v -race ./pkg/csi-common/...
go test -v -race ./pkg/mounter/...
go test -v -race ./pkg/...
16 changes: 4 additions & 12 deletions pkg/smb/nodeserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"fmt"
"os"
"reflect"
"runtime"
"syscall"
"testing"

Expand All @@ -38,15 +37,8 @@ const (
targetTest = "./target_test"
)

// skip test if running on windows
func skipTestIfWindows(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Skipping test on Windows")
}
}

func TestNodeStageVolume(t *testing.T) {
skipTestIfWindows(t)
skipIfTestingOnWindows(t)

stdVolCap := csi.VolumeCapability{
AccessType: &csi.VolumeCapability_Mount{
Expand Down Expand Up @@ -190,7 +182,7 @@ func TestNodeExpandVolume(t *testing.T) {
}

func TestNodePublishVolume(t *testing.T) {
skipTestIfWindows(t)
skipIfTestingOnWindows(t)
volumeCap := csi.VolumeCapability_AccessMode{Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER}
errorMountSource := "./error_mount_source"
alreadyMountedTarget := "./false_is_likely_exist_target"
Expand Down Expand Up @@ -294,7 +286,7 @@ func TestNodePublishVolume(t *testing.T) {
}

func TestNodeUnpublishVolume(t *testing.T) {
skipTestIfWindows(t)
skipIfTestingOnWindows(t)
errorTarget := "./error_is_likely_target"
targetFile := "./abc.go"

Expand Down Expand Up @@ -346,7 +338,7 @@ func TestNodeUnpublishVolume(t *testing.T) {
}

func TestNodeUnstageVolume(t *testing.T) {
skipTestIfWindows(t)
skipIfTestingOnWindows(t)
errorTarget := "./error_is_likely_target"
targetFile := "./abc.go"

Expand Down
15 changes: 10 additions & 5 deletions pkg/smb/smb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -30,10 +31,7 @@ const (
)

func NewFakeDriver() *Driver {

driver := NewDriver(fakeNodeID)

return driver
return NewDriver(fakeNodeID)
}

func TestNewFakeDriver(t *testing.T) {
Expand All @@ -42,8 +40,15 @@ func TestNewFakeDriver(t *testing.T) {
assert.NotNil(t, d)
}

// skip test if running on windows
func skipIfTestingOnWindows(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Skipping test on Windows")
}
}

func TestIsCorruptedDir(t *testing.T) {
skipTestIfWindows(t)
skipIfTestingOnWindows(t)
existingMountPath, err := ioutil.TempDir(os.TempDir(), "csi-mount-test")
if err != nil {
t.Fatalf("failed to create tmp dir: %v", err)
Expand Down

0 comments on commit ac86adb

Please sign in to comment.