{"id":19865901,"url":"https://github.com/expectto/be","last_synced_at":"2025-05-02T05:32:06.155Z","repository":{"id":203850968,"uuid":"710533480","full_name":"expectto/be","owner":"expectto","description":"Wide collection of Golang assertions: Gomega and Gomock compatible matchers","archived":false,"fork":false,"pushed_at":"2025-05-01T16:21:05.000Z","size":254,"stargazers_count":20,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-01T17:24:17.352Z","etag":null,"topics":["bdd","ginkgo","golang","gomega","gomock","gomock-matchers","matchers","testing","testing-library"],"latest_commit_sha":null,"homepage":"https://expectto.github.io/be/","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/expectto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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,"zenodo":null}},"created_at":"2023-10-26T22:33:31.000Z","updated_at":"2025-05-01T16:21:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"e7eb21ba-1799-4a2e-a913-2241e5a5e201","html_url":"https://github.com/expectto/be","commit_stats":null,"previous_names":["expectto/be"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expectto%2Fbe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expectto%2Fbe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expectto%2Fbe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/expectto%2Fbe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/expectto","download_url":"https://codeload.github.com/expectto/be/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251992993,"owners_count":21677022,"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","ginkgo","golang","gomega","gomock","gomock-matchers","matchers","testing","testing-library"],"created_at":"2024-11-12T15:24:28.896Z","updated_at":"2025-05-02T05:32:04.837Z","avatar_url":"https://github.com/expectto.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"## Expect(👨🏼‍💻).To(Be(🚀))\n\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/expectto/be/blob/main/LICENSE)\n[![Go Reference](https://pkg.go.dev/badge/github.com/expectto/be.svg)](https://expectto.github.io/be/)\n\n\n`expectto/be` is a Golang package that offers a substantial collection of `Be` matchers. Every `Be` matcher is\ncompatible with both [Ginkgo](https://github.com/onsi/ginkgo)/[Gomega](https://github.com/onsi/gomega)\nand [Gomock](https://github.com/uber-go/mock). Where possible, arguments of matchers can be either finite values or\nmatchers (Be/Gomega/Gomock).\u003cbr\u003e\nEmploying `expectto/be` matchers enables you to create straightforward, readable, and maintainable unit or\nintegration tests in Golang. Tasks such as testing HTTP requests, validating JSON responses, and more become remarkably\ncomprehensive and straightforward.\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Example](#example)\n- [Matchers](#matchers)\n    - [Be (core)](#core-be)\n    - [Be Reflected](#be_reflected)\n    - [Be Math](#be_math)\n    - [Be String](#be_string)\n    - [Be Time](#be_time)\n    - [Be JWT](#be_jwt)\n    - [Be URL](#be_url)\n    - [Be JSON](#be_json)\n    - [Be HTTP](#be_http)\n\n- [Contributing](#contributing)\n- [License](#license)\n\n## Installation\n\nTo use `Be` in your Golang project, simply import it:\n\n```go\nimport \"github.com/expectto/be\"\n```\n\n## Example\n\nConsider the following example demonstrating the usage of `expectto/be`'s HTTP request matchers:\n\n```go\nreq, err := buildRequestForServiceFoo()\nExpect(err).To(Succeed())\n\n// Matching an HTTP request\nExpect(req).To(be_http.Request(\n    // Matching the URL\n    be_http.HavingURL(be_url.URL(\n        be_url.WithHttps(),\n        be_url.HavingHost(\"example.com\"),\n        be_url.HavingPath(\"/path\"),\n        be_url.HavingSearchParam(\"status\", \"active\"),\n        be_url.HavingSearchParam(\"v\", be_reflected.AsNumericString()),\n        be_url.HavingSearchParam(\"q\", \"Hello World\"),\n    )),\n\n    // Matching the HTTP method\n    be_http.POST()\n\n    // Matching request's context\n    be_http.HavingCtx(be_ctx.Ctx(\n        be_ctx.WithDeadline(be_time.LaterThan(time.Now().Add(30*time.Minute))),\n        be_ctx.WithValue(\"foobar\", 100),\n    )),\n\n    // Matching the request body using JSON matchers\n    be_http.HavingBody(\n        be.JSON(\n            be_json.JsonAsReader,\n            be_json.HaveKeyValue(\"hello\", \"world\"),\n            be_json.HaveKeyValue(\"n\", be_reflected.AsInteger(), be_math.GreaterThan(10)),\n            be_json.HaveKeyValue(\"ids\", be_reflected.AsSliceOf[string]),\n            Not(be_json.HaveKeyValue(\"deleted_field\")), // not to have a deleted field\n            \n            be_json.HaveKeyValue(\"email\", be_string.ValidEmail(), be_string.HaveSuffix(\"@tests.com\")),\n\n            // \"details\":[{\"key\":\"foo\"},{\"key\":\"bar\"}]\n            be_json.HaveKeyValue(\"details\", And(\n                be_reflected.AsObjects(),\n                be.HaveLength(be_math.GreaterThan(2)),\n                ContainElements(\n                    be_json.HaveKeyValue(\"key\", \"foo\"),\n                    be_json.HaveKeyValue(\"key\", \"bar\"),\n                ),\n            )),\n        ),\n    ),\n\n\t// Matching HTTP headers \n    be_http.HavingHeader(\"X-Custom\", \"Hey-There\"), \n    be_http.HavingHeader(\"Authorization\", \n        be_string.MatchTemplate(\"Bearer {{jwt}}\", \n        be_string.Var(\"jwt\", \n            be_jwt.Token(\n                be_jwt.Valid(), \n                be_jwt.HavingClaim(\"name\", \"John Doe\"), \n            ), \n        ), \n    ),\n))      \n```\n\n## Matchers\n\n### Core Be\n\n📦 `be` provides a set of core matchers for common testing scenarios.\u003cbr\u003e[See detailed docs](core-be-matchers.md)\n\n#### Core matchers:\n\n`Always`, `Never`, `All`, `Any`, `Eq`, `Not`, `HaveLength`, `Dive`, `DiveAny`, `DiveFirst`\n\n### be_reflected\n\n📦 `be_reflected` provides Be matchers that use reflection, enabling expressive assertions on values' reflect kinds and\ntypes.\u003cbr\u003e[See detailed docs](be_reflected/README.md)\n\n#### General Matchers based on reflect.Kind:\n\n`AsKind`, `AsFunc`, `AsChan`, `AsPointer`, `AsFinalPointer`, `AsStruct`, `AsPointerToStruct`, `AsSlice`, `AsPointerToSlice`, `AsSliceOf`, `AsMap`, `AsPointerToMap`, `AsObject`, `AsObjects`, `AsPointerToObject`\n\n#### Data Type Matchers based on reflect.Kind\n\n`AsString`, `AsBytes`, `AsNumeric`, `AsNumericString`, `AsInteger`, `AsIntegerString`, `AsFloat`, `AsFloatishString`,\n\n#### Interface Matchers based on reflect.Kind\n\n`AsReader`,`AsStringer`\n\n#### Matchers based on types compatibility:\n\n`AssignableTo`, `Implementing`\n\n### be_math\n\n📦 `be_math` provides Be matchers for mathematical operations.\u003cbr\u003e[See detailed docs](be_math/README.md)\n\n#### Matchers on math:\n\n`GreaterThan`, `GreaterThanEqual`, `LessThan`, `LessThanEqual`, `Approx`, `InRange`, `Odd`, `Even`, `Negative`, `Positive`, `Zero`, `Integral`, `DivisibleBy`\n\n#### Shortcut aliases for math matchers:\n\n`Gt`, `Gte`, `Lt`, `Lte`\n\n### be_string\n\n📦 `be_string` provides Be matchers for string-related assertions.\u003cbr\u003e[See detailed docs](be_string/README.md)\n\n#### Matchers on strings\n\n`NonEmptyString`, `EmptyString`, `Alpha`, `Numeric`, `AlphaNumeric`, `AlphaNumericWithDots`, `Float`, `Titled`, `LowerCaseOnly`, `MatchWildcard`, `ValidEmail`\n\n#### Template matchers\n\n`MatchTemplate`\n\n### be_time\n\n📦 `be_time` provides Be matchers on time.Time.\u003cbr\u003e[See detailed docs](be_time/README.md)\n\n#### Time Matchers\n\n`LaterThan`, `LaterThanEqual`, `EarlierThan`, `EarlierThanEqual`, `Eq`, `Approx`, \u003cbr\u003e\n`SameExactMilli`, `SameExactSecond`, `SameExactMinute`, `SameExactHour`,  \u003cbr\u003e\n`SameExactDay`, `SameExactWeekday`, `SameExactWeek`, `SameExactMonth`, \u003cbr\u003e\n`SameSecond`, `SameMinute`, `SameHour`, `SameDay`, `SameYearDay`, \u003cbr\u003e\n`SameWeek`, `SameMonth`, `SameYear`, `SameTimzone`, `SameOffset`, `IsDST`\n\n### be_jwt\n\n📦 `be_jwt` provides Be matchers for handling JSON Web Tokens (JWT). It includes matchers for transforming and validating\nJWT tokens. Matchers corresponds to specific\ngolang [jwt implementation](https://github.com/golang-jwt/jwt/v5).\u003cbr\u003e [See detailed docs](be_jwt/README.md)\n\n#### Transformers for JWT matching:\n\n`TransformSignedJwtFromString`, `TransformJwtFromString`\n\n#### Matchers on JWT:\n\n`Token`, `Valid`, `HavingClaims`, `HavingClaim`, `HavingMethodAlg`, `SignedVia`\n\n### be_url\n\n📦 `be_url` provides Be matchers on url.URL.\u003cbr\u003e [See detailed docs](be_jwt/README.md)\n\n#### Transformers for URL Matchers:\n\n`TransformUrlFromString`, `TransformSchemelessUrlFromString`\n\n#### URL Matchers:\n\n`URL`, `HavingHost`, `HavingHostname`, `HavingScheme`, `NotHavingScheme`, `WithHttps`, `WithHttp`, `HavingPort`, `NotHavingPort`, `HavingPath`, `HavingRawQuery`, `HavingSearchParam`, `HavingMultipleSearchParam`, `HavingUsername`, `HavingUserinfo`, `HavingPassword`\n\n### be_ctx\n\n📦 `be_ctx` provides Be matchers on context.Context.\u003cbr\u003e [See detailed docs](be_ctx/README.md)\n\n#### Context Matchers:\n\n`Ctx`, `CtxWithValue`, `CtxWithDeadline`, `CtxWithError`\n\n### be_json\n\n📦 `be_json` provides Be matchers for expressive assertions on JSON.\u003cbr\u003e [See detailed docs](be_json/README.md)\n\n#### JSON Matchers:\n\n`Matcher`, `HaveKeyValue`\n\n### be_http\n\n📦 `be_http` provides Be matchers for expressive assertions on http.Request.\u003cbr\u003e [See detailed docs](be_http/README.md)\n\n#### Matchers on HTTP:\n\n`Request`, `HavingMethod`, \u003cbr\u003e\n`GET`, `HEAD`, `POST`, `PUT`, `PATCH`, `DELETE`, `OPTIONS`, `CONNECT`, `TRACE`, \u003cbr\u003e\n`HavingURL`, `HavingBody`, `HavingHost`, `HavingProto`, `HavingHeader`, `HavingHeaders`\n\n# Contributing\n\n`Be` welcomes contributions! Feel free to open issues, suggest improvements, or submit pull\nrequests. [Contribution guidelines for this project](CONTRIBUTING.md)\n\n# License\n\nThis project is [licensed under the MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpectto%2Fbe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexpectto%2Fbe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpectto%2Fbe/lists"}