{"id":20645494,"url":"https://github.com/pedrohenriques/go-dbfixtures-mongodb-driver","last_synced_at":"2026-04-17T16:04:55.808Z","repository":{"id":187655842,"uuid":"635080064","full_name":"PedroHenriques/go-dbfixtures-mongodb-driver","owner":"PedroHenriques","description":"A MongoDB driver for the Golang go-dbfixtures package.","archived":false,"fork":false,"pushed_at":"2023-08-11T09:44:22.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-17T12:31:40.129Z","etag":null,"topics":["fixtures","golang","mongodb","testing","testing-tools"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PedroHenriques.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-05-01T23:27:34.000Z","updated_at":"2023-08-11T09:25:42.000Z","dependencies_parsed_at":"2023-08-11T16:28:11.020Z","dependency_job_id":null,"html_url":"https://github.com/PedroHenriques/go-dbfixtures-mongodb-driver","commit_stats":null,"previous_names":["pedrohenriques/go-dbfixtures-mongodb-driver"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/PedroHenriques/go-dbfixtures-mongodb-driver","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PedroHenriques%2Fgo-dbfixtures-mongodb-driver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PedroHenriques%2Fgo-dbfixtures-mongodb-driver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PedroHenriques%2Fgo-dbfixtures-mongodb-driver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PedroHenriques%2Fgo-dbfixtures-mongodb-driver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PedroHenriques","download_url":"https://codeload.github.com/PedroHenriques/go-dbfixtures-mongodb-driver/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PedroHenriques%2Fgo-dbfixtures-mongodb-driver/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31935719,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T12:37:54.787Z","status":"ssl_error","status_checked_at":"2026-04-17T12:37:25.095Z","response_time":62,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fixtures","golang","mongodb","testing","testing-tools"],"created_at":"2024-11-16T16:20:04.275Z","updated_at":"2026-04-17T16:04:55.783Z","avatar_url":"https://github.com/PedroHenriques.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Coverage Status](https://coveralls.io/repos/github/PedroHenriques/go-dbfixtures-mongodb-driver/badge.svg?branch=main)](https://coveralls.io/github/PedroHenriques/go-dbfixtures-mongodb-driver?branch=main)\n![ci workflow](https://github.com/PedroHenriques/go-dbfixtures-mongodb-driver/actions/workflows/ci.yml/badge.svg?branch=main)\n![cd workflow](https://github.com/PedroHenriques/go-dbfixtures-mongodb-driver/actions/workflows/cd.yml/badge.svg)\n\n# Fixtures Manager MongoDB Driver\n\nAn abstraction layer for the [mongodb package](https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo) to facilitate handling database fixtures for testing purposes, in a MongoDB database.  \nThis package is ment to be used in conjunction with the [dbfixtures package](https://pkg.go.dev/github.com/PedroHenriques/go-dbfixtures/dbfixtures), but can also be used by itself.\n\n## Installation\n\n```sh\ngo get github.com/PedroHenriques/go-dbfixtures-mongodb-driver\n```\n\n## Usage\n\nThis package exposes the `func New(mongoClient *mongo.Client, dbName string, dbOpts *options.DatabaseOptions) dbfixtures.IDriver` function that returns an instance of the driver.  \n\n**Note:** For detailed information about the `options.DatabaseOptions` argument, please consult the [MongoDB Golang driver's documentation]https://pkg.go.dev/go.mongodb.org/mongo-driver@v1.12.1/mongo/options#DatabaseOptions).\n\nAn instance of the driver exposes the following interface\n\n```go\ntype IDriver interface {\n\t// clears the specified \"tables\" of any content\n\tTruncate(tableNames []string) error\n\n\t// inserts the supplied \"rows\" into the specified \"table\"\n\tInsertFixtures(tableName string, fixtures []interface{}) error\n\n\t// cleanup and terminate the connection to the database\n\tClose() error\n}\n```\n\n### Example\n\n```go\npackage driver_test\n\nimport (\n\t\"context\"\n\n\t\"github.com/PedroHenriques/go-dbfixtures-mongodb-driver/driver\"\n\t\"github.com/stretchr/testify/require\"\n\t\"github.com/stretchr/testify/suite\"\n\t\"go.mongodb.org/mongo-driver/bson\"\n\t\"go.mongodb.org/mongo-driver/mongo\"\n\t\"go.mongodb.org/mongo-driver/mongo/options\"\n)\n\ntype driverE2eTestSuite struct {\n\tsuite.Suite\n\n\tmongoCliente *mongo.Client\n\tmongoDbName  string\n}\n\nfunc (suite *driverE2eTestSuite) SetupSuite() {\n\tConnUrl := \"mongodb://testmongo:27017\"\n\topts := options.Client().ApplyURI(ConnUrl)\n\n\tclient, err := mongo.Connect(context.TODO(), opts)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tsuite.mongoCliente = client\n\n\tsuite.mongoDbName = \"testCol\"\n}\n\nfunc (suite *driverE2eTestSuite) TearDownSuite() {\n\tsuite.mongoCliente.Disconnect(context.TODO())\n}\n\nfunc (suite *driverE2eTestSuite) TestItShouldWork() {\n\tdatabase := suite.mongoCliente.Database(suite.mongoDbName)\n\tcol1 := database.Collection(\"col1\")\n\n\tinsRes1, _ := col1.InsertMany(\n\t\tcontext.TODO(),\n\t\t[]interface{}{\n\t\t\ttestDocument{Name: \"doc 11\", Age: 3},\n\t\t\ttestDocument{Name: \"doc 12\", Age: 33},\n\t\t},\n\t)\n\n\trequire.Equal(suite.T(), 2, len(insRes1.InsertedIDs))\n\n\texpectedDocuments := \u0026[]interface{}{\n\t\ttestDocument{Name: \"doc 26\", Age: 86},\n\t}\n\n\tdriver := driver.New(\n\t\tsuite.mongoCliente, suite.mongoDbName, \u0026options.DatabaseOptions{},\n\t)\n\n\terr := driver.InsertFixtures(\"col1\", *expectedDocuments)\n\n\trequire.Nil(suite.T(), err)\n\n\tcolDocs, _ := col1.Find(context.TODO(), bson.D{})\n\tactualDocuments := \u0026[]testDocument{}\n\tcolDocs.All(context.TODO(), actualDocuments)\n\n\trequire.EqualValues(suite.T(), len(*expectedDocuments), len(*actualDocuments))\n\tfor i, actualDocument := range *actualDocuments {\n\t\trequire.EqualExportedValues(suite.T(), (*expectedDocuments)[i], actualDocument)\n\t}\n}\n```\n\n## Testing This Package\n\n* `cd` into the package's root directory\n* run `sh cli/test.sh -b -gv 1.20`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpedrohenriques%2Fgo-dbfixtures-mongodb-driver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpedrohenriques%2Fgo-dbfixtures-mongodb-driver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpedrohenriques%2Fgo-dbfixtures-mongodb-driver/lists"}