...
1
16
17 package flexvolume
18
19 import (
20 "testing"
21
22 "k8s.io/mount-utils"
23
24 v1 "k8s.io/api/core/v1"
25 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26 "k8s.io/apimachinery/pkg/types"
27 "k8s.io/kubernetes/pkg/volume"
28 "k8s.io/kubernetes/test/utils/harness"
29 )
30
31 func TestSetUpAt(tt *testing.T) {
32 t := harness.For(tt)
33 defer t.Close()
34
35 spec := fakeVolumeSpec()
36 pod := &v1.Pod{
37 ObjectMeta: metav1.ObjectMeta{
38 Name: "my-pod",
39 Namespace: "my-ns",
40 UID: types.UID("my-uid"),
41 },
42 Spec: v1.PodSpec{
43 ServiceAccountName: "my-sa",
44 },
45 }
46 mounter := mount.NewFakeMounter(nil)
47
48 plugin, rootDir := testPlugin(t)
49 plugin.unsupportedCommands = []string{"unsupportedCmd"}
50 plugin.runner = fakeRunner(
51
52 assertDriverCall(t, successOutput(), mountCmd, rootDir+"/mount-dir",
53 specJSON(plugin, spec, map[string]string{
54 optionKeyPodName: "my-pod",
55 optionKeyPodNamespace: "my-ns",
56 optionKeyPodUID: "my-uid",
57 optionKeyServiceAccountName: "my-sa",
58 })),
59
60
61 assertDriverCall(t, notSupportedOutput(), mountCmd, rootDir+"/mount-dir",
62 specJSON(plugin, spec, map[string]string{
63 optionFSGroup: "42",
64 optionKeyPodName: "my-pod",
65 optionKeyPodNamespace: "my-ns",
66 optionKeyPodUID: "my-uid",
67 optionKeyServiceAccountName: "my-sa",
68 })),
69 assertDriverCall(t, fakeVolumeNameOutput("sdx"), getVolumeNameCmd,
70 specJSON(plugin, spec, nil)),
71 )
72
73 m, _ := plugin.newMounterInternal(spec, pod, mounter, plugin.runner)
74 var mounterArgs volume.MounterArgs
75 m.SetUpAt(rootDir+"/mount-dir", mounterArgs)
76
77 group := int64(42)
78 mounterArgs.FsGroup = &group
79 m.SetUpAt(rootDir+"/mount-dir", mounterArgs)
80 }
81
View as plain text