Skip to content

Commit

Permalink
CI: Add MacOS unit test workflow
Browse files Browse the repository at this point in the history
Signed-off-by: Mayank Shah <[email protected]>
  • Loading branch information
mayankshah1607 committed Oct 5, 2020
1 parent eef5de2 commit aa77a32
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 37 deletions.
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
80 changes: 53 additions & 27 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
}{
{
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 @@ -593,6 +604,7 @@ func TestNodeUnpublishVolume(t *testing.T) {
DefaultError: status.Error(codes.InvalidArgument, "Target path missing in request"),
},
},
// skip on mac
{
desc: "[Error] Unmount error mocked by IsLikelyNotMountPoint",
req: csi.NodeUnpublishVolumeRequest{TargetPath: errorTarget, VolumeId: "vol_1"},
Expand Down Expand Up @@ -633,6 +645,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 +673,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 +689,12 @@ func TestGetBlockSizeBytes(t *testing.T) {
testTarget, err := testutil.GetWorkDirPath("test")
assert.NoError(t, err)

notFoundErr := "err: 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 +704,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 Down

0 comments on commit aa77a32

Please sign in to comment.