{"id":18881146,"url":"https://github.com/godogx/mongosteps","last_synced_at":"2026-02-21T00:30:16.413Z","repository":{"id":38187136,"uuid":"479117984","full_name":"godogx/mongosteps","owner":"godogx","description":"Cucumber gRPC steps for Golang","archived":false,"fork":false,"pushed_at":"2024-04-12T22:41:22.000Z","size":464,"stargazers_count":3,"open_issues_count":5,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-12-31T03:26:59.755Z","etag":null,"topics":["bdd","cucumber","functional-testing","gherkin","go","godog","godog-extension","golang","integration-testing","testing"],"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/godogx.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-07T19:14:45.000Z","updated_at":"2024-12-20T06:41:04.000Z","dependencies_parsed_at":"2024-11-08T06:48:15.920Z","dependency_job_id":"a690a15b-6fdc-408d-84cc-51767a8589c9","html_url":"https://github.com/godogx/mongosteps","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/godogx%2Fmongosteps","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/godogx%2Fmongosteps/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/godogx%2Fmongosteps/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/godogx%2Fmongosteps/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/godogx","download_url":"https://codeload.github.com/godogx/mongosteps/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239850449,"owners_count":19707348,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["bdd","cucumber","functional-testing","gherkin","go","godog","godog-extension","golang","integration-testing","testing"],"created_at":"2024-11-08T06:47:42.702Z","updated_at":"2026-02-21T00:30:16.368Z","avatar_url":"https://github.com/godogx.png","language":"Go","readme":"# Cucumber mongodb steps for Golang\n\n[![GitHub Releases](https://img.shields.io/github/v/release/godogx/mongosteps)](https://github.com/godogx/mongosteps/releases/latest)\n[![Build Status](https://github.com/godogx/mongosteps/actions/workflows/test.yaml/badge.svg)](https://github.com/godogx/mongosteps/actions/workflows/test.yaml)\n[![codecov](https://codecov.io/gh/godogx/mongosteps/branch/master/graph/badge.svg?token=eTdAgDE2vR)](https://codecov.io/gh/godogx/mongosteps)\n[![Go Report Card](https://goreportcard.com/badge/github.com/godogx/mongosteps)](https://goreportcard.com/report/github.com/godogx/mongosteps)\n[![GoDevDoc](https://img.shields.io/badge/dev-doc-00ADD8?logo=go)](https://pkg.go.dev/github.com/godogx/mongosteps)\n\n`mongosteps` provides steps for [`cucumber/godog`](https://github.com/cucumber/godog) and makes it easy to run tests with MongoDB.\n\n## Table of Contents\n\n- [Prerequisites](#prerequisites)\n- [Usage](#usage)\n    - [Setup](#setup)\n    - [Notes](#notes)\n    - [Steps](#steps)\n        - [Delete all documents / Truncate collection](#delete-all-documents--truncate-collection)\n        - [Insert documents to collection](#insert-documents-to-collection)\n        - [Assert no documents in collection](#assert-no-documents-in-collection)\n        - [Assert number of documents in collection](#assert-number-of-documents-in-collection)\n        - [Assert all documents in collection](#assert-all-documents-in-collection)\n        - [Search for documents](#search-for-documents)\n\n## Prerequisites\n\n- `Go \u003e= 1.19`\n\n[\u003csub\u003e\u003csup\u003e[table of contents]\u003c/sup\u003e\u003c/sub\u003e](#table-of-contents)\n\n## Install\n\n```bash\ngo get github.com/godogx/mongosteps\n```\n\n[\u003csub\u003e\u003csup\u003e[table of contents]\u003c/sup\u003e\u003c/sub\u003e](#table-of-contents)\n\n## Usage\n\n### Setup\n\nInitiate an `mongosteps.Manager` and register it to the scenario\n\n```go\npackage mypackage\n\nimport (\n\t\"bytes\"\n\t\"context\"\n\t\"math/rand\"\n\t\"testing\"\n\n\t\"github.com/cucumber/godog\"\n\t\"github.com/godogx/mongosteps\"\n\t\"go.mongodb.org/mongo-driver/mongo\"\n\t\"go.mongodb.org/mongo-driver/mongo/options\"\n)\n\nfunc TestIntegration(t *testing.T) {\n\tout := bytes.NewBuffer(nil)\n\n\t// Create mongodb connection.\n\tconn, err := mongo.Connect(context.Background(), options.Client().ApplyURI(\"mongodb://localhost:27017\"))\n\tif err != nil {\n\t\tt.Fatalf(\"could not connect to mongodb: %s\", err.Error())\n\t}\n\n\t// Initiate a new manager.\n\tmanager := mongosteps.NewManager(\n\t\tmongosteps.WithDefaultDatabase(conn.Database(\"mydb\"), mongosteps.CleanUpAfterScenario(\"mycollection\")),\n\t\t// If you have more than 1 database, you can use the following:\n\t\t// mongosteps.WithDatabase(\"other\", conn.Database(\"otherdb\"), mongosteps.CleanUpAfterScenario(\"othercollection\")),\n\t)\n\n\tsuite := godog.TestSuite{\n\t\tName:                 \"Integration\",\n\t\tTestSuiteInitializer: nil,\n\t\tScenarioInitializer: func(ctx *godog.ScenarioContext) {\n\t\t\t// Register the client.\n\t\t\tmanager.RegisterContext(ctx)\n\t\t},\n\t\tOptions: \u0026godog.Options{\n\t\t\tStrict:    true,\n\t\t\tOutput:    out,\n\t\t\tRandomize: rand.Int63(),\n\t\t},\n\t}\n\n\t// Run the suite.\n\tif status := suite.Run(); status != 0 {\n\t\tt.Fatal(out.String())\n\t}\n}\n```\n\n[\u003csub\u003e\u003csup\u003e[table of contents]\u003c/sup\u003e\u003c/sub\u003e](#table-of-contents)\n\n### Notes\n\n- All the JSON (for insertions and assertions) are in [MongoDB Extended JSON (v2)](https://docs.mongodb.com/manual/reference/mongodb-extended-json/) format.\n- For assertions, we do support `\u003cignore-diff\u003e` for any data types.\n\nFor example: Given these documents are stored in the collection\n\n```json5\n[\n    {\n        \"_id\": {\"$oid\": \"6250053966df8910f804c3a7\"},\n        \"name\": \"John Doe\",\n        \"age\": 30,\n        \"address\": {\n            \"street\": \"Street 1\",\n            \"city\": \"City 1\",\n            \"country\": \"Country 1\"\n        }\n    }\n]\n```\n\nThis assertion matches\n\n```json5\n[\n    {\n        \"_id\": \"\u003cignore-diff\u003e\",\n        \"name\": \"John Doe\",\n        \"age\": 30,\n        \"address\": \"\u003cignore-diff\u003e\"\n    }\n]\n```\n\n[\u003csub\u003e\u003csup\u003e[table of contents]\u003c/sup\u003e\u003c/sub\u003e](#table-of-contents)\n\n### Steps\n\n#### Delete all documents / Truncate collection\n\n- `no (?:docs|documents) in collection \"([^\"]*)\"$`\n- `no (?:docs|documents) in collection \"([^\"]*)\" of database \"([^\"]*)\"$`\n\nFor example:\n\n```gherkin\nGiven no documents in collection \"customer\"\n```\n\n```gherkin\nGiven no documents in collection \"customer\" of database \"other\"\n```\n\n[\u003csub\u003e\u003csup\u003e[table of contents]\u003c/sup\u003e\u003c/sub\u003e](#table-of-contents)\n\n#### Insert documents to collection\n\n- `these (?:docs|documents) are(?: stored)? in collection \"([^\"]*)\"[:]?$`\n- `(?:docs|documents) from(?: file)? \"([^\"]*)\" are(?: stored)? in collection \"([^\"]*)\"$`\n- `these (?:docs|documents) are(?: stored)? in collection \"([^\"]*)\" of database \"([^\"]*)\"[:]?$`\n- `(?:docs|documents) from(?: file)? \"([^\"]*)\" are(?: stored)? in collection \"([^\"]*)\" of database \"([^\"]*)\"[:]?$`\n\nFor example:\n\n```gherkin\nGiven these documents are stored in collection \"customer\":\n\"\"\"\n[\n    {\n        \"_id\": {\"$oid\": \"6250053966df8910f804c3a7\"},\n        \"name\": \"John Doe\",\n        \"age\": 30,\n        \"address\": {\n            \"street\": \"Street 1\",\n            \"city\": \"City 1\",\n            \"country\": \"Country 1\"\n        }\n    }\n]\n\"\"\"\n```\n\n```gherkin\nGiven documents from file \"../../resources/fixtures/customers.json\" are stored in collection \"customer\" of database \"other\"\n```\n\n[\u003csub\u003e\u003csup\u003e[table of contents]\u003c/sup\u003e\u003c/sub\u003e](#table-of-contents)\n\n#### Assert no documents in collection\n\n- `no (?:docs|documents) are(?: available)? in collection \"([^\"]*)\"$`\n- `no (?:docs|documents) are(?: available)? in collection \"([^\"]*)\" of database \"([^\"]*)\"$`\n\nFor example:\n\n```gherkin\nThen no documents are available in collection \"customer\"\n```\n\n```gherkin\nThen no documents are available in collection \"customer\" of database \"other\"\n```\n\n[\u003csub\u003e\u003csup\u003e[table of contents]\u003c/sup\u003e\u003c/sub\u003e](#table-of-contents)\n\n#### Assert number of documents in collection\n\n- `collection \"([^\"]*)\" should have ([0-9]+) (?:doc|docs|document|documents)(?: available)?$`\n- `there (?:is|are) ([0-9]+) (?:doc|docs|document|documents)(?: available)? in collection \"([^\"]*)\" of database \"([^\"]*)\"$`\n- `collection \"([^\"]*)\" of database \"([^\"]*)\" should have ([0-9]+) (?:doc|docs|document|documents)(?: available)?$`\n- `there (?:is|are) ([0-9]+) (?:doc|docs|document|documents)(?: available)? in collection \"([^\"]*)\"$`\n\nFor example:\n\n```gherkin\nThen there are 2 documents in collection \"customer\"\n```\n\n```gherkin\nThen collection \"customer\" of database \"other\" should have 2 documents\n```\n\n[\u003csub\u003e\u003csup\u003e[table of contents]\u003c/sup\u003e\u003c/sub\u003e](#table-of-contents)\n\n#### Assert all documents in collection\n\nInline documents:\n\n- `collection \"([^\"]*)\" should have only (?:this|these) (?:doc|docs|document|documents)(?: available)?[:]?$`\n- `there (?:is|are) only (?:this|these) (?:doc|docs|document|documents)(?: available)? in collection \"([^\"]*)\"[:]?$`\n- `collection \"([^\"]*)\" of database \"([^\"]*)\" should have only (?:this|these) (?:doc|docs|document|documents)(?: available)?[:]?$`\n- `there (?:is|are) only (?:this|these) (?:doc|docs|document|documents)(?: available)? in collection \"([^\"]*)\" of database \"([^\"]*)\"[:]?$`\n\nFrom a file:\n\n- `there (?:is|are) only (?:this|these) (?:doc|docs|document|documents) from(?: file)? \"([^\"]*)\"(?: available)? in collection \"([^\"]*)\"[:]?$`\n- `there (?:is|are) only (?:this|these) (?:doc|docs|document|documents) from(?: file)? \"([^\"]*)\"(?: available)? in collection \"([^\"]*)\" of database \"([^\"]*)\"[:]?$`\n\nFor example:\n\n```gherkin\nThen collection \"customer\" should have only these documents:\n\"\"\"\n[\n    {\n        \"_id\": \"\u003cignored-diff\u003e\",\n        \"name\": \"John Doe\",\n        \"age\": 30,\n        \"address\": {\n            \"street\": \"Street 1\",\n            \"city\": \"City 1\",\n            \"country\": \"Country 1\"\n        }\n    }\n]\n\"\"\"\n```\n\n```gherkin\nThen there are only these documents from file \"../../resources/fixtures/customers.json\" in collection \"customer\" of database \"other\"\n```\n\n[\u003csub\u003e\u003csup\u003e[table of contents]\u003c/sup\u003e\u003c/sub\u003e](#table-of-contents)\n\n#### Search for documents\n\nWithout a query:\n\n- `(?:search|find) in collection \"([^\"]*)\"$`\n- `(?:search|find) in collection \"([^\"]*)\" of database \"([^\"]*)\"$`\n\nWith a query:\n\n- `(?:search|find) in collection \"([^\"]*)\" with query[:]?$`\n- `(?:search|find) in collection \"([^\"]*)\" of database \"([^\"]*)\" with query[:]?$`\n\nAssert number of documents found:\n\n- `found ([0-9]+) (?:doc|docs|document|documents) in the result$`\n- `there (?:is|are) ([0-9]+) (?:doc|docs|document|documents) in the result$`\n\nAssert documents found:\n\n- `(?:this|these) (?:doc|docs|document|documents) (?:is|are) in the result[:]?$`\n- `found (?:this|these) (?:doc|docs|document|documents) in the result[:]?$`\n\nFor example:\n\n```gherkin\nGiven documents from file \"../../resources/fixtures/customers.json\" are stored in collection \"customer\"\n\nWhen I search in collection \"customer\"\n\nThen I found 2 documents in the result\nAnd I found these documents in the result:\n\"\"\"\n[\n    {\n        \"_id\": \"\u003cignored-diff\u003e\",\n        \"name\": \"John Doe\",\n        \"age\": 30,\n        \"address\": {\n            \"street\": \"Street 1\",\n            \"city\": \"City 1\",\n            \"country\": \"Country 1\"\n        }\n    },\n    {\n        \"_id\": \"\u003cignored-diff\u003e\",\n        \"name\": \"Jane Doe\",\n        \"age\": 20,\n        \"address\": {\n            \"street\": \"Street 2\",\n            \"city\": \"City 2\",\n            \"country\": \"Country 2\"\n        }\n    }\n]\n\"\"\"\n```\n\n[\u003csub\u003e\u003csup\u003e[table of contents]\u003c/sup\u003e\u003c/sub\u003e](#table-of-contents)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgodogx%2Fmongosteps","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgodogx%2Fmongosteps","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgodogx%2Fmongosteps/lists"}