|
| 1 | +// Copyright (C) MongoDB, Inc. 2025-present. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | +// not use this file except in compliance with the License. You may obtain |
| 5 | +// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | + |
| 7 | +package options |
| 8 | + |
| 9 | +import ( |
| 10 | + "testing" |
| 11 | + |
| 12 | + "go.mongodb.org/mongo-driver/v2/internal/require" |
| 13 | + "go.mongodb.org/mongo-driver/v2/x/mongo/driver" |
| 14 | + "go.mongodb.org/mongo-driver/v2/x/mongo/driver/drivertest" |
| 15 | +) |
| 16 | + |
| 17 | +func TestSetClientOptions(t *testing.T) { |
| 18 | + t.Parallel() |
| 19 | + |
| 20 | + t.Run("set Crypt with driver.Crypt", func(t *testing.T) { |
| 21 | + t.Parallel() |
| 22 | + |
| 23 | + opts := &ClientOptions{} |
| 24 | + c := driver.NewCrypt(&driver.CryptOptions{}) |
| 25 | + opts, err := SetInternalClientOptions(opts, map[string]any{ |
| 26 | + "crypt": c, |
| 27 | + }) |
| 28 | + require.NoError(t, err) |
| 29 | + require.Equal(t, c, opts.Crypt) |
| 30 | + }) |
| 31 | + |
| 32 | + t.Run("set Crypt with driver.Deployment", func(t *testing.T) { |
| 33 | + t.Parallel() |
| 34 | + |
| 35 | + opts := &ClientOptions{} |
| 36 | + _, err := SetInternalClientOptions(opts, map[string]any{ |
| 37 | + "crypt": &drivertest.MockDeployment{}, |
| 38 | + }) |
| 39 | + require.EqualError(t, err, "unexpected type for crypt") |
| 40 | + }) |
| 41 | + |
| 42 | + t.Run("set Deployment with driver.Deployment", func(t *testing.T) { |
| 43 | + t.Parallel() |
| 44 | + |
| 45 | + opts := &ClientOptions{} |
| 46 | + d := &drivertest.MockDeployment{} |
| 47 | + opts, err := SetInternalClientOptions(opts, map[string]any{ |
| 48 | + "deployment": d, |
| 49 | + }) |
| 50 | + require.NoError(t, err) |
| 51 | + require.Equal(t, d, opts.Deployment) |
| 52 | + }) |
| 53 | + |
| 54 | + t.Run("set Deployment with driver.Crypt", func(t *testing.T) { |
| 55 | + t.Parallel() |
| 56 | + |
| 57 | + opts := &ClientOptions{} |
| 58 | + _, err := SetInternalClientOptions(opts, map[string]any{ |
| 59 | + "deployment": driver.NewCrypt(&driver.CryptOptions{}), |
| 60 | + }) |
| 61 | + require.EqualError(t, err, "unexpected type for deployment") |
| 62 | + }) |
| 63 | + |
| 64 | + t.Run("set unsupported option", func(t *testing.T) { |
| 65 | + t.Parallel() |
| 66 | + |
| 67 | + opts := &ClientOptions{} |
| 68 | + _, err := SetInternalClientOptions(opts, map[string]any{ |
| 69 | + "unsupported": "unsupported", |
| 70 | + }) |
| 71 | + require.EqualError(t, err, "unsupported option: unsupported") |
| 72 | + }) |
| 73 | +} |
0 commit comments