volume_propagation_linux_test.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // +build linux
  2. package volume
  3. import (
  4. "strings"
  5. "testing"
  6. )
  7. func TestParseMountRawPropagation(t *testing.T) {
  8. var (
  9. valid []string
  10. invalid map[string]string
  11. )
  12. valid = []string{
  13. "/hostPath:/containerPath:shared",
  14. "/hostPath:/containerPath:rshared",
  15. "/hostPath:/containerPath:slave",
  16. "/hostPath:/containerPath:rslave",
  17. "/hostPath:/containerPath:private",
  18. "/hostPath:/containerPath:rprivate",
  19. "/hostPath:/containerPath:ro,shared",
  20. "/hostPath:/containerPath:ro,slave",
  21. "/hostPath:/containerPath:ro,private",
  22. "/hostPath:/containerPath:ro,z,shared",
  23. "/hostPath:/containerPath:ro,Z,slave",
  24. "/hostPath:/containerPath:Z,ro,slave",
  25. "/hostPath:/containerPath:slave,Z,ro",
  26. "/hostPath:/containerPath:Z,slave,ro",
  27. "/hostPath:/containerPath:slave,ro,Z",
  28. "/hostPath:/containerPath:rslave,ro,Z",
  29. "/hostPath:/containerPath:ro,rshared,Z",
  30. "/hostPath:/containerPath:ro,Z,rprivate",
  31. }
  32. invalid = map[string]string{
  33. "/path:/path:ro,rshared,rslave": `invalid mode`,
  34. "/path:/path:ro,z,rshared,rslave": `invalid mode`,
  35. "/path:shared": "invalid volume specification",
  36. "/path:slave": "invalid volume specification",
  37. "/path:private": "invalid volume specification",
  38. "name:/absolute-path:shared": "invalid volume specification",
  39. "name:/absolute-path:rshared": "invalid volume specification",
  40. "name:/absolute-path:slave": "invalid volume specification",
  41. "name:/absolute-path:rslave": "invalid volume specification",
  42. "name:/absolute-path:private": "invalid volume specification",
  43. "name:/absolute-path:rprivate": "invalid volume specification",
  44. }
  45. for _, path := range valid {
  46. if _, err := ParseMountRaw(path, "local"); err != nil {
  47. t.Fatalf("ParseMountRaw(`%q`) should succeed: error %q", path, err)
  48. }
  49. }
  50. for path, expectedError := range invalid {
  51. if _, err := ParseMountRaw(path, "local"); err == nil {
  52. t.Fatalf("ParseMountRaw(`%q`) should have failed validation. Err %v", path, err)
  53. } else {
  54. if !strings.Contains(err.Error(), expectedError) {
  55. t.Fatalf("ParseMountRaw(`%q`) error should contain %q, got %v", path, expectedError, err.Error())
  56. }
  57. }
  58. }
  59. }