Skip to content

Commit d67a451

Browse files
committed
Fix search index failure on empty "Options"
1 parent 9da64b8 commit d67a451

File tree

5 files changed

+76
-10
lines changed

5 files changed

+76
-10
lines changed

.evergreen/config.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ timeout:
2626
args: [ls, -la]
2727

2828
functions:
29-
assume-test-secrets-ec2-role:
30-
- command: ec2.assume_role
31-
params:
32-
role_arn: ${aws_test_secrets_role}
33-
3429
setup-system:
3530
# Executes clone and applies the submitted patch, if any
3631
- command: git.get_project
@@ -439,7 +434,7 @@ functions:
439434
params:
440435
binary: "bash"
441436
env:
442-
TEST_SEARCH_INDEX: "${MONGODB_URI}"
437+
SEARCH_INDEX_URI: "${SEARCH_INDEX_URI}"
443438
args: [*task-runner, evg-test-search-index]
444439

445440
add-aws-auth-variables-to-file:
@@ -2063,7 +2058,7 @@ task_groups:
20632058
params:
20642059
working_dir: src/go.mongodb.org/mongo-driver
20652060
binary: bash
2066-
include_expansions_in_env: [AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN]
2061+
include_expansions_in_env: [AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN, MONGODB_URI]
20672062
env:
20682063
MONGODB_VERSION: ${VERSION}
20692064
LAMBDA_STACK_NAME: dbx-go-lambda
@@ -2072,6 +2067,15 @@ task_groups:
20722067
- command: expansions.update
20732068
params:
20742069
file: src/go.mongodb.org/mongo-driver/atlas-expansion.yml
2070+
- command: shell.exec
2071+
params:
2072+
working_dir: src/go.mongodb.org/mongo-driver
2073+
shell: bash
2074+
script: |-
2075+
echo "SEARCH_INDEX_URI: ${MONGODB_URI}" > atlas-expansion.yml
2076+
- command: expansions.update
2077+
params:
2078+
file: src/go.mongodb.org/mongo-driver/atlas-expansion.yml
20752079
teardown_group:
20762080
- command: subprocess.exec
20772081
params:

Taskfile.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ tasks:
160160

161161
evg-test-search-index:
162162
# Use the long timeout to wait for the responses from the server.
163-
- go test ./internal/integration -run TestSearchIndexProse -v -timeout {{.LONG_TEST_TIMEOUT}}s >> test.suite
163+
- go test ./internal/integration -run TestSearchIndex -v -timeout {{.LONG_TEST_TIMEOUT}}s >> test.suite
164164

165165
evg-test-ocsp:
166166
- go test -v ./mongo -run TestOCSP ${OCSP_TLS_SHOULD_SUCCEED} >> test.suite

internal/integration/search_index_prose_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestSearchIndexProse(t *testing.T) {
3131

3232
const timeout = 5 * time.Minute
3333

34-
uri := os.Getenv("TEST_INDEX_URI")
34+
uri := os.Getenv("SEARCH_INDEX_URI")
3535
if uri == "" {
3636
t.Skip("skipping")
3737
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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 integration
8+
9+
import (
10+
"context"
11+
"os"
12+
"testing"
13+
"time"
14+
15+
"go.mongodb.org/mongo-driver/v2/bson"
16+
"go.mongodb.org/mongo-driver/v2/internal/integration/mtest"
17+
"go.mongodb.org/mongo-driver/v2/internal/require"
18+
"go.mongodb.org/mongo-driver/v2/mongo"
19+
"go.mongodb.org/mongo-driver/v2/mongo/options"
20+
"go.mongodb.org/mongo-driver/v2/x/bsonx/bsoncore"
21+
)
22+
23+
func TestSearchIndex(t *testing.T) {
24+
t.Parallel()
25+
26+
const timeout = 5 * time.Minute
27+
28+
uri := os.Getenv("SEARCH_INDEX_URI")
29+
if uri == "" {
30+
t.Skip("skipping")
31+
}
32+
33+
opts := options.Client().ApplyURI(uri).SetTimeout(timeout)
34+
mt := mtest.New(t, mtest.NewOptions().ClientOptions(opts).MinServerVersion("7.0").Topologies(mtest.ReplicaSet))
35+
36+
mt.Run("search indexes with empty option", func(mt *mtest.T) {
37+
ctx := context.Background()
38+
39+
expected := bson.RawArray(bsoncore.NewArrayBuilder().AppendDocument(
40+
bsoncore.NewDocumentBuilder().
41+
AppendDocument("definition", bsoncore.NewDocumentBuilder().
42+
AppendDocument("mappings", bsoncore.NewDocumentBuilder().
43+
AppendBoolean("dynamic", true).
44+
Build()).
45+
Build()).
46+
Build()).
47+
Build())
48+
49+
_, err := mt.Coll.SearchIndexes().CreateOne(ctx, mongo.SearchIndexModel{
50+
Definition: bson.D{
51+
{"mappings", bson.D{
52+
{"dynamic", true},
53+
}},
54+
},
55+
})
56+
require.NoError(mt, err, "failed to create index")
57+
evt := mt.GetStartedEvent()
58+
actual, ok := evt.Command.Lookup("indexes").ArrayOK()
59+
require.True(mt, ok, "expected command %v to contain an indexes array", evt.Command)
60+
require.Equal(mt, expected, actual, "expected indexes array %v, got %v", expected, actual)
61+
})
62+
}

mongo/search_index_view.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ func (siv SearchIndexView) CreateMany(
123123
}
124124

125125
var iidx int32
126+
iidx, indexes = bsoncore.AppendDocumentElementStart(indexes, strconv.Itoa(i))
126127
if model.Options != nil {
127128
searchIndexArgs, err := mongoutil.NewOptions[options.SearchIndexesOptions](model.Options)
128129
if err != nil {
129130
return nil, fmt.Errorf("failed to construct options from builder: %w", err)
130131
}
131132

132-
iidx, indexes = bsoncore.AppendDocumentElementStart(indexes, strconv.Itoa(i))
133133
if searchIndexArgs.Name != nil {
134134
indexes = bsoncore.AppendStringElement(indexes, "name", *searchIndexArgs.Name)
135135
}

0 commit comments

Comments
 (0)