Introduce test harness into unit tests

The harness lets us execute code after the test has completed.

Use it to clean-up temp dirs in the flexvolume tests (initially).
This commit is contained in:
Justin Santa Barbara
2018-10-08 18:37:48 -04:00
parent f883fd2ce6
commit 58fc3c8c23
10 changed files with 156 additions and 28 deletions

View File

@@ -18,10 +18,15 @@ package flexvolume
import (
"testing"
"k8s.io/kubernetes/test/utils/harness"
)
func TestDetach(t *testing.T) {
plugin, _ := testPlugin()
func TestDetach(tt *testing.T) {
t := harness.For(tt)
defer t.Close()
plugin, _ := testPlugin(t)
plugin.runner = fakeRunner(
assertDriverCall(t, notSupportedOutput(), detachCmd,
"sdx", "localhost"),
@@ -31,8 +36,11 @@ func TestDetach(t *testing.T) {
d.Detach("sdx", "localhost")
}
func TestUnmountDevice(t *testing.T) {
plugin, rootDir := testPlugin()
func TestUnmountDevice(tt *testing.T) {
t := harness.For(tt)
defer t.Close()
plugin, rootDir := testPlugin(t)
plugin.runner = fakeRunner(
assertDriverCall(t, notSupportedOutput(), unmountDeviceCmd,
rootDir+"/mount-dir"),