mount_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. Copyright 2018 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 mount
  14. import (
  15. "reflect"
  16. "testing"
  17. )
  18. func TestIsBind(t *testing.T) {
  19. tests := []struct {
  20. mountOption []string
  21. isBind bool
  22. expectedBindOpts []string
  23. expectedRemountOpts []string
  24. }{
  25. {
  26. []string{"vers=2", "ro", "_netdev"},
  27. false,
  28. []string{},
  29. []string{},
  30. },
  31. {
  32. []string{"bind", "vers=2", "ro", "_netdev"},
  33. true,
  34. []string{"bind", "_netdev"},
  35. []string{"bind", "remount", "vers=2", "ro", "_netdev"},
  36. },
  37. }
  38. for _, test := range tests {
  39. bind, bindOpts, bindRemountOpts := IsBind(test.mountOption)
  40. if bind != test.isBind {
  41. t.Errorf("Expected bind to be %v but got %v", test.isBind, bind)
  42. }
  43. if test.isBind {
  44. if !reflect.DeepEqual(test.expectedBindOpts, bindOpts) {
  45. t.Errorf("Expected bind mount options to be %+v got %+v", test.expectedBindOpts, bindOpts)
  46. }
  47. if !reflect.DeepEqual(test.expectedRemountOpts, bindRemountOpts) {
  48. t.Errorf("Expected remount options to be %+v got %+v", test.expectedRemountOpts, bindRemountOpts)
  49. }
  50. }
  51. }
  52. }