@@ -61,9 +61,9 @@ var contactQueryTests = []struct {
61
61
}
62
62
63
63
func TestContacts (t * testing.T ) {
64
- db := setup (t )
64
+ cfg , db := setup (t )
65
65
66
- ix1 := indexers .NewContactIndexer (elasticURL , aliasName , 2 , 1 , 4 )
66
+ ix1 := indexers .NewContactIndexer (cfg . ElasticURL , aliasName , 2 , 1 , 4 )
67
67
assert .Equal (t , "indexer_test" , ix1 .Name ())
68
68
69
69
dbModified , err := ix1 .GetDBLastModified (context .Background (), db )
@@ -87,10 +87,10 @@ func TestContacts(t *testing.T) {
87
87
assert .WithinDuration (t , time .Date (2017 , 11 , 10 , 21 , 11 , 59 , 890662000 , time .UTC ), esModified , 0 )
88
88
89
89
assertIndexerStats (t , ix1 , 9 , 0 )
90
- assertIndexesWithPrefix (t , aliasName , []string {expectedIndexName })
90
+ assertIndexesWithPrefix (t , cfg , aliasName , []string {expectedIndexName })
91
91
92
92
for _ , tc := range contactQueryTests {
93
- assertQuery (t , []byte (tc .query ), tc .expected , "query mismatch for %s" , tc .query )
93
+ assertQuery (t , cfg , []byte (tc .query ), tc .expected , "query mismatch for %s" , tc .query )
94
94
}
95
95
96
96
lastModified , err := ix1 .GetESLastModified (indexName )
@@ -112,21 +112,21 @@ func TestContacts(t *testing.T) {
112
112
113
113
time .Sleep (1 * time .Second )
114
114
115
- assertIndexesWithPrefix (t , aliasName , []string {expectedIndexName })
115
+ assertIndexesWithPrefix (t , cfg , aliasName , []string {expectedIndexName })
116
116
117
117
// should only match new john, old john is gone
118
- assertQuery (t , []byte (`{"match": {"name": {"query": "john"}}}` ), []int64 {2 })
118
+ assertQuery (t , cfg , []byte (`{"match": {"name": {"query": "john"}}}` ), []int64 {2 })
119
119
120
120
// 3 is no longer in our group
121
- assertQuery (t , []byte (`{"match": {"group_ids": {"query": 4}}}` ), []int64 {1 })
121
+ assertQuery (t , cfg , []byte (`{"match": {"group_ids": {"query": 4}}}` ), []int64 {1 })
122
122
123
123
// change John's name to Eric..
124
124
_ , err = db .Exec (`
125
125
UPDATE contacts_contact SET name = 'Eric', modified_on = '2020-08-20 14:00:00+00' where id = 2;` )
126
126
require .NoError (t , err )
127
127
128
128
// and simulate another indexer doing a parallel rebuild
129
- ix2 := indexers .NewContactIndexer (elasticURL , aliasName , 2 , 1 , 4 )
129
+ ix2 := indexers .NewContactIndexer (cfg . ElasticURL , aliasName , 2 , 1 , 4 )
130
130
131
131
indexName2 , err := ix2 .Index (db , true , false )
132
132
assert .NoError (t , err )
@@ -136,20 +136,20 @@ func TestContacts(t *testing.T) {
136
136
time .Sleep (1 * time .Second )
137
137
138
138
// check we have a new index but the old index is still around
139
- assertIndexesWithPrefix (t , aliasName , []string {expectedIndexName , expectedIndexName + "_1" })
139
+ assertIndexesWithPrefix (t , cfg , aliasName , []string {expectedIndexName , expectedIndexName + "_1" })
140
140
141
141
// and the alias points to the new index
142
- assertQuery (t , []byte (`{"match": {"name": {"query": "eric"}}}` ), []int64 {2 })
142
+ assertQuery (t , cfg , []byte (`{"match": {"name": {"query": "eric"}}}` ), []int64 {2 })
143
143
144
144
// simulate another indexer doing a parallel rebuild with cleanup
145
- ix3 := indexers .NewContactIndexer (elasticURL , aliasName , 2 , 1 , 4 )
145
+ ix3 := indexers .NewContactIndexer (cfg . ElasticURL , aliasName , 2 , 1 , 4 )
146
146
indexName3 , err := ix3 .Index (db , true , true )
147
147
assert .NoError (t , err )
148
148
assert .Equal (t , expectedIndexName + "_2" , indexName3 ) // new index used
149
149
assertIndexerStats (t , ix3 , 8 , 0 )
150
150
151
151
// check we cleaned up indexes besides the new one
152
- assertIndexesWithPrefix (t , aliasName , []string {expectedIndexName + "_2" })
152
+ assertIndexesWithPrefix (t , cfg , aliasName , []string {expectedIndexName + "_2" })
153
153
154
154
// check that the original indexer now indexes against the new index
155
155
indexName , err = ix1 .Index (db , false , false )
0 commit comments