Skip to content

Commit aca107e

Browse files
committed
Fixed potential nil dereference in hostpath unit test
1 parent a60cbd5 commit aca107e

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

pkg/volume/hostpath/host_path_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ func TestCanSupport(t *testing.T) {
5252
plugMgr := volume.VolumePluginMgr{}
5353
plugMgr.InitPlugins(ProbeVolumePlugins(volume.VolumeConfig{}), nil /* prober */, volumetest.NewFakeVolumeHost(t, "fake", nil, nil))
5454

55-
plug, err := plugMgr.FindPluginByName("kubernetes.io/host-path")
55+
plug, err := plugMgr.FindPluginByName(hostPathPluginName)
5656
if err != nil {
57-
t.Errorf("Can't find the plugin by name")
57+
t.Fatal("Can't find the plugin by name")
5858
}
59-
if plug.GetPluginName() != "kubernetes.io/host-path" {
59+
if plug.GetPluginName() != hostPathPluginName {
6060
t.Errorf("Wrong name: %s", plug.GetPluginName())
6161
}
6262
if !plug.CanSupport(&volume.Spec{Volume: &v1.Volume{VolumeSource: v1.VolumeSource{HostPath: &v1.HostPathVolumeSource{}}}}) {
@@ -74,9 +74,9 @@ func TestGetAccessModes(t *testing.T) {
7474
plugMgr := volume.VolumePluginMgr{}
7575
plugMgr.InitPlugins(ProbeVolumePlugins(volume.VolumeConfig{}), nil /* prober */, volumetest.NewFakeVolumeHost(t, "/tmp/fake", nil, nil))
7676

77-
plug, err := plugMgr.FindPersistentPluginByName("kubernetes.io/host-path")
77+
plug, err := plugMgr.FindPersistentPluginByName(hostPathPluginName)
7878
if err != nil {
79-
t.Errorf("Can't find the plugin by name")
79+
t.Fatal("Can't find the plugin by name")
8080
}
8181
if len(plug.GetAccessModes()) != 1 || plug.GetAccessModes()[0] != v1.ReadWriteOnce {
8282
t.Errorf("Expected %s PersistentVolumeAccessMode", v1.ReadWriteOnce)
@@ -109,7 +109,7 @@ func TestDeleter(t *testing.T) {
109109
spec := &volume.Spec{PersistentVolume: &v1.PersistentVolume{Spec: v1.PersistentVolumeSpec{PersistentVolumeSource: v1.PersistentVolumeSource{HostPath: &v1.HostPathVolumeSource{Path: tempPath}}}}}
110110
plug, err := plugMgr.FindDeletablePluginBySpec(spec)
111111
if err != nil {
112-
t.Errorf("Can't find the plugin by name")
112+
t.Fatal("Can't find the plugin by name")
113113
}
114114
deleter, err := plug.NewDeleter(spec)
115115
if err != nil {
@@ -230,9 +230,9 @@ func TestPlugin(t *testing.T) {
230230
plugMgr := volume.VolumePluginMgr{}
231231
plugMgr.InitPlugins(ProbeVolumePlugins(volume.VolumeConfig{}), nil /* prober */, volumetest.NewFakeVolumeHost(t, "fake", nil, nil))
232232

233-
plug, err := plugMgr.FindPluginByName("kubernetes.io/host-path")
233+
plug, err := plugMgr.FindPluginByName(hostPathPluginName)
234234
if err != nil {
235-
t.Errorf("Can't find the plugin by name")
235+
t.Fatal("Can't find the plugin by name")
236236
}
237237

238238
volPath := "/tmp/vol1"

0 commit comments

Comments
 (0)