Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Add darwin unit test workflow #564

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/darwin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: MacOS Build & Unit Test
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:

build:
name: Build
runs-on: macos-latest
steps:

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.13
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Build Test
run: |
make azuredisk-darwin
- name: Run unit tests on MacOS
run: go test -v -race ./pkg/...
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
name: Go

name: Linux Build & Unit Tests
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:

build:
name: Build
runs-on: ubuntu-latest
Expand All @@ -22,9 +19,8 @@ jobs:
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Test
- name: Build Test
run: sudo go test -covermode=count -coverprofile=profile.cov ./pkg/...

- name: Send coverage
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: Go

name: Windows Build & Unit Tests
on:
push:
branches: [ master ]
Expand All @@ -20,9 +19,9 @@ jobs:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Build
- name: Build Test
run: |
go build -a -o _output/azurediskplugin.exe ./pkg/azurediskplugin
make azuredisk-windows
- name: Run Windows Unit Tests
run: |
# start the CSI Proxy before running tests on windows
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ azuredisk:
azuredisk-windows:
CGO_ENABLED=0 GOOS=windows go build -a -ldflags ${LDFLAGS} -o _output/azurediskplugin.exe ./pkg/azurediskplugin

.PHONY: azuredisk-darwin
azuredisk-darwin:
CGO_ENABLED=0 GOOS=darwin go build -a -ldflags ${LDFLAGS} -o _output/azurediskplugin ./pkg/azurediskplugin

.PHONY: container
container: azuredisk
docker build --no-cache -t $(IMAGE_TAG) -f ./pkg/azurediskplugin/dev.Dockerfile .
Expand Down
2 changes: 1 addition & 1 deletion pkg/azuredisk/azure_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (handler *fakeIOHandler) ReadFile(filename string) ([]byte, error) {
}

func TestIoHandler(t *testing.T) {
if runtime.GOOS == "windows" {
if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
t.Skipf("skip test on GOOS=%s", runtime.GOOS)
}
disk, err := findDiskByLun(lun, &fakeIOHandler{}, nil)
Expand Down
98 changes: 67 additions & 31 deletions pkg/azuredisk/nodeserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,10 @@ func TestNodeGetVolumeStats(t *testing.T) {
nonexistedPath := "/not/a/real/directory"
fakePath := "/tmp/fake-volume-path"
tests := []struct {
desc string
req csi.NodeGetVolumeStatsRequest
expectedErr error
desc string
req csi.NodeGetVolumeStatsRequest
expectedErr error
skipOnDarwin bool
Copy link
Contributor Author

@mayankshah1607 mayankshah1607 Oct 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andyzhangx In many test cases, I have provided an option to skip on darwin as the tests return the following error:
util/mount on this platform is not supported
Tests are also skipped on darwin when the returned error is nil

}{
{
desc: "Volume ID missing",
Expand All @@ -235,9 +236,10 @@ func TestNodeGetVolumeStats(t *testing.T) {
expectedErr: status.Errorf(codes.NotFound, "path /not/a/real/directory does not exist"),
},
{
desc: "standard success",
req: csi.NodeGetVolumeStatsRequest{VolumePath: fakePath, VolumeId: "vol_1"},
expectedErr: nil,
desc: "standard success",
req: csi.NodeGetVolumeStatsRequest{VolumePath: fakePath, VolumeId: "vol_1"},
skipOnDarwin: true,
expectedErr: nil,
},
}

Expand All @@ -246,9 +248,11 @@ func TestNodeGetVolumeStats(t *testing.T) {
d, _ := NewFakeDriver(t)

for _, test := range tests {
_, err := d.NodeGetVolumeStats(context.Background(), &test.req)
if !reflect.DeepEqual(err, test.expectedErr) {
t.Errorf("desc: %s\n actualErr: (%v), expectedErr: (%v)", test.desc, err, test.expectedErr)
if !(test.skipOnDarwin && runtime.GOOS == "darwin") {
_, err := d.NodeGetVolumeStats(context.Background(), &test.req)
if !reflect.DeepEqual(err, test.expectedErr) {
t.Errorf("desc: %s\n actualErr: (%v), expectedErr: (%v)", test.desc, err, test.expectedErr)
}
}
}

Expand Down Expand Up @@ -276,9 +280,10 @@ func TestNodeStageVolume(t *testing.T) {
}

tests := []struct {
desc string
req csi.NodeStageVolumeRequest
expectedErr error
desc string
req csi.NodeStageVolumeRequest
expectedErr error
skipOnDarwin bool
}{
{
desc: "Volume ID missing",
Expand Down Expand Up @@ -313,7 +318,8 @@ func TestNodeStageVolume(t *testing.T) {
expectedErr: status.Error(codes.InvalidArgument, "lun not provided"),
},
{
desc: "Invalid Lun",
desc: "Invalid Lun",
skipOnDarwin: true,
req: csi.NodeStageVolumeRequest{VolumeId: "vol_1", StagingTargetPath: sourceTest,
VolumeCapability: &csi.VolumeCapability{AccessMode: &volumeCap,
AccessType: stdVolCap},
Expand All @@ -331,11 +337,13 @@ func TestNodeStageVolume(t *testing.T) {
d, _ := NewFakeDriver(t)
d.mounter, _ = mounter.NewSafeMounter()
for _, test := range tests {
_, err := d.NodeStageVolume(context.Background(), &test.req)
if test.desc == "Failed volume mount" {
assert.Error(t, err)
} else if !reflect.DeepEqual(err, test.expectedErr) {
t.Errorf("desc: %s\n actualErr: (%v), expectedErr: (%v)", test.desc, err, test.expectedErr)
if !(test.skipOnDarwin && runtime.GOOS == "darwin") {
_, err := d.NodeStageVolume(context.Background(), &test.req)
if test.desc == "Failed volume mount" {
assert.Error(t, err)
} else if !reflect.DeepEqual(err, test.expectedErr) {
t.Errorf("desc: %s\n actualErr: (%v), expectedErr: (%v)", test.desc, err, test.expectedErr)
}
}
}

Expand All @@ -356,6 +364,7 @@ func TestNodeUnstageVolume(t *testing.T) {
desc string
req csi.NodeUnstageVolumeRequest
skipOnWindows bool
skipOnDarwin bool
expectedErr testutil.TestError
}{
{
Expand All @@ -376,6 +385,7 @@ func TestNodeUnstageVolume(t *testing.T) {
desc: "[Error] CleanupMountPoint error mocked by IsLikelyNotMountPoint",
req: csi.NodeUnstageVolumeRequest{StagingTargetPath: errorTarget, VolumeId: "vol_1"},
skipOnWindows: true, // no error reported in windows
skipOnDarwin: true,
expectedErr: testutil.TestError{
DefaultError: status.Error(codes.Internal, fmt.Sprintf("failed to unmount staging target \"%s\": "+
"fake IsLikelyNotMountPoint: fake error", errorTarget)),
Expand All @@ -396,7 +406,8 @@ func TestNodeUnstageVolume(t *testing.T) {
d.mounter = fakeMounter

for _, test := range tests {
if !(runtime.GOOS == "windows" && test.skipOnWindows) {
if !(runtime.GOOS == "windows" && test.skipOnWindows) &&
!(runtime.GOOS == "darwin" && test.skipOnDarwin) {
_, err := d.NodeUnstageVolume(context.Background(), &test.req)
if !testutil.AssertError(&test.expectedErr, err) {
t.Errorf("desc: %s\n actualErr: (%v), expectedErr: (%v)", test.desc, err, test.expectedErr.Error())
Expand Down Expand Up @@ -577,6 +588,7 @@ func TestNodeUnpublishVolume(t *testing.T) {
desc string
req csi.NodeUnpublishVolumeRequest
skipOnWindows bool
skipOnDarwin bool
expectedErr testutil.TestError
}{
{
Expand All @@ -597,6 +609,7 @@ func TestNodeUnpublishVolume(t *testing.T) {
desc: "[Error] Unmount error mocked by IsLikelyNotMountPoint",
req: csi.NodeUnpublishVolumeRequest{TargetPath: errorTarget, VolumeId: "vol_1"},
skipOnWindows: true, // no error reported in windows
skipOnDarwin: true, // no error reported in darwin
expectedErr: testutil.TestError{
DefaultError: status.Error(codes.Internal, fmt.Sprintf("failed to unmount target \"%s\": fake IsLikelyNotMountPoint: fake error", errorTarget)),
},
Expand All @@ -616,9 +629,12 @@ func TestNodeUnpublishVolume(t *testing.T) {
d.mounter = fakeMounter

for _, test := range tests {
_, err := d.NodeUnpublishVolume(context.Background(), &test.req)
if !testutil.AssertError(&test.expectedErr, err) {
t.Errorf("desc: %s\n actualErr: (%v), expectedErr: (%v)", test.desc, err, test.expectedErr.Error())
if !(test.skipOnWindows && runtime.GOOS == "windows") &&
!(test.skipOnDarwin && runtime.GOOS == "darwin") {
_, err := d.NodeUnpublishVolume(context.Background(), &test.req)
if !testutil.AssertError(&test.expectedErr, err) {
t.Errorf("desc: %s\n actualErr: (%v), expectedErr: (%v)", test.desc, err, test.expectedErr.Error())
}
}
}

Expand All @@ -633,6 +649,15 @@ func TestNodeExpandVolume(t *testing.T) {
RequiredBytes: volumehelper.GiBToBytes(15),
LimitBytes: volumehelper.GiBToBytes(10),
}

invalidPathErr := testutil.TestError{
DefaultError: status.Error(codes.Internal, "Could not determine device path: exit status 1"),
WindowsError: status.Error(codes.Internal, "Could not determine device path: executable file not found in %PATH%"),
}

if runtime.GOOS == "darwin" {
invalidPathErr.DefaultError = status.Error(codes.Internal, "Could not determine device path: executable file not found in $PATH")
}
tests := []struct {
desc string
req csi.NodeExpandVolumeRequest
Expand All @@ -652,10 +677,7 @@ func TestNodeExpandVolume(t *testing.T) {
VolumePath: "./test",
VolumeId: "test",
},
expectedErr: testutil.TestError{
DefaultError: status.Error(codes.Internal, "Could not determine device path: exit status 1"),
WindowsError: status.Error(codes.Internal, "Could not determine device path: executable file not found in %PATH%"),
},
expectedErr: invalidPathErr,
},
}
for _, test := range tests {
Expand All @@ -671,6 +693,12 @@ func TestGetBlockSizeBytes(t *testing.T) {
testTarget, err := testutil.GetWorkDirPath("test")
assert.NoError(t, err)

notFoundErr := "exit status 1"
// exception in darwin
if runtime.GOOS == "darwin" {
notFoundErr = "executable file not found in $PATH"
}

tests := []struct {
desc string
req string
Expand All @@ -680,16 +708,18 @@ func TestGetBlockSizeBytes(t *testing.T) {
desc: "no exist path",
req: "testpath",
expectedErr: testutil.TestError{
DefaultError: errors.New("error when getting size of block volume at path testpath: output: , err: exit status 1"),
WindowsError: errors.New("error when getting size of block volume at path testpath: output: , err: executable file not found in %PATH%"),
DefaultError: fmt.Errorf("error when getting size of block volume at path testpath: output: , err: %s", notFoundErr),
WindowsError: fmt.Errorf("error when getting size of block volume at path testpath: output: , err: %s", notFoundErr),
},
},
{
desc: "invalid path",
req: testTarget,
expectedErr: testutil.TestError{
DefaultError: fmt.Errorf("error when getting size of block volume at path %s: output: , err: exit status 1", testTarget),
WindowsError: fmt.Errorf("error when getting size of block volume at path %s: output: , err: executable file not found in %%PATH%%", testTarget),
DefaultError: fmt.Errorf("error when getting size of block volume at path %s: "+
"output: , err: %s", testTarget, notFoundErr),
WindowsError: fmt.Errorf("error when getting size of block volume at path %s: "+
"output: , err: %s", testTarget, notFoundErr),
},
},
}
Expand All @@ -707,11 +737,17 @@ func TestGetBlockSizeBytes(t *testing.T) {
}

func TestEnsureBlockTargetFile(t *testing.T) {
// sip this test because `util/mount` not supported
// on darwin
if runtime.GOOS == "darwin" {
t.Skip("Skipping tests on darwin")
}
testTarget, err := testutil.GetWorkDirPath("test")
assert.NoError(t, err)
testPath, err := testutil.GetWorkDirPath(fmt.Sprintf("test%ctest", os.PathSeparator))
assert.NoError(t, err)
d, _ := NewFakeDriver(t)
d, err := NewFakeDriver(t)
assert.NoError(t, err)

tests := []struct {
desc string
Expand Down
6 changes: 6 additions & 0 deletions test/utils/testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ type TestError struct {
// Error returns the error on the basis of the platform
func (t TestError) Error() string {
if t.WindowsError == nil || !isWindows() {
if t.DefaultError == nil {
return ""
}
return t.DefaultError.Error()
}
if t.WindowsError == nil {
return ""
}
return t.WindowsError.Error()
}

Expand Down