mounter_test.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. Copyright 2017 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package flexvolume
  14. import (
  15. "testing"
  16. "k8s.io/api/core/v1"
  17. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  18. "k8s.io/apimachinery/pkg/types"
  19. "k8s.io/kubernetes/pkg/util/mount"
  20. "k8s.io/kubernetes/pkg/volume"
  21. "k8s.io/kubernetes/test/utils/harness"
  22. )
  23. func TestSetUpAt(tt *testing.T) {
  24. t := harness.For(tt)
  25. defer t.Close()
  26. spec := fakeVolumeSpec()
  27. pod := &v1.Pod{
  28. ObjectMeta: metav1.ObjectMeta{
  29. Name: "my-pod",
  30. Namespace: "my-ns",
  31. UID: types.UID("my-uid"),
  32. },
  33. Spec: v1.PodSpec{
  34. ServiceAccountName: "my-sa",
  35. },
  36. }
  37. mounter := &mount.FakeMounter{}
  38. plugin, rootDir := testPlugin(t)
  39. plugin.unsupportedCommands = []string{"unsupportedCmd"}
  40. plugin.runner = fakeRunner(
  41. // first call without mounterArgs.FsGroup
  42. assertDriverCall(t, successOutput(), mountCmd, rootDir+"/mount-dir",
  43. specJSON(plugin, spec, map[string]string{
  44. optionKeyPodName: "my-pod",
  45. optionKeyPodNamespace: "my-ns",
  46. optionKeyPodUID: "my-uid",
  47. optionKeyServiceAccountName: "my-sa",
  48. })),
  49. // second test has mounterArgs.FsGroup
  50. assertDriverCall(t, notSupportedOutput(), mountCmd, rootDir+"/mount-dir",
  51. specJSON(plugin, spec, map[string]string{
  52. optionFSGroup: "42",
  53. optionKeyPodName: "my-pod",
  54. optionKeyPodNamespace: "my-ns",
  55. optionKeyPodUID: "my-uid",
  56. optionKeyServiceAccountName: "my-sa",
  57. })),
  58. assertDriverCall(t, fakeVolumeNameOutput("sdx"), getVolumeNameCmd,
  59. specJSON(plugin, spec, nil)),
  60. )
  61. m, _ := plugin.newMounterInternal(spec, pod, mounter, plugin.runner)
  62. var mounterArgs volume.MounterArgs
  63. m.SetUpAt(rootDir+"/mount-dir", mounterArgs)
  64. group := int64(42)
  65. mounterArgs.FsGroup = &group
  66. m.SetUpAt(rootDir+"/mount-dir", mounterArgs)
  67. }