From 82e9dcf024363eaf1eb96651977b8d6ad15f2503 Mon Sep 17 00:00:00 2001 From: Mayank Shah Date: Sun, 6 Sep 2020 13:40:38 +0530 Subject: [PATCH 1/4] fix: unit tests on Windows Signed-off-by: Mayank Shah --- pkg/azuredisk/azure_test.go | 8 ++++++++ pkg/azuredisk/azuredisk_test.go | 1 + pkg/azuredisk/nodeserver_test.go | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/pkg/azuredisk/azure_test.go b/pkg/azuredisk/azure_test.go index d487d025d1..e9c81db207 100644 --- a/pkg/azuredisk/azure_test.go +++ b/pkg/azuredisk/azure_test.go @@ -21,10 +21,18 @@ import ( "io/ioutil" "os" "reflect" + "runtime" "testing" ) +func skipTestsIfWindows(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("Skipping tests on Windows") + } +} + func TestGetCloudProvider(t *testing.T) { + skipTestsIfWindows(t) fakeCredFile := "fake-cred-file.json" fakeKubeConfig := "fake-kube-config" emptyKubeConfig := "empty-kube-config" diff --git a/pkg/azuredisk/azuredisk_test.go b/pkg/azuredisk/azuredisk_test.go index 76a881f7b0..4fbc3dedb1 100644 --- a/pkg/azuredisk/azuredisk_test.go +++ b/pkg/azuredisk/azuredisk_test.go @@ -544,6 +544,7 @@ func TestIsAvailabilityZone(t *testing.T) { } func TestIsCorruptedDir(t *testing.T) { + skipTestsIfWindows(t) existingMountPath, err := ioutil.TempDir(os.TempDir(), "csi-mount-test") if err != nil { t.Fatalf("failed to create tmp dir: %v", err) diff --git a/pkg/azuredisk/nodeserver_test.go b/pkg/azuredisk/nodeserver_test.go index 06afa8061c..77b9301087 100644 --- a/pkg/azuredisk/nodeserver_test.go +++ b/pkg/azuredisk/nodeserver_test.go @@ -326,6 +326,7 @@ func TestNodeStageVolume(t *testing.T) { } func TestNodeUnstageVolume(t *testing.T) { + skipTestsIfWindows(t) errorTarget := "./error_is_likely_target" targetFile := "./abc.go" tests := []struct { @@ -379,6 +380,7 @@ func TestNodeUnstageVolume(t *testing.T) { } func TestNodePublishVolume(t *testing.T) { + skipTestsIfWindows(t) volumeCap := csi.VolumeCapability_AccessMode{Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER} publishContext := map[string]string{ LUN: "/dev/01", @@ -504,6 +506,7 @@ func TestNodePublishVolume(t *testing.T) { } func TestNodeUnpublishVolume(t *testing.T) { + skipTestsIfWindows(t) errorTarget := "./error_is_likely_target" targetFile := "./abc.go" tests := []struct { @@ -556,6 +559,7 @@ func TestNodeUnpublishVolume(t *testing.T) { } func TestNodeExpandVolume(t *testing.T) { + skipTestsIfWindows(t) d, _ := NewFakeDriver(t) stdCapacityRange = &csi.CapacityRange{ RequiredBytes: volumehelper.GiBToBytes(15), @@ -590,6 +594,7 @@ func TestNodeExpandVolume(t *testing.T) { } func TestGetBlockSizeBytes(t *testing.T) { + skipTestsIfWindows(t) d, _ := NewFakeDriver(t) testTarget := "./test" tests := []struct { @@ -622,6 +627,7 @@ func TestGetBlockSizeBytes(t *testing.T) { } func TestEnsureBlockTargetFile(t *testing.T) { + skipTestsIfWindows(t) testTarget := "./test" d, _ := NewFakeDriver(t) tests := []struct { From 9d40cd440d1a9c589292d0392ae921445315d47d Mon Sep 17 00:00:00 2001 From: Mayank Shah Date: Sun, 6 Sep 2020 20:50:12 +0530 Subject: [PATCH 2/4] rename to `skipIfTestingOnWindows` Signed-off-by: Mayank Shah --- pkg/azuredisk/azure_test.go | 4 ++-- pkg/azuredisk/azuredisk_test.go | 2 +- pkg/azuredisk/nodeserver_test.go | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/azuredisk/azure_test.go b/pkg/azuredisk/azure_test.go index e9c81db207..8308e5c0bf 100644 --- a/pkg/azuredisk/azure_test.go +++ b/pkg/azuredisk/azure_test.go @@ -25,14 +25,14 @@ import ( "testing" ) -func skipTestsIfWindows(t *testing.T) { +func skipIfTestingOnWindows(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("Skipping tests on Windows") } } func TestGetCloudProvider(t *testing.T) { - skipTestsIfWindows(t) + skipIfTestingOnWindows(t) fakeCredFile := "fake-cred-file.json" fakeKubeConfig := "fake-kube-config" emptyKubeConfig := "empty-kube-config" diff --git a/pkg/azuredisk/azuredisk_test.go b/pkg/azuredisk/azuredisk_test.go index 4fbc3dedb1..2edef4e32a 100644 --- a/pkg/azuredisk/azuredisk_test.go +++ b/pkg/azuredisk/azuredisk_test.go @@ -544,7 +544,7 @@ func TestIsAvailabilityZone(t *testing.T) { } func TestIsCorruptedDir(t *testing.T) { - skipTestsIfWindows(t) + skipIfTestingOnWindows(t) existingMountPath, err := ioutil.TempDir(os.TempDir(), "csi-mount-test") if err != nil { t.Fatalf("failed to create tmp dir: %v", err) diff --git a/pkg/azuredisk/nodeserver_test.go b/pkg/azuredisk/nodeserver_test.go index 77b9301087..3724873255 100644 --- a/pkg/azuredisk/nodeserver_test.go +++ b/pkg/azuredisk/nodeserver_test.go @@ -326,7 +326,7 @@ func TestNodeStageVolume(t *testing.T) { } func TestNodeUnstageVolume(t *testing.T) { - skipTestsIfWindows(t) + skipIfTestingOnWindows(t) errorTarget := "./error_is_likely_target" targetFile := "./abc.go" tests := []struct { @@ -380,7 +380,7 @@ func TestNodeUnstageVolume(t *testing.T) { } func TestNodePublishVolume(t *testing.T) { - skipTestsIfWindows(t) + skipIfTestingOnWindows(t) volumeCap := csi.VolumeCapability_AccessMode{Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER} publishContext := map[string]string{ LUN: "/dev/01", @@ -506,7 +506,7 @@ func TestNodePublishVolume(t *testing.T) { } func TestNodeUnpublishVolume(t *testing.T) { - skipTestsIfWindows(t) + skipIfTestingOnWindows(t) errorTarget := "./error_is_likely_target" targetFile := "./abc.go" tests := []struct { @@ -559,7 +559,7 @@ func TestNodeUnpublishVolume(t *testing.T) { } func TestNodeExpandVolume(t *testing.T) { - skipTestsIfWindows(t) + skipIfTestingOnWindows(t) d, _ := NewFakeDriver(t) stdCapacityRange = &csi.CapacityRange{ RequiredBytes: volumehelper.GiBToBytes(15), @@ -594,7 +594,7 @@ func TestNodeExpandVolume(t *testing.T) { } func TestGetBlockSizeBytes(t *testing.T) { - skipTestsIfWindows(t) + skipIfTestingOnWindows(t) d, _ := NewFakeDriver(t) testTarget := "./test" tests := []struct { @@ -627,7 +627,7 @@ func TestGetBlockSizeBytes(t *testing.T) { } func TestEnsureBlockTargetFile(t *testing.T) { - skipTestsIfWindows(t) + skipIfTestingOnWindows(t) testTarget := "./test" d, _ := NewFakeDriver(t) tests := []struct { From a922d6cfe6c77d1345a2e971237040f6119d67a7 Mon Sep 17 00:00:00 2001 From: Mayank Shah Date: Sun, 6 Sep 2020 20:55:58 +0530 Subject: [PATCH 3/4] fix workflow Signed-off-by: Mayank Shah --- .github/workflows/windows.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 2930cbb58c..1d1bc83ae1 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -25,6 +25,4 @@ jobs: go build -a -o _output/azurediskplugin.exe ./pkg/azurediskplugin - name: Run Windows Unit Tests run: | - go test -v -race ./pkg/mounter/... - go test -v -race ./pkg/util/... - go test -v -race ./pkg/csi-common/... + go test -v -race ./pkg/... From 24df3ee336df942b3f4624f81d385fe107490e50 Mon Sep 17 00:00:00 2001 From: Mayank Shah Date: Sun, 6 Sep 2020 21:07:55 +0530 Subject: [PATCH 4/4] skip `TestEnsureMountPoint` on Windows Signed-off-by: Mayank Shah --- pkg/azuredisk/nodeserver_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/azuredisk/nodeserver_test.go b/pkg/azuredisk/nodeserver_test.go index 3724873255..f4ae0ec507 100644 --- a/pkg/azuredisk/nodeserver_test.go +++ b/pkg/azuredisk/nodeserver_test.go @@ -131,6 +131,7 @@ func TestGetMaxDataDiskCount(t *testing.T) { } func TestEnsureMountPoint(t *testing.T) { + skipIfTestingOnWindows(t) errorTarget := "./error_is_likely_target" alreadyExistTarget := "./false_is_likely_exist_target" azuredisk := "./azure.go"