Skip to content

Commit ae46306

Browse files
authored
Merge pull request #174 from Sakuralbj/unit-test
test: add unit-test
2 parents 2715585 + 0a9e04f commit ae46306

File tree

8 files changed

+539
-5
lines changed

8 files changed

+539
-5
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ go_import_path: sigs.k8s.io/blobfuse-csi-driver
33
dist: bionic
44

55
go:
6-
- "1.12.1"
6+
- "1.13.9"
77

88
before_install:
99
- GO111MODULE=off go get github.com/mattn/goveralls
1010

1111
script:
12-
- go test -covermode=count -coverprofile=profile.cov ./pkg/...
12+
- sudo -E env "PATH=$PATH" go test -covermode=count -coverprofile=profile.cov ./pkg/...
1313
- $GOPATH/bin/goveralls -coverprofile=profile.cov -service=travis-ci

pkg/blobfuse/blobfuse_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ import (
2626
"github.com/stretchr/testify/assert"
2727
)
2828

29+
const (
30+
fakeNodeID = "fakeNodeID"
31+
fakeDriverName = "fake"
32+
vendorVersion = "0.3.0"
33+
)
34+
35+
func NewFakeDriver() *Driver {
36+
driver := NewDriver(fakeNodeID)
37+
driver.Name = fakeDriverName
38+
driver.Version = vendorVersion
39+
return driver
40+
}
41+
42+
func TestNewFakeDriver(t *testing.T) {
43+
d := NewDriver(fakeNodeID)
44+
assert.NotNil(t, d)
45+
}
46+
2947
func TestAppendDefaultMountOptions(t *testing.T) {
3048
tests := []struct {
3149
options []string

pkg/blobfuse/controllerserver_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package blobfuse
18+
19+
import (
20+
"context"
21+
"testing"
22+
23+
"github.com/container-storage-interface/spec/lib/go/csi"
24+
"github.com/stretchr/testify/assert"
25+
)
26+
27+
func TestControllerGetCapabilities(t *testing.T) {
28+
d := NewFakeDriver()
29+
controlCap := []*csi.ControllerServiceCapability{
30+
{
31+
Type: &csi.ControllerServiceCapability_Rpc{},
32+
},
33+
}
34+
d.Cap = controlCap
35+
req := csi.ControllerGetCapabilitiesRequest{}
36+
resp, err := d.ControllerGetCapabilities(context.Background(), &req)
37+
assert.NoError(t, err)
38+
assert.NotNil(t, resp)
39+
assert.Equal(t, resp.Capabilities, controlCap)
40+
}

pkg/blobfuse/identityserver_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package blobfuse
18+
19+
import (
20+
"context"
21+
"testing"
22+
23+
"github.com/container-storage-interface/spec/lib/go/csi"
24+
"github.com/stretchr/testify/assert"
25+
)
26+
27+
func TestGetPluginInfo(t *testing.T) {
28+
// Check with correct arguments
29+
d := NewFakeDriver()
30+
req := csi.GetPluginInfoRequest{}
31+
resp, err := d.GetPluginInfo(context.Background(), &req)
32+
assert.NoError(t, err)
33+
assert.Equal(t, resp.Name, fakeDriverName)
34+
assert.Equal(t, resp.GetVendorVersion(), vendorVersion)
35+
36+
//Check error when driver name is empty
37+
d = NewFakeDriver()
38+
d.Name = ""
39+
req = csi.GetPluginInfoRequest{}
40+
resp, err = d.GetPluginInfo(context.Background(), &req)
41+
assert.Error(t, err)
42+
assert.Nil(t, resp)
43+
44+
//Check error when version is empty
45+
d = NewFakeDriver()
46+
d.Version = ""
47+
req = csi.GetPluginInfoRequest{}
48+
resp, err = d.GetPluginInfo(context.Background(), &req)
49+
assert.Error(t, err)
50+
assert.Nil(t, resp)
51+
}
52+
53+
func TestProbe(t *testing.T) {
54+
d := NewFakeDriver()
55+
req := csi.ProbeRequest{}
56+
resp, err := d.Probe(context.Background(), &req)
57+
assert.NoError(t, err)
58+
assert.NotNil(t, resp)
59+
assert.Equal(t, resp.XXX_sizecache, int32(0))
60+
assert.Equal(t, resp.Ready.Value, true)
61+
}
62+
63+
func TestGetPluginCapabilities(t *testing.T) {
64+
d := NewFakeDriver()
65+
req := csi.GetPluginCapabilitiesRequest{}
66+
resp, err := d.GetPluginCapabilities(context.Background(), &req)
67+
assert.NoError(t, err)
68+
assert.NotNil(t, resp)
69+
assert.Equal(t, resp.XXX_sizecache, int32(0))
70+
}

pkg/blobfuse/nodeserver.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
4444
if len(req.GetVolumeId()) == 0 {
4545
return nil, status.Error(codes.InvalidArgument, "Volume ID missing in request")
4646
}
47-
if len(req.GetTargetPath()) == 0 {
48-
return nil, status.Error(codes.InvalidArgument, "Target path missing in request")
49-
}
5047

5148
source := req.GetStagingTargetPath()
5249
if len(source) == 0 {

0 commit comments

Comments
 (0)