Files
mongo/find_test.go
George Suntres 38265c15d1 Initial import
2026-03-29 11:38:57 -04:00

52 lines
956 B
Go

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)
}
}