1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
package mongorestore
import (
"testing"
"github.com/mongodb/mongo-tools/common/testutil"
. "github.com/smartystreets/goconvey/convey"
"gopkg.in/mgo.v2/bson"
)
func TestTimestampStringParsing(t *testing.T) {
testutil.VerifyTestType(t, testutil.UnitTestType)
Convey("Testing some possible timestamp strings:", t, func() {
Convey("123:456 [should pass]", func() {
ts, err := ParseTimestampFlag("123:456")
So(err, ShouldBeNil)
So(ts, ShouldEqual, (int64(123)<<32 | int64(456)))
})
Convey("123 [should pass]", func() {
ts, err := ParseTimestampFlag("123")
So(err, ShouldBeNil)
So(ts, ShouldEqual, int64(123)<<32)
})
Convey("123: [should pass]", func() {
ts, err := ParseTimestampFlag("123:")
So(err, ShouldBeNil)
So(ts, ShouldEqual, int64(123)<<32)
})
Convey("123.123 [should fail]", func() {
ts, err := ParseTimestampFlag("123.123")
So(err, ShouldNotBeNil)
So(ts, ShouldEqual, 0)
})
Convey(": [should fail]", func() {
ts, err := ParseTimestampFlag(":")
So(err, ShouldNotBeNil)
So(ts, ShouldEqual, 0)
})
Convey("1:1:1 [should fail]", func() {
ts, err := ParseTimestampFlag("1:1:1")
So(err, ShouldNotBeNil)
So(ts, ShouldEqual, 0)
})
Convey("cats [should fail]", func() {
ts, err := ParseTimestampFlag("cats")
So(err, ShouldNotBeNil)
So(ts, ShouldEqual, 0)
})
Convey("[empty string] [should fail]", func() {
ts, err := ParseTimestampFlag("")
So(err, ShouldNotBeNil)
So(ts, ShouldEqual, 0)
})
})
}
func TestValidOplogLimitChecking(t *testing.T) {
testutil.VerifyTestType(t, testutil.UnitTestType)
Convey("With a MongoRestore instance with oplogLimit of 5:0", t, func() {
mr := &MongoRestore{
oplogLimit: bson.MongoTimestamp(int64(5) << 32),
}
Convey("an oplog entry with ts=1000:0 should be invalid", func() {
So(mr.TimestampBeforeLimit(bson.MongoTimestamp(int64(1000)<<32)), ShouldBeFalse)
})
Convey("an oplog entry with ts=5:1 should be invalid", func() {
So(mr.TimestampBeforeLimit(bson.MongoTimestamp(int64(5)<<32|1)), ShouldBeFalse)
})
Convey("an oplog entry with ts=5:0 should be invalid", func() {
So(mr.TimestampBeforeLimit(bson.MongoTimestamp(int64(5)<<32)), ShouldBeFalse)
})
Convey("an oplog entry with ts=4:9 should be valid", func() {
So(mr.TimestampBeforeLimit(bson.MongoTimestamp(int64(4)<<32|9)), ShouldBeTrue)
})
Convey("an oplog entry with ts=4:0 should be valid", func() {
So(mr.TimestampBeforeLimit(bson.MongoTimestamp(int64(4)<<32)), ShouldBeTrue)
})
Convey("an oplog entry with ts=0:1 should be valid", func() {
So(mr.TimestampBeforeLimit(bson.MongoTimestamp(1)), ShouldBeTrue)
})
})
Convey("With a MongoRestore instance with no oplogLimit", t, func() {
mr := &MongoRestore{}
Convey("an oplog entry with ts=1000:0 should be valid", func() {
So(mr.TimestampBeforeLimit(bson.MongoTimestamp(int64(1000)<<32)), ShouldBeTrue)
})
Convey("an oplog entry with ts=5:1 should be valid", func() {
So(mr.TimestampBeforeLimit(bson.MongoTimestamp(int64(5)<<32|1)), ShouldBeTrue)
})
Convey("an oplog entry with ts=5:0 should be valid", func() {
So(mr.TimestampBeforeLimit(bson.MongoTimestamp(int64(5)<<32)), ShouldBeTrue)
})
})
}
|