staggered_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright (C) 2014 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at http://mozilla.org/MPL/2.0/.
  6. package versioner
  7. import (
  8. "io/ioutil"
  9. "os"
  10. "path/filepath"
  11. "testing"
  12. "time"
  13. )
  14. func TestStaggeredVersioningVersionCount(t *testing.T) {
  15. if testing.Short() {
  16. t.Skip("Test takes some time, skipping.")
  17. }
  18. dir, err := ioutil.TempDir("", "")
  19. defer os.RemoveAll(dir)
  20. if err != nil {
  21. t.Error(err)
  22. }
  23. v := NewStaggered("", dir, map[string]string{"maxAge": "365"})
  24. versionDir := filepath.Join(dir, ".stversions")
  25. path := filepath.Join(dir, "test")
  26. for i := 1; i <= 3; i++ {
  27. f, err := os.Create(path)
  28. if err != nil {
  29. t.Error(err)
  30. }
  31. f.Close()
  32. v.Archive(path)
  33. d, err := os.Open(versionDir)
  34. if err != nil {
  35. t.Error(err)
  36. }
  37. n, err := d.Readdirnames(-1)
  38. if err != nil {
  39. t.Error(err)
  40. }
  41. if len(n) != 1 {
  42. t.Error("Wrong count")
  43. }
  44. d.Close()
  45. time.Sleep(time.Second)
  46. }
  47. os.RemoveAll(path)
  48. for i := 1; i <= 3; i++ {
  49. f, err := os.Create(path)
  50. if err != nil {
  51. t.Error(err)
  52. }
  53. f.Close()
  54. v.Archive(path)
  55. d, err := os.Open(versionDir)
  56. if err != nil {
  57. t.Error(err)
  58. }
  59. n, err := d.Readdirnames(-1)
  60. if err != nil {
  61. t.Error(err)
  62. }
  63. if len(n) != i {
  64. t.Error("Wrong count")
  65. }
  66. d.Close()
  67. time.Sleep(31 * time.Second)
  68. }
  69. os.RemoveAll(path)
  70. }