Skip to content

Commit 86957b1

Browse files
committed
Fix search index failure on empty "Options"
1 parent 4018aa3 commit 86957b1

File tree

5 files changed

+68
-10
lines changed

5 files changed

+68
-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: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
)
21+
22+
func TestSearchIndex(t *testing.T) {
23+
t.Parallel()
24+
25+
const timeout = 5 * time.Minute
26+
27+
uri := os.Getenv("SEARCH_INDEX_URI")
28+
if uri == "" {
29+
t.Skip("skipping")
30+
}
31+
32+
opts := options.Client().ApplyURI(uri).SetTimeout(timeout)
33+
mt := mtest.New(t, mtest.NewOptions().ClientOptions(opts).MinServerVersion("7.0").Topologies(mtest.ReplicaSet))
34+
35+
mt.Run("search indexes with empty option", func(mt *mtest.T) {
36+
ctx := context.Background()
37+
38+
_, err := mt.Coll.InsertMany(ctx, []any{
39+
bson.M{
40+
"string_field": "test1 test1",
41+
},
42+
})
43+
require.NoError(mt, err, "failed to insert")
44+
45+
_, err = mt.Coll.SearchIndexes().CreateOne(ctx, mongo.SearchIndexModel{
46+
Definition: bson.D{
47+
{"mappings", bson.D{
48+
{"dynamic", true},
49+
}},
50+
},
51+
})
52+
require.NoError(mt, err, "failed to create index")
53+
})
54+
}

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)