-
Notifications
You must be signed in to change notification settings - Fork 9
/
index_copier_test.go
63 lines (54 loc) · 1.75 KB
/
index_copier_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
// Copyright Kuei-chun Chen, 2022-present. All rights reserved.
package hummingbird
import (
"context"
"testing"
"github.com/simagix/keyhole/mdb"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
func TestIndexCopier(t *testing.T) {
ctx := context.Background()
source, err := GetMongoClient(TestSourceURI)
assertEqual(t, nil, err)
dbName, collName := mdb.SplitNamespace(TestNS)
src := source.Database(dbName).Collection(collName)
err = src.Drop(ctx)
assertEqual(t, nil, err)
locale := "zh_Hant"
opts := options.Index()
collation := options.Collation{Locale: locale}
collOpts := options.CreateCollection()
collOpts.SetCollation(&collation)
err = source.Database(dbName).CreateCollection(ctx, collName, collOpts)
assertEqual(t, nil, err)
opts.SetCollation(&collation)
imodel := mongo.IndexModel{Keys: bson.D{{"_id", 1}}, Options: opts}
_, err = src.Indexes().CreateOne(ctx, imodel)
assertEqual(t, nil, err)
target, err := GetMongoClient(TestReplicaURI)
assertEqual(t, nil, err)
tgt := target.Database(dbName).Collection(collName)
err = tgt.Drop(ctx)
assertEqual(t, nil, err)
scursor, err := src.Indexes().List(ctx)
assertEqual(t, nil, err)
scursor.Next(ctx)
var sindex mdb.Index
bson.Unmarshal(scursor.Current, &sindex)
defer scursor.Close(ctx)
assertEqual(t, locale, sindex.Collation.Map()["locale"])
filename := "testdata/index.json"
_, err = NewMigratorInstance(filename)
assertEqual(t, nil, err)
err = IndexCopier()
assertEqual(t, nil, err)
tcursor, err := tgt.Indexes().List(ctx)
assertEqual(t, nil, err)
tcursor.Next(ctx)
var tindex mdb.Index
bson.Unmarshal(tcursor.Current, &tindex)
defer tcursor.Close(ctx)
assertEqual(t, locale, tindex.Collation.Map()["locale"])
}