Merge pull request #38947 from xiangpengzhao/fix-testcase-errorf

Automatic merge from submit-queue (batch tested with PRs 38947, 50239, 51115, 51094, 51116)

Call Fatalf instead of Errorf when mounter/unmounter is nil in volume tests

If we get a nil mounter or unmounter, a panic will occur. Should call `Fatalf` instead of `Errorf`.
pull/6/head
Kubernetes Submit Queue 2017-08-23 08:41:01 -07:00 committed by GitHub
commit 7df5c63218
12 changed files with 38 additions and 11 deletions

View File

@ -235,6 +235,9 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
spec := volume.NewSpecFromPersistentVolume(pv, true)
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}}
mounter, _ := plug.NewMounter(spec, pod, volume.VolumeOptions{})
if mounter == nil {
t.Fatalf("Got a nil Mounter")
}
if !mounter.GetAttributes().ReadOnly {
t.Errorf("Expected true for mounter.IsReadOnly")

View File

@ -317,7 +317,7 @@ func TestPlugin(t *testing.T) {
t.Errorf("Failed to make a new Mounter: %v", err)
}
if mounter == nil {
t.Errorf("Got a nil Mounter")
t.Fatalf("Got a nil Mounter")
}
vName, err := plugin.GetVolumeName(volume.NewSpecFromVolume(volumeSpec))
@ -381,7 +381,7 @@ func TestPluginReboot(t *testing.T) {
t.Errorf("Failed to make a new Mounter: %v", err)
}
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)
@ -597,7 +597,7 @@ func doTestCleanAndTeardown(plugin volume.VolumePlugin, podUID types.UID, testVo
t.Errorf("Failed to make a new Unmounter: %v", err)
}
if unmounter == nil {
t.Errorf("Got a nil Unmounter")
t.Fatalf("Got a nil Unmounter")
}
if err := unmounter.TearDown(); err != nil {

View File

@ -241,7 +241,7 @@ func newDownwardAPITest(t *testing.T, name string, volumeFiles, podLabels, podAn
t.Errorf("Failed to make a new Mounter: %v", err)
}
if mounter == nil {
t.Errorf("Got a nil Mounter")
t.Fatalf("Got a nil Mounter")
}
volumePath := mounter.GetPath()
@ -278,7 +278,7 @@ func (test *downwardAPITest) tearDown() {
test.t.Errorf("Failed to make a new Unmounter: %v", err)
}
if unmounter == nil {
test.t.Errorf("Got a nil Unmounter")
test.t.Fatalf("Got a nil Unmounter")
}
if err := unmounter.TearDown(); err != nil {

View File

@ -221,7 +221,7 @@ func TestPluginBackCompat(t *testing.T) {
t.Errorf("Failed to make a new Mounter: %v", err)
}
if mounter == nil {
t.Errorf("Got a nil Mounter")
t.Fatalf("Got a nil Mounter")
}
volPath := mounter.GetPath()
@ -249,6 +249,9 @@ func TestMetrics(t *testing.T) {
if err != nil {
t.Errorf("Failed to make a new Mounter: %v", err)
}
if mounter == nil {
t.Fatalf("Got a nil Mounter")
}
// Need to create the subdirectory
os.MkdirAll(mounter.GetPath(), 0755)

View File

@ -362,6 +362,9 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
spec := volume.NewSpecFromPersistentVolume(pv, true)
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}}
mounter, _ := plug.NewMounter(spec, pod, volume.VolumeOptions{})
if mounter == nil {
t.Fatalf("Got a nil Mounter")
}
if !mounter.GetAttributes().ReadOnly {
t.Errorf("Expected true for mounter.IsReadOnly")

View File

@ -251,6 +251,9 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
spec := volume.NewSpecFromPersistentVolume(pv, true)
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}}
mounter, _ := plug.NewMounter(spec, pod, volume.VolumeOptions{})
if mounter == nil {
t.Fatalf("Got a nil Mounter")
}
if !mounter.GetAttributes().ReadOnly {
t.Errorf("Expected true for mounter.IsReadOnly")

View File

@ -225,7 +225,7 @@ func TestPlugin(t *testing.T) {
t.Errorf("Failed to make a new Mounter: %v", err)
}
if mounter == nil {
t.Errorf("Got a nil Mounter")
t.Fatalf("Got a nil Mounter")
}
path := mounter.GetPath()
@ -242,7 +242,7 @@ func TestPlugin(t *testing.T) {
t.Errorf("Failed to make a new Unmounter: %v", err)
}
if unmounter == nil {
t.Errorf("Got a nil Unmounter")
t.Fatalf("Got a nil Unmounter")
}
if err := unmounter.TearDown(); err != nil {
@ -288,6 +288,9 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
spec := volume.NewSpecFromPersistentVolume(pv, true)
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}}
mounter, _ := plug.NewMounter(spec, pod, volume.VolumeOptions{})
if mounter == nil {
t.Fatalf("Got a nil Mounter")
}
if !mounter.GetAttributes().ReadOnly {
t.Errorf("Expected true for mounter.IsReadOnly")

View File

@ -283,6 +283,9 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
spec := volume.NewSpecFromPersistentVolume(pv, true)
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}}
mounter, _ := plug.NewMounter(spec, pod, volume.VolumeOptions{})
if mounter == nil {
t.Fatalf("Got a nil Mounter")
}
if !mounter.GetAttributes().ReadOnly {
t.Errorf("Expected true for mounter.IsReadOnly")

View File

@ -247,6 +247,9 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
spec := volume.NewSpecFromPersistentVolume(pv, true)
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}}
mounter, _ := plug.NewMounter(spec, pod, volume.VolumeOptions{})
if mounter == nil {
t.Fatalf("Got a nil Mounter")
}
if !mounter.GetAttributes().ReadOnly {
t.Errorf("Expected true for mounter.IsReadOnly")

View File

@ -194,6 +194,9 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
spec := volume.NewSpecFromPersistentVolume(pv, true)
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}}
mounter, _ := plug.NewMounter(spec, pod, volume.VolumeOptions{})
if mounter == nil {
t.Fatalf("Got a nil Mounter")
}
if !mounter.GetAttributes().ReadOnly {
t.Errorf("Expected true for mounter.IsReadOnly")

View File

@ -235,6 +235,9 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) {
spec := volume.NewSpecFromPersistentVolume(pv, true)
pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{UID: types.UID("poduid")}}
mounter, _ := plug.NewMounter(spec, pod, volume.VolumeOptions{})
if mounter == nil {
t.Fatalf("Got a nil Mounter")
}
if !mounter.GetAttributes().ReadOnly {
t.Errorf("Expected true for mounter.IsReadOnly")

View File

@ -319,7 +319,7 @@ func TestPlugin(t *testing.T) {
t.Errorf("Failed to make a new Mounter: %v", err)
}
if mounter == nil {
t.Errorf("Got a nil Mounter")
t.Fatalf("Got a nil Mounter")
}
volumePath := mounter.GetPath()
@ -392,7 +392,7 @@ func TestPluginReboot(t *testing.T) {
t.Errorf("Failed to make a new Mounter: %v", err)
}
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)
@ -617,7 +617,7 @@ func doTestCleanAndTeardown(plugin volume.VolumePlugin, podUID types.UID, testVo
t.Errorf("Failed to make a new Unmounter: %v", err)
}
if unmounter == nil {
t.Errorf("Got a nil Unmounter")
t.Fatalf("Got a nil Unmounter")
}
if err := unmounter.TearDown(); err != nil {