Files
crawlab/core/mongo/db.go
Marvin Zhang f5d9ccfbfc feat: initialize configuration and enhance IPC handling in task runner tests
- Added configuration initialization in db.go to ensure proper setup of application settings.
- Refactored runner_test.go to streamline IPC message handling by introducing a setupPipe function and an initRunner function for better readability and maintainability.
- Improved synchronization in tests by using channels for signaling readiness and processing, enhancing the reliability of IPC message handling.
- Updated test cases to validate IPC message processing and error handling, ensuring robustness in the task runner's functionality.
2025-01-06 14:41:38 +08:00

29 lines
520 B
Go

package mongo
import (
"github.com/crawlab-team/crawlab/core/config"
"github.com/spf13/viper"
"go.mongodb.org/mongo-driver/mongo"
)
func init() {
config.InitConfig()
}
func GetMongoDb(dbName string) *mongo.Database {
// Use default database name if not provided
if dbName == "" {
if dbName = viper.GetString("mongo.db"); dbName == "" {
dbName = "test"
}
}
c, err := GetMongoClient()
if err != nil {
logger.Errorf("error getting mongo client: %v", err)
return nil
}
return c.Database(dbName)
}