INNER CODE UNIT · Go
TestCollection_e2e_New
chenmingyong0423/go-mongox · collection_e2e_test.go:62
func TestCollection_e2e_New(t *testing.T) {
assert.NotNil(t, getCollection[any](t))
}
func getCollection[T any](t *testing.T) *Collection[T] {
client, err := mongo.Connect(options.Client().ApplyURI("mongodb://localhost:27017").SetAuth(options.Credential{
Username: "test",
Password: "test",
AuthSource: "db-test",
}))
assert.NoError(t, err)
assert.NoError(t, client.Ping(context.Background(), readpref.Primary()))
collection := NewCollection[T](NewClient(client, &Config{}).NewDatabase("db-test"), "test_user")
return collection
}