|
7 | 7 | package integration |
8 | 8 |
|
9 | 9 | import ( |
| 10 | + "context" |
10 | 11 | "testing" |
11 | 12 |
|
12 | 13 | "go.mongodb.org/mongo-driver/v2/bson" |
13 | 14 | "go.mongodb.org/mongo-driver/v2/internal/assert" |
14 | 15 | "go.mongodb.org/mongo-driver/v2/internal/require" |
| 16 | + "go.mongodb.org/mongo-driver/v2/mongo" |
| 17 | + "go.mongodb.org/mongo-driver/v2/mongo/options" |
15 | 18 | ) |
16 | 19 |
|
17 | 20 | func TestOPMSGMockDeployment(t *testing.T) { |
18 | | - var md *MockDeployment |
| 21 | + md := NewMockDeployment() |
19 | 22 |
|
20 | | - t.Run("NewMockDeployment", func(t *testing.T) { |
21 | | - md = NewMockDeployment() |
22 | | - require.NotNil(t, md, "unexpected error from NewMockDeployment") |
| 23 | + opts := options.Client() |
| 24 | + opts.Opts = append(opts.Opts, func(co *options.ClientOptions) error { |
| 25 | + co.Deployment = md |
| 26 | + |
| 27 | + return nil |
| 28 | + }) |
| 29 | + client, err := mongo.Connect(opts) |
| 30 | + |
| 31 | + t.Run("NewMockDeployment connect to client", func(t *testing.T) { |
| 32 | + require.NoError(t, err, "unexpected error from connect to mockdeployment") |
23 | 33 | }) |
24 | 34 | t.Run("AddResponses with one", func(t *testing.T) { |
25 | 35 | res := bson.D{{"ok", 1}} |
26 | 36 | md.AddResponses(res) |
27 | 37 | assert.NotNil(t, md.conn.responses, "expected non-nil responses") |
28 | 38 | assert.Len(t, md.conn.responses, 1, "expected 1 response, got %v", len(md.conn.responses)) |
| 39 | + err = client.Ping(context.Background(), nil) |
| 40 | + require.NoError(t, err) |
29 | 41 | }) |
30 | 42 | t.Run("AddResponses with multiple", func(t *testing.T) { |
31 | 43 | res1 := bson.D{{"ok", 1}} |
32 | 44 | res2 := bson.D{{"ok", 2}} |
33 | 45 | res3 := bson.D{{"ok", 3}} |
34 | 46 | md.AddResponses(res1, res2, res3) |
35 | 47 | assert.NotNil(t, md.conn.responses, "expected non-nil responses") |
36 | | - assert.Len(t, md.conn.responses, 4, "expected 4 responses, got %v", len(md.conn.responses)) |
| 48 | + assert.Len(t, md.conn.responses, 3, "expected 3 responses, got %v", len(md.conn.responses)) |
| 49 | + err = client.Ping(context.Background(), nil) |
| 50 | + require.NoError(t, err) |
37 | 51 | }) |
38 | 52 | t.Run("ClearResponses", func(t *testing.T) { |
39 | 53 | md.ClearResponses() |
40 | 54 | assert.NotNil(t, md.conn.responses, "expected non-nil responses") |
41 | 55 | assert.Len(t, md.conn.responses, 0, "expected 0 responses, got %v", len(md.conn.responses)) |
| 56 | + err = client.Ping(context.Background(), nil) |
| 57 | + require.Error(t, err, "expected Ping error, got nil") |
42 | 58 | }) |
43 | 59 | } |
0 commit comments