golib/gdb/mgodb/mongo_test.go

39 lines
681 B
Go
Raw Normal View History

2023-06-15 21:22:51 +08:00
//
// mongo_test.go
// Copyright (C) 2023 tiglog <me@tiglog.com>
//
// Distributed under terms of the MIT license.
//
package mgodb_test
import (
"os"
"testing"
"go.mongodb.org/mongo-driver/bson"
2023-06-15 21:38:12 +08:00
"git.hexq.cn/tiglog/golib/gdb/mgodb"
"git.hexq.cn/tiglog/golib/gtest"
2023-06-15 21:22:51 +08:00
)
func initMM() {
url := os.Getenv("MONGO_URL")
mgodb.Init(url, "test", 8)
}
func TestConnect(t *testing.T) {
initMM()
err := mgodb.Mm.Connect()
gtest.NoError(t, err)
}
func TestListDatabases(t *testing.T) {
initMM()
cli, err := mgodb.Mm.Client()
gtest.NoError(t, err)
gtest.NotNil(t, cli)
names, err := cli.ListDatabaseNames(nil, bson.D{})
gtest.NoError(t, err)
gtest.Greater(t, 0, names)
}