This repository has been archived by the owner on Aug 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
listener_test.go
123 lines (103 loc) · 3.24 KB
/
listener_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
112
113
114
115
116
117
118
119
120
121
122
123
// Copyright 2017 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package apidAnalytics
import (
"github.com/apid/apid-core"
"github.com/apigee-labs/transicator/common"
)
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
const (
LISTENER_TABLE_DATA_SCOPE = "edgex.data_scope"
)
var _ = Describe("ApigeeSync event", func() {
handler := handler{}
Context("ApigeeSync snapshot event", func() {
var db apid.DB
var snapshot common.Snapshot
BeforeEach(func() {
db = getDB()
snapshot = common.Snapshot{SnapshotInfo: "test_snapshot"}
})
AfterEach(func() {
setDB(db)
})
It("should set DB to appropriate version", func() {
handler.Handle(&snapshot)
expectedDB, err := data.DBVersion(snapshot.SnapshotInfo)
Expect(err).NotTo(HaveOccurred())
Expect(getDB() == expectedDB).Should(BeTrue())
})
})
Context("Process changeList", func() {
Context(LISTENER_TABLE_DATA_SCOPE, func() {
BeforeEach(func() {
config.Set(useCaching, true)
createTenantCache()
Expect(len(tenantCache)).To(Equal(1))
createOrgEnvCache()
Expect(len(orgEnvCache)).To(Equal(1))
})
AfterEach(func() {
config.Set(useCaching, false)
})
It("insert/delete event should add/remove to/from cache if usecaching is true", func() {
insert := common.ChangeList{
LastSequence: "test",
Changes: []common.Change{
{
Operation: common.Insert,
Table: LISTENER_TABLE_DATA_SCOPE,
NewRow: common.Row{
"id": &common.ColumnVal{Value: "i2"},
"_change_selector": &common.ColumnVal{Value: "c2"},
"apid_cluster_id": &common.ColumnVal{Value: "a2"},
"scope": &common.ColumnVal{Value: "s2"},
"org": &common.ColumnVal{Value: "o2"},
"env": &common.ColumnVal{Value: "e2"},
"created": &common.ColumnVal{Value: "c2"},
"created_by": &common.ColumnVal{Value: "c2"},
"updated": &common.ColumnVal{Value: "u2"},
"updated_by": &common.ColumnVal{Value: "u2"},
},
},
},
}
handler.Handle(&insert)
tenant := tenantCache["i2"]
Expect(tenant.Org).To(Equal("o2"))
Expect(tenant.Env).To(Equal("e2"))
orgEnv := getKeyForOrgEnvCache("o2", "e2")
Expect(orgEnvCache[orgEnv]).To(BeTrue())
delete := common.ChangeList{
LastSequence: "test",
Changes: []common.Change{
{
Operation: common.Delete,
Table: LISTENER_TABLE_DATA_SCOPE,
OldRow: insert.Changes[0].NewRow,
},
},
}
handler.Handle(&delete)
_, exists := tenantCache["i2"]
Expect(exists).To(BeFalse())
_, exists = orgEnvCache[orgEnv]
Expect(exists).To(BeFalse())
})
})
})
})