From c01bac90eb5760180c61031b17edc67782a72886 Mon Sep 17 00:00:00 2001 From: Tamer Tas Date: Fri, 18 Sep 2015 13:56:13 +0300 Subject: [PATCH] Refactor downward API volume plugin test --- pkg/volume/downwardapi/downwardapi_test.go | 41 +++++++++++++--------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/pkg/volume/downwardapi/downwardapi_test.go b/pkg/volume/downwardapi/downwardapi_test.go index cb7906be6dc..371bc583227 100644 --- a/pkg/volume/downwardapi/downwardapi_test.go +++ b/pkg/volume/downwardapi/downwardapi_test.go @@ -600,7 +600,8 @@ func TestWriteWithUnixPathBadPath(t *testing.T) { labels := map[string]string{ "key1": "value1", - "key2": "value2"} + "key2": "value2", + } fake := testclient.NewSimpleFake(&api.Pod{ ObjectMeta: api.ObjectMeta{ @@ -613,42 +614,48 @@ func TestWriteWithUnixPathBadPath(t *testing.T) { pluginMgr := volume.VolumePluginMgr{} pluginMgr.InitPlugins(ProbeVolumePlugins(), newTestHost(t, fake)) plugin, err := pluginMgr.FindPluginByName(downwardAPIPluginName) + if err != nil { + t.Errorf("Can't find the plugin by name") + } + volumeSpec := &api.Volume{ Name: testVolumeName, VolumeSource: api.VolumeSource{ DownwardAPI: &api.DownwardAPIVolumeSource{ Items: []api.DownwardAPIVolumeFile{ - {Path: "this//labels", FieldRef: api.ObjectFieldSelector{ - FieldPath: "metadata.labels"}}, - }}}, - } - if err != nil { - t.Errorf("Can't find the plugin by name") + { + Path: "this//labels", + FieldRef: api.ObjectFieldSelector{ + FieldPath: "metadata.labels", + }, + }, + }, + }, + }, } + pod := &api.Pod{ObjectMeta: api.ObjectMeta{UID: testPodUID, Labels: labels}} builder, err := plugin.NewBuilder(volume.NewSpecFromVolume(volumeSpec), pod, volume.VolumeOptions{}) - if err != nil { - t.Errorf("Failed to make a new Builder: %v", err) - } - if builder == nil { - t.Errorf("Got a nil Builder") + t.Fatalf("Failed to make a new Builder: %v", err) + } else if builder == nil { + t.Fatalf("Got a nil Builder") } volumePath := builder.GetPath() + defer CleanEverything(plugin, testVolumeName, volumePath, testPodUID, t) + err = builder.SetUp() if err != nil { - t.Errorf("Failed to setup volume: %v", err) + t.Fatalf("Failed to setup volume: %v", err) } - var data []byte - data, err = ioutil.ReadFile(path.Join(volumePath, "this/labels")) + data, err := ioutil.ReadFile(path.Join(volumePath, "this/labels")) if err != nil { - t.Errorf(err.Error()) + t.Fatalf(err.Error()) } if sortLines(string(data)) != sortLines(formatMap(labels)) { t.Errorf("Found `%s` expected %s", data, formatMap(labels)) } - CleanEverything(plugin, testVolumeName, volumePath, testPodUID, t) }