-
Notifications
You must be signed in to change notification settings - Fork 139
/
Copy pathblip_sync_messages_test.go
111 lines (90 loc) · 2.72 KB
/
blip_sync_messages_test.go
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
/*
Copyright 2018-Present Couchbase, Inc.
Use of this software is governed by the Business Source License included in
the file licenses/BSL-Couchbase.txt. As of the Change Date specified in that
file, in accordance with the Business Source License, use of this software will
be governed by the Apache License, Version 2.0, included in the file
licenses/APL2.txt.
*/
package rest
import (
"testing"
"github.com/couchbase/go-blip"
"github.com/couchbase/sync_gateway/base"
"github.com/couchbase/sync_gateway/db"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAddRevision(t *testing.T) {
testCases := []struct {
deletedPropertyValue string
expectedDeletedVal bool
}{
{
deletedPropertyValue: "true",
expectedDeletedVal: true,
},
{
deletedPropertyValue: "truedat",
expectedDeletedVal: true,
},
{
deletedPropertyValue: "0",
expectedDeletedVal: false,
},
{
deletedPropertyValue: "false",
expectedDeletedVal: false,
},
{
deletedPropertyValue: "False",
expectedDeletedVal: true, // Counter-intuitive! deleted() should probably lowercase the string before comparing
},
{
deletedPropertyValue: "",
expectedDeletedVal: true, // It's not false, so it's true
},
{
deletedPropertyValue: "nil",
expectedDeletedVal: false, // was not set, so it's false
},
}
for _, testCase := range testCases {
blipMessage := blip.Message{}
blipMessage.Properties = blip.Properties{}
if testCase.deletedPropertyValue != "nil" {
blipMessage.Properties["deleted"] = testCase.deletedPropertyValue
}
revMessage := &db.RevMessage{
Message: &blipMessage,
}
assert.Equal(t, testCase.expectedDeletedVal, revMessage.Deleted())
}
}
// Make sure that the subChangesParams helper deals correctly with JSON strings.
// Reproduces SG #3283
func TestSubChangesSince(t *testing.T) {
rt := NewRestTester(t, nil)
defer rt.Close()
rq := blip.NewRequest()
rq.Properties["since"] = `"1"`
subChangesParams, err := db.NewSubChangesParams(base.TestCtx(t), rq, nil, rt.GetDatabase().Options.ChangesRequestPlus)
require.NoError(t, err)
seqID := subChangesParams.Since()
assert.Equal(t, uint64(1), seqID.Seq)
}
// Tests parsing the "future" mode of subChanges.
func TestSubChangesFuture(t *testing.T) {
rt := NewRestTester(t, nil)
defer rt.Close()
latestSeq := func() (db.SequenceID, error) {
return db.SequenceID{Seq: 999}, nil
}
rq := blip.NewRequest()
rq.Properties["future"] = "true"
rq.Properties["since"] = `"1"`
subChangesParams, err := db.NewSubChangesParams(base.TestCtx(t), rq, latestSeq, rt.GetDatabase().Options.ChangesRequestPlus)
require.NoError(t, err)
seqID := subChangesParams.Since()
assert.Equal(t, uint64(999), seqID.Seq)
}