summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAudrius Butkevicius <audrius.butkevicius@gmail.com>2015-08-19 20:11:19 +0100
committerAudrius Butkevicius <audrius.butkevicius@gmail.com>2015-08-19 20:11:19 +0100
commit50702eda94d07bb3544c66aa1a0106bd3a2a7f33 (patch)
tree12c7c8265e9699b0c97cb5cec5b8883735583819
parent59eeafbdfae7c7026ad65f2288595d6c50fd7b6a (diff)
parent47a1494d6840a85479998a25068eab8d32a95424 (diff)
Merge pull request #2171 from Zillode/staggered-test
Add unit test for staggered versioning (fixes #2165)
-rw-r--r--lib/versioner/staggered_test.go84
1 files changed, 84 insertions, 0 deletions
diff --git a/lib/versioner/staggered_test.go b/lib/versioner/staggered_test.go
new file mode 100644
index 000000000..d25202442
--- /dev/null
+++ b/lib/versioner/staggered_test.go
@@ -0,0 +1,84 @@
+// Copyright (C) 2014 The Syncthing Authors.
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this file,
+// You can obtain one at http://mozilla.org/MPL/2.0/.
+
+package versioner
+
+import (
+ "io/ioutil"
+ "os"
+ "path/filepath"
+ "testing"
+ "time"
+)
+
+func TestStaggeredVersioningVersionCount(t *testing.T) {
+ if testing.Short() {
+ t.Skip("Test takes some time, skipping.")
+ }
+
+ dir, err := ioutil.TempDir("", "")
+ defer os.RemoveAll(dir)
+ if err != nil {
+ t.Error(err)
+ }
+
+ v := NewStaggered("", dir, map[string]string{"maxAge": "365"})
+ versionDir := filepath.Join(dir, ".stversions")
+
+ path := filepath.Join(dir, "test")
+
+ for i := 1; i <= 3; i++ {
+ f, err := os.Create(path)
+ if err != nil {
+ t.Error(err)
+ }
+ f.Close()
+ v.Archive(path)
+
+ d, err := os.Open(versionDir)
+ if err != nil {
+ t.Error(err)
+ }
+ n, err := d.Readdirnames(-1)
+ if err != nil {
+ t.Error(err)
+ }
+
+ if len(n) != 1 {
+ t.Error("Wrong count")
+ }
+ d.Close()
+
+ time.Sleep(time.Second)
+ }
+ os.RemoveAll(path)
+
+ for i := 1; i <= 3; i++ {
+ f, err := os.Create(path)
+ if err != nil {
+ t.Error(err)
+ }
+ f.Close()
+ v.Archive(path)
+
+ d, err := os.Open(versionDir)
+ if err != nil {
+ t.Error(err)
+ }
+ n, err := d.Readdirnames(-1)
+ if err != nil {
+ t.Error(err)
+ }
+
+ if len(n) != i {
+ t.Error("Wrong count")
+ }
+ d.Close()
+
+ time.Sleep(31 * time.Second)
+ }
+ os.RemoveAll(path)
+}