Initial import
This commit is contained in:
51
find_test.go
Normal file
51
find_test.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package mongo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
func TestFind_Default(t *testing.T) {
|
||||
client := GetMongoClient()
|
||||
|
||||
filter := bson.M{"name": bson.M{"$regex": "OSRAM"}}
|
||||
findResult, err := client.Find(context.Background(), "mydb", "mycollection", filter, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to insertOne %#v", err)
|
||||
}
|
||||
|
||||
dataAny, hasData := findResult["data"]
|
||||
if !hasData {
|
||||
t.Fatal("no data")
|
||||
}
|
||||
|
||||
data := dataAny.(bson.A)
|
||||
|
||||
if len(data) != 1 {
|
||||
t.Fatalf("Expected to return 1 document but got %d", len(data))
|
||||
}
|
||||
|
||||
hasMoreAny, hasMoreOk := findResult["has_more"]
|
||||
if !hasMoreOk {
|
||||
t.Fatal("no has more")
|
||||
}
|
||||
|
||||
hasMore := hasMoreAny.(bool)
|
||||
|
||||
if hasMore {
|
||||
t.Fatalf("Expected to have reached the end of the results")
|
||||
}
|
||||
|
||||
totalAny, totalOk := findResult["total"]
|
||||
if !totalOk {
|
||||
t.Fatal("no total")
|
||||
}
|
||||
|
||||
total := totalAny.(int64)
|
||||
|
||||
if total != 1 {
|
||||
t.Fatalf("Expected total to be 1 but found %d", total)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user