-
Notifications
You must be signed in to change notification settings - Fork 892
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b4cd75
commit 1b6ff9d
Showing
6 changed files
with
117 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package mongo | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"go.mongodb.org/mongo-driver/bson" | ||
"go.mongodb.org/mongo-driver/internal/assert" | ||
"go.mongodb.org/mongo-driver/internal/uuid" | ||
"go.mongodb.org/mongo-driver/mongo/options" | ||
) | ||
|
||
func TestSearchIndexProse(t *testing.T) { | ||
const timeout = 5 * time.Minute | ||
|
||
ctx := context.Background() | ||
|
||
uri := os.Getenv("TEST_INDEX_URI") | ||
if uri == "" { | ||
t.Skip("skipping") | ||
} | ||
clientOptions := options.Client().ApplyURI(uri).SetTimeout(timeout) | ||
|
||
// Create a MongoClient that points to MONGODB_URI and listens to the | ||
// ComandMonitor, ServerMonitor, and PoolMonitor events. | ||
client, err := Connect(ctx, clientOptions) | ||
assert.NoError(t, err, "failed to connect %s", uri) | ||
defer client.Disconnect(ctx) | ||
|
||
id, err := uuid.New() | ||
assert.NoError(t, err) | ||
collName := fmt.Sprintf("col%s", id.String()) | ||
collection := client.Database("test").Collection(collName) | ||
defer collection.Drop(ctx) | ||
|
||
_, err = collection.InsertOne(ctx, bson.D{}) | ||
assert.NoError(t, err, "failed to insert") | ||
|
||
view := collection.SearchIndexes() | ||
|
||
definition := bson.D{{"mappings", bson.D{{"dynamic", false}}}} | ||
searchName := "test-search-index" | ||
index, err := view.CreateOne(ctx, SearchIndexModel{ | ||
Definition: definition, | ||
Name: &searchName, | ||
}) | ||
assert.NoError(t, err, "failed to create index") | ||
|
||
cursor, err := view.List(ctx, &index, nil) | ||
assert.NoError(t, err, "failed to list") | ||
|
||
if !cursor.Next(ctx) { | ||
assert.Fail(t, "expected aggregate to return a document, but got none") | ||
} | ||
for i := 0; i < 3; i++ { | ||
if cursor.Current.Lookup("name").StringValue() == searchName && cursor.Current.Lookup("queryable").Boolean() { | ||
break | ||
} | ||
time.Sleep(5 * time.Second) | ||
} | ||
} |