1
16
17 package flexvolume
18
19 import (
20 "testing"
21 "time"
22
23 v1 "k8s.io/api/core/v1"
24 "k8s.io/kubernetes/pkg/volume"
25 "k8s.io/kubernetes/test/utils/harness"
26 )
27
28 func TestAttach(tt *testing.T) {
29 t := harness.For(tt)
30 defer t.Close()
31
32 spec := fakeVolumeSpec()
33
34 plugin, _ := testPlugin(t)
35 plugin.runner = fakeRunner(
36 assertDriverCall(t, notSupportedOutput(), attachCmd,
37 specJSON(plugin, spec, nil), "localhost"),
38 )
39
40 a, _ := plugin.NewAttacher()
41 a.Attach(spec, "localhost")
42 }
43
44 func TestWaitForAttach(tt *testing.T) {
45 t := harness.For(tt)
46 defer t.Close()
47
48 spec := fakeVolumeSpec()
49 var pod *v1.Pod
50 plugin, _ := testPlugin(t)
51 plugin.runner = fakeRunner(
52 assertDriverCall(t, notSupportedOutput(), waitForAttachCmd, "/dev/sdx",
53 specJSON(plugin, spec, nil)),
54 )
55
56 a, _ := plugin.NewAttacher()
57 a.WaitForAttach(spec, "/dev/sdx", pod, 1*time.Second)
58 }
59
60 func TestMountDevice(tt *testing.T) {
61 t := harness.For(tt)
62 defer t.Close()
63
64 spec := fakeVolumeSpec()
65
66 plugin, rootDir := testPlugin(t)
67 plugin.runner = fakeRunner(
68 assertDriverCall(t, notSupportedOutput(), mountDeviceCmd, rootDir+"/mount-dir", "/dev/sdx",
69 specJSON(plugin, spec, nil)),
70 )
71
72 a, _ := plugin.NewAttacher()
73 a.MountDevice(spec, "/dev/sdx", rootDir+"/mount-dir", volume.DeviceMounterArgs{})
74 }
75
76 func TestIsVolumeAttached(tt *testing.T) {
77 t := harness.For(tt)
78 defer t.Close()
79
80 spec := fakeVolumeSpec()
81
82 plugin, _ := testPlugin(t)
83 plugin.runner = fakeRunner(
84 assertDriverCall(t, notSupportedOutput(), isAttached, specJSON(plugin, spec, nil), "localhost"),
85 )
86 a, _ := plugin.NewAttacher()
87 specs := []*volume.Spec{spec}
88 a.VolumesAreAttached(specs, "localhost")
89 }
90
View as plain text