...
1
2
3
4
5
6
7 package mtest
8
9 import (
10 "context"
11 "fmt"
12
13 "go.mongodb.org/mongo-driver/bson"
14 "go.mongodb.org/mongo-driver/mongo"
15 "go.mongodb.org/mongo-driver/x/mongo/driver/connstring"
16 "go.mongodb.org/mongo-driver/x/mongo/driver/topology"
17 )
18
19
20 func AuthEnabled() bool {
21 return testContext.authEnabled
22 }
23
24
25 func SSLEnabled() bool {
26 return testContext.sslEnabled
27 }
28
29
30 func ClusterTopologyKind() TopologyKind {
31 return testContext.topoKind
32 }
33
34
35 func ClusterURI() string {
36 return testContext.connString.Original
37 }
38
39
40 func Serverless() bool {
41 return testContext.serverless
42 }
43
44
45
46 func SingleMongosLoadBalancerURI() string {
47 return testContext.singleMongosLoadBalancerURI
48 }
49
50
51
52 func MultiMongosLoadBalancerURI() string {
53 return testContext.multiMongosLoadBalancerURI
54 }
55
56
57 func ClusterConnString() *connstring.ConnString {
58 return testContext.connString
59 }
60
61
62
63 func GlobalClient() *mongo.Client {
64 return testContext.client
65 }
66
67
68 func GlobalTopology() *topology.Topology {
69 return testContext.topo
70 }
71
72
73
74 func ServerVersion() string {
75 return testContext.serverVersion
76 }
77
78
79 func SetFailPoint(fp FailPoint, client *mongo.Client) error {
80 admin := client.Database("admin")
81 if err := admin.RunCommand(context.Background(), fp).Err(); err != nil {
82 return fmt.Errorf("error creating fail point: %w", err)
83 }
84 return nil
85 }
86
87
88
89 func SetRawFailPoint(fp bson.Raw, client *mongo.Client) error {
90 admin := client.Database("admin")
91 if err := admin.RunCommand(context.Background(), fp).Err(); err != nil {
92 return fmt.Errorf("error creating fail point: %w", err)
93 }
94 return nil
95 }
96
View as plain text