Commit 35b45d60 authored by xiangpengzhao's avatar xiangpengzhao

Use Fatalf instead of Errorf when mounter/unmounter if nil in volume tests

parent 2b08d1e5
...@@ -235,6 +235,9 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) { ...@@ -235,6 +235,9 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
spec := volume.NewSpecFromPersistentVolume(pv, true) spec := volume.NewSpecFromPersistentVolume(pv, true)
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}} pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}}
mounter, _ := plug.NewMounter(spec, pod, volume.VolumeOptions{}) mounter, _ := plug.NewMounter(spec, pod, volume.VolumeOptions{})
if mounter == nil {
t.Fatalf("Got a nil Mounter")
}
if !mounter.GetAttributes().ReadOnly { if !mounter.GetAttributes().ReadOnly {
t.Errorf("Expected true for mounter.IsReadOnly") t.Errorf("Expected true for mounter.IsReadOnly")
......
...@@ -317,7 +317,7 @@ func TestPlugin(t *testing.T) { ...@@ -317,7 +317,7 @@ func TestPlugin(t *testing.T) {
t.Errorf("Failed to make a new Mounter: %v", err) t.Errorf("Failed to make a new Mounter: %v", err)
} }
if mounter == nil { if mounter == nil {
t.Errorf("Got a nil Mounter") t.Fatalf("Got a nil Mounter")
} }
vName, err := plugin.GetVolumeName(volume.NewSpecFromVolume(volumeSpec)) vName, err := plugin.GetVolumeName(volume.NewSpecFromVolume(volumeSpec))
...@@ -381,7 +381,7 @@ func TestPluginReboot(t *testing.T) { ...@@ -381,7 +381,7 @@ func TestPluginReboot(t *testing.T) {
t.Errorf("Failed to make a new Mounter: %v", err) t.Errorf("Failed to make a new Mounter: %v", err)
} }
if mounter == nil { if mounter == nil {
t.Errorf("Got a nil Mounter") t.Fatalf("Got a nil Mounter")
} }
podMetadataDir := fmt.Sprintf("%v/pods/test_pod_uid3/plugins/kubernetes.io~configmap/test_volume_name", rootDir) podMetadataDir := fmt.Sprintf("%v/pods/test_pod_uid3/plugins/kubernetes.io~configmap/test_volume_name", rootDir)
...@@ -597,7 +597,7 @@ func doTestCleanAndTeardown(plugin volume.VolumePlugin, podUID types.UID, testVo ...@@ -597,7 +597,7 @@ func doTestCleanAndTeardown(plugin volume.VolumePlugin, podUID types.UID, testVo
t.Errorf("Failed to make a new Unmounter: %v", err) t.Errorf("Failed to make a new Unmounter: %v", err)
} }
if unmounter == nil { if unmounter == nil {
t.Errorf("Got a nil Unmounter") t.Fatalf("Got a nil Unmounter")
} }
if err := unmounter.TearDown(); err != nil { if err := unmounter.TearDown(); err != nil {
......
...@@ -241,7 +241,7 @@ func newDownwardAPITest(t *testing.T, name string, volumeFiles, podLabels, podAn ...@@ -241,7 +241,7 @@ func newDownwardAPITest(t *testing.T, name string, volumeFiles, podLabels, podAn
t.Errorf("Failed to make a new Mounter: %v", err) t.Errorf("Failed to make a new Mounter: %v", err)
} }
if mounter == nil { if mounter == nil {
t.Errorf("Got a nil Mounter") t.Fatalf("Got a nil Mounter")
} }
volumePath := mounter.GetPath() volumePath := mounter.GetPath()
...@@ -278,7 +278,7 @@ func (test *downwardAPITest) tearDown() { ...@@ -278,7 +278,7 @@ func (test *downwardAPITest) tearDown() {
test.t.Errorf("Failed to make a new Unmounter: %v", err) test.t.Errorf("Failed to make a new Unmounter: %v", err)
} }
if unmounter == nil { if unmounter == nil {
test.t.Errorf("Got a nil Unmounter") test.t.Fatalf("Got a nil Unmounter")
} }
if err := unmounter.TearDown(); err != nil { if err := unmounter.TearDown(); err != nil {
......
...@@ -221,7 +221,7 @@ func TestPluginBackCompat(t *testing.T) { ...@@ -221,7 +221,7 @@ func TestPluginBackCompat(t *testing.T) {
t.Errorf("Failed to make a new Mounter: %v", err) t.Errorf("Failed to make a new Mounter: %v", err)
} }
if mounter == nil { if mounter == nil {
t.Errorf("Got a nil Mounter") t.Fatalf("Got a nil Mounter")
} }
volPath := mounter.GetPath() volPath := mounter.GetPath()
...@@ -249,6 +249,9 @@ func TestMetrics(t *testing.T) { ...@@ -249,6 +249,9 @@ func TestMetrics(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Failed to make a new Mounter: %v", err) t.Errorf("Failed to make a new Mounter: %v", err)
} }
if mounter == nil {
t.Fatalf("Got a nil Mounter")
}
// Need to create the subdirectory // Need to create the subdirectory
os.MkdirAll(mounter.GetPath(), 0755) os.MkdirAll(mounter.GetPath(), 0755)
......
...@@ -362,6 +362,9 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) { ...@@ -362,6 +362,9 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
spec := volume.NewSpecFromPersistentVolume(pv, true) spec := volume.NewSpecFromPersistentVolume(pv, true)
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}} pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}}
mounter, _ := plug.NewMounter(spec, pod, volume.VolumeOptions{}) mounter, _ := plug.NewMounter(spec, pod, volume.VolumeOptions{})
if mounter == nil {
t.Fatalf("Got a nil Mounter")
}
if !mounter.GetAttributes().ReadOnly { if !mounter.GetAttributes().ReadOnly {
t.Errorf("Expected true for mounter.IsReadOnly") t.Errorf("Expected true for mounter.IsReadOnly")
......
...@@ -251,6 +251,9 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) { ...@@ -251,6 +251,9 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
spec := volume.NewSpecFromPersistentVolume(pv, true) spec := volume.NewSpecFromPersistentVolume(pv, true)
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}} pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}}
mounter, _ := plug.NewMounter(spec, pod, volume.VolumeOptions{}) mounter, _ := plug.NewMounter(spec, pod, volume.VolumeOptions{})
if mounter == nil {
t.Fatalf("Got a nil Mounter")
}
if !mounter.GetAttributes().ReadOnly { if !mounter.GetAttributes().ReadOnly {
t.Errorf("Expected true for mounter.IsReadOnly") t.Errorf("Expected true for mounter.IsReadOnly")
......
...@@ -225,7 +225,7 @@ func TestPlugin(t *testing.T) { ...@@ -225,7 +225,7 @@ func TestPlugin(t *testing.T) {
t.Errorf("Failed to make a new Mounter: %v", err) t.Errorf("Failed to make a new Mounter: %v", err)
} }
if mounter == nil { if mounter == nil {
t.Errorf("Got a nil Mounter") t.Fatalf("Got a nil Mounter")
} }
path := mounter.GetPath() path := mounter.GetPath()
...@@ -242,7 +242,7 @@ func TestPlugin(t *testing.T) { ...@@ -242,7 +242,7 @@ func TestPlugin(t *testing.T) {
t.Errorf("Failed to make a new Unmounter: %v", err) t.Errorf("Failed to make a new Unmounter: %v", err)
} }
if unmounter == nil { if unmounter == nil {
t.Errorf("Got a nil Unmounter") t.Fatalf("Got a nil Unmounter")
} }
if err := unmounter.TearDown(); err != nil { if err := unmounter.TearDown(); err != nil {
...@@ -288,6 +288,9 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) { ...@@ -288,6 +288,9 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
spec := volume.NewSpecFromPersistentVolume(pv, true) spec := volume.NewSpecFromPersistentVolume(pv, true)
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}} pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}}
mounter, _ := plug.NewMounter(spec, pod, volume.VolumeOptions{}) mounter, _ := plug.NewMounter(spec, pod, volume.VolumeOptions{})
if mounter == nil {
t.Fatalf("Got a nil Mounter")
}
if !mounter.GetAttributes().ReadOnly { if !mounter.GetAttributes().ReadOnly {
t.Errorf("Expected true for mounter.IsReadOnly") t.Errorf("Expected true for mounter.IsReadOnly")
......
...@@ -283,6 +283,9 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) { ...@@ -283,6 +283,9 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
spec := volume.NewSpecFromPersistentVolume(pv, true) spec := volume.NewSpecFromPersistentVolume(pv, true)
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}} pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}}
mounter, _ := plug.NewMounter(spec, pod, volume.VolumeOptions{}) mounter, _ := plug.NewMounter(spec, pod, volume.VolumeOptions{})
if mounter == nil {
t.Fatalf("Got a nil Mounter")
}
if !mounter.GetAttributes().ReadOnly { if !mounter.GetAttributes().ReadOnly {
t.Errorf("Expected true for mounter.IsReadOnly") t.Errorf("Expected true for mounter.IsReadOnly")
......
...@@ -247,6 +247,9 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) { ...@@ -247,6 +247,9 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
spec := volume.NewSpecFromPersistentVolume(pv, true) spec := volume.NewSpecFromPersistentVolume(pv, true)
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}} pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}}
mounter, _ := plug.NewMounter(spec, pod, volume.VolumeOptions{}) mounter, _ := plug.NewMounter(spec, pod, volume.VolumeOptions{})
if mounter == nil {
t.Fatalf("Got a nil Mounter")
}
if !mounter.GetAttributes().ReadOnly { if !mounter.GetAttributes().ReadOnly {
t.Errorf("Expected true for mounter.IsReadOnly") t.Errorf("Expected true for mounter.IsReadOnly")
......
...@@ -194,6 +194,9 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) { ...@@ -194,6 +194,9 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
spec := volume.NewSpecFromPersistentVolume(pv, true) spec := volume.NewSpecFromPersistentVolume(pv, true)
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}} pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}}
mounter, _ := plug.NewMounter(spec, pod, volume.VolumeOptions{}) mounter, _ := plug.NewMounter(spec, pod, volume.VolumeOptions{})
if mounter == nil {
t.Fatalf("Got a nil Mounter")
}
if !mounter.GetAttributes().ReadOnly { if !mounter.GetAttributes().ReadOnly {
t.Errorf("Expected true for mounter.IsReadOnly") t.Errorf("Expected true for mounter.IsReadOnly")
......
...@@ -235,6 +235,9 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) { ...@@ -235,6 +235,9 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
spec := volume.NewSpecFromPersistentVolume(pv, true) spec := volume.NewSpecFromPersistentVolume(pv, true)
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}} pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}}
mounter, _ := plug.NewMounter(spec, pod, volume.VolumeOptions{}) mounter, _ := plug.NewMounter(spec, pod, volume.VolumeOptions{})
if mounter == nil {
t.Fatalf("Got a nil Mounter")
}
if !mounter.GetAttributes().ReadOnly { if !mounter.GetAttributes().ReadOnly {
t.Errorf("Expected true for mounter.IsReadOnly") t.Errorf("Expected true for mounter.IsReadOnly")
......
...@@ -319,7 +319,7 @@ func TestPlugin(t *testing.T) { ...@@ -319,7 +319,7 @@ func TestPlugin(t *testing.T) {
t.Errorf("Failed to make a new Mounter: %v", err) t.Errorf("Failed to make a new Mounter: %v", err)
} }
if mounter == nil { if mounter == nil {
t.Errorf("Got a nil Mounter") t.Fatalf("Got a nil Mounter")
} }
volumePath := mounter.GetPath() volumePath := mounter.GetPath()
...@@ -392,7 +392,7 @@ func TestPluginReboot(t *testing.T) { ...@@ -392,7 +392,7 @@ func TestPluginReboot(t *testing.T) {
t.Errorf("Failed to make a new Mounter: %v", err) t.Errorf("Failed to make a new Mounter: %v", err)
} }
if mounter == nil { if mounter == nil {
t.Errorf("Got a nil Mounter") t.Fatalf("Got a nil Mounter")
} }
podMetadataDir := fmt.Sprintf("%v/pods/test_pod_uid3/plugins/kubernetes.io~secret/test_volume_name", rootDir) podMetadataDir := fmt.Sprintf("%v/pods/test_pod_uid3/plugins/kubernetes.io~secret/test_volume_name", rootDir)
...@@ -617,7 +617,7 @@ func doTestCleanAndTeardown(plugin volume.VolumePlugin, podUID types.UID, testVo ...@@ -617,7 +617,7 @@ func doTestCleanAndTeardown(plugin volume.VolumePlugin, podUID types.UID, testVo
t.Errorf("Failed to make a new Unmounter: %v", err) t.Errorf("Failed to make a new Unmounter: %v", err)
} }
if unmounter == nil { if unmounter == nil {
t.Errorf("Got a nil Unmounter") t.Fatalf("Got a nil Unmounter")
} }
if err := unmounter.TearDown(); err != nil { if err := unmounter.TearDown(); err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment