-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #420 from Sakuralbj/test
Add Unit tests
- Loading branch information
Showing
3 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
Copyright 2020 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package azuredisk | ||
|
||
import ( | ||
"context" | ||
"github.com/container-storage-interface/spec/lib/go/csi" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
const ( | ||
fakeCSIDriverName = "fake" | ||
vendorVersion = "0.3.0" | ||
) | ||
|
||
func TestGetPluginInfo(t *testing.T) { | ||
// Check with correct arguments | ||
d, _ := NewFakeDriver(t) | ||
req := csi.GetPluginInfoRequest{} | ||
resp, err := d.GetPluginInfo(context.Background(), &req) | ||
assert.NoError(t, err) | ||
assert.Equal(t, resp.Name, fakeCSIDriverName) | ||
assert.Equal(t, resp.GetVendorVersion(), vendorVersion) | ||
|
||
//Check error when driver name is empty | ||
d, _ = NewFakeDriver(t) | ||
d.Name = "" | ||
req = csi.GetPluginInfoRequest{} | ||
resp, err = d.GetPluginInfo(context.Background(), &req) | ||
assert.Error(t, err) | ||
assert.Nil(t, resp) | ||
|
||
//Check error when version is empty | ||
d, _ = NewFakeDriver(t) | ||
d.Version = "" | ||
req = csi.GetPluginInfoRequest{} | ||
resp, err = d.GetPluginInfo(context.Background(), &req) | ||
assert.Error(t, err) | ||
assert.Nil(t, resp) | ||
} | ||
|
||
func TestProbe(t *testing.T) { | ||
d, _ := NewFakeDriver(t) | ||
req := csi.ProbeRequest{} | ||
resp, err := d.Probe(context.Background(), &req) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, resp) | ||
assert.Equal(t, resp.XXX_sizecache, int32(0)) | ||
assert.Equal(t, resp.Ready.Value, true) | ||
} | ||
|
||
func TestGetPluginCapabilities(t *testing.T) { | ||
d, _ := NewFakeDriver(t) | ||
req := csi.GetPluginCapabilitiesRequest{} | ||
resp, err := d.GetPluginCapabilities(context.Background(), &req) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, resp) | ||
assert.Equal(t, resp.XXX_sizecache, int32(0)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
Copyright 2020 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package azuredisk | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"runtime" | ||
"strings" | ||
"testing" | ||
|
||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
func TestGetVersion(t *testing.T) { | ||
version := GetVersion() | ||
|
||
expected := VersionInfo{ | ||
DriverName: DriverName, | ||
DriverVersion: "N/A", | ||
GitCommit: "N/A", | ||
BuildDate: "N/A", | ||
GoVersion: runtime.Version(), | ||
Compiler: runtime.Compiler, | ||
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), | ||
TopologyKey: "N/A", | ||
} | ||
|
||
if !reflect.DeepEqual(version, expected) { | ||
t.Errorf("Unexpected error. \n Expected: %v \n Found: %v", expected, version) | ||
} | ||
|
||
} | ||
|
||
func TestGetVersionYAML(t *testing.T) { | ||
resp, err := GetVersionYAML() | ||
if err != nil { | ||
t.Fatalf("Unexpected error: %v", err) | ||
} | ||
|
||
versionInfo := GetVersion() | ||
marshalled, _ := yaml.Marshal(&versionInfo) | ||
|
||
expected := strings.TrimSpace(string(marshalled)) | ||
|
||
if resp != expected { | ||
t.Fatalf("Unexpected error. \n Expected:%v\nFound:%v", expected, resp) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
Copyright 2020 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package mounter | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestNewSafeMounter(t *testing.T) { | ||
resp, err := NewSafeMounter() | ||
assert.NotNil(t, resp) | ||
assert.Nil(t, err) | ||
} |