volume_linux_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // +build linux
  2. package volume
  3. import (
  4. "strings"
  5. "testing"
  6. mounttypes "github.com/docker/docker/api/types/mount"
  7. )
  8. func TestConvertTmpfsOptions(t *testing.T) {
  9. type testCase struct {
  10. opt mounttypes.TmpfsOptions
  11. readOnly bool
  12. expectedSubstrings []string
  13. unexpectedSubstrings []string
  14. }
  15. cases := []testCase{
  16. {
  17. opt: mounttypes.TmpfsOptions{SizeBytes: 1024 * 1024, Mode: 0700},
  18. readOnly: false,
  19. expectedSubstrings: []string{"size=1m", "mode=700"},
  20. unexpectedSubstrings: []string{"ro"},
  21. },
  22. {
  23. opt: mounttypes.TmpfsOptions{},
  24. readOnly: true,
  25. expectedSubstrings: []string{"ro"},
  26. unexpectedSubstrings: []string{},
  27. },
  28. }
  29. for _, c := range cases {
  30. data, err := ConvertTmpfsOptions(&c.opt, c.readOnly)
  31. if err != nil {
  32. t.Fatalf("could not convert %+v (readOnly: %v) to string: %v",
  33. c.opt, c.readOnly, err)
  34. }
  35. t.Logf("data=%q", data)
  36. for _, s := range c.expectedSubstrings {
  37. if !strings.Contains(data, s) {
  38. t.Fatalf("expected substring: %s, got %v (case=%+v)", s, data, c)
  39. }
  40. }
  41. for _, s := range c.unexpectedSubstrings {
  42. if strings.Contains(data, s) {
  43. t.Fatalf("unexpected substring: %s, got %v (case=%+v)", s, data, c)
  44. }
  45. }
  46. }
  47. }