-
Notifications
You must be signed in to change notification settings - Fork 891
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 318f5ef
Showing
6 changed files
with
110 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,65 @@ | ||
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) { | ||
if os.Getenv("SEARCH_INDEX_TEST") == "" { | ||
t.Skip("skipping") | ||
} | ||
|
||
const timeout = 5 * time.Minute | ||
|
||
ctx := context.Background() | ||
|
||
uri := os.Getenv("MONGODB_URI") | ||
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") | ||
|
||
for i := 0; i < 3; i++ { | ||
if !cursor.Next(ctx) { | ||
assert.Fail(t, "expected aggregate to return a document, but got none") | ||
} | ||
if cursor.Current.Lookup("name").StringValue() == searchName && cursor.Current.Lookup("queryable").Boolean() { | ||
break | ||
} | ||
time.Sleep(5 * time.Second) | ||
} | ||
} |