{"id":13413870,"url":"https://github.com/fluentassert/verify","last_synced_at":"2025-03-14T20:30:45.080Z","repository":{"id":39883220,"uuid":"352282806","full_name":"fluentassert/verify","owner":"fluentassert","description":" Extensible, type-safe, fluent assertion Go library.","archived":false,"fork":false,"pushed_at":"2024-09-16T17:06:18.000Z","size":703,"stargazers_count":40,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-09-16T21:02:19.894Z","etag":null,"topics":["assertions","go","golang","testing"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/fluentassert/verify","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/fluentassert.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2021-03-28T08:56:56.000Z","updated_at":"2024-09-16T17:06:19.000Z","dependencies_parsed_at":"2023-10-17T01:42:00.100Z","dependency_job_id":"6b38e283-db02-4945-85da-bd50fd64a01a","html_url":"https://github.com/fluentassert/verify","commit_stats":{"total_commits":179,"total_committers":2,"mean_commits":89.5,"dds":0.4022346368715084,"last_synced_commit":"0d4903d48aada8ff1d94d4c4adc6bda13ec34172"},"previous_names":["pellared/fluentassert"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluentassert%2Fverify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluentassert%2Fverify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluentassert%2Fverify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluentassert%2Fverify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fluentassert","download_url":"https://codeload.github.com/fluentassert/verify/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243641986,"owners_count":20323943,"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":["assertions","go","golang","testing"],"created_at":"2024-07-30T20:01:51.607Z","updated_at":"2025-03-14T20:30:45.073Z","avatar_url":"https://github.com/fluentassert.png","language":"Go","readme":"# fluentassert\n\n\u003e [!CAUTION]\n\u003e [Avoid using assertion libraries](https://go.dev/wiki/TestComments#assert-libraries).\n\u003e Instead, use [`go-cmp`](https://github.com/google/go-cmp)\n\u003e and write custom test helpers.\n\u003e Using the popular [`testify`](https://github.com/stretchr/testify)\n\u003e may be also an acceptable choice,\n\u003e especially together with [`testifylint`](https://github.com/Antonboom/testifylint)\n\u003e to avoid common mistakes.\n\u003e Use this library if you still want to.\n\u003e Consider yourself warned.\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/fluentassert/verify.svg)](https://pkg.go.dev/github.com/fluentassert/verify)\n[![Keep a Changelog](https://img.shields.io/badge/changelog-Keep%20a%20Changelog-%23E05735)](CHANGELOG.md)\n[![GitHub Release](https://img.shields.io/github/v/release/fluentassert/verify)](https://github.com/fluentassert/verify/releases)\n[![go.mod](https://img.shields.io/github/go-mod/go-version/fluentassert/verify)](go.mod)\n[![LICENSE](https://img.shields.io/github/license/fluentassert/verify)](LICENSE)\n\n[![Build Status](https://img.shields.io/github/actions/workflow/status/fluentassert/verify/build.yml?branch=main)](https://github.com/fluentassert/verify/actions?query=workflow%3Abuild+branch%3Amain)\n[![Go Report Card](https://goreportcard.com/badge/github.com/fluentassert/verify)](https://goreportcard.com/report/github.com/fluentassert/verify)\n[![Codecov](https://codecov.io/gh/fluentassert/verify/branch/main/graph/badge.svg)](https://codecov.io/gh/fluentassert/verify)\n\n## Description\n\nThe fluent API makes the assertion code easier\nto read and write ([more](https://dave.cheney.net/2019/09/24/be-wary-of-functions-which-take-several-parameters-of-the-same-type)).\n\nThe generics (type parameters) make the usage type-safe.\n\nThe library is [extensible](#extensibility) by design.\n\n### Quick start\n\n```go\npackage test\n\nimport (\n\t\"testing\"\n\n\t\"github.com/fluentassert/verify\"\n)\n\nfunc Foo() (string, error) {\n\treturn \"wrong\", nil\n}\n\nfunc TestFoo(t *testing.T) {\n\tgot, err := Foo()\n\n\tverify.NoError(err).Require(t)           // Require(f) uses t.Fatal(f), stops execution if fails\n\tverify.String(got).Equal(\"ok\").Assert(t) // Assert(f) uses t.Error(f), continues execution if fails\n}\n```\n\n```sh\n$ go test\n--- FAIL: TestFoo (0.00s)\n    basic_test.go:17:\n        the objects are not equal\n        got: \"wrong\"\n        want: \"ok\"\n```\n\n⚠ Do not forget calling\n[`Assert(t)`](https://pkg.go.dev/github.com/fluentassert/verify#FailureMessage.Assert)\nor [`Require(t)`](https://pkg.go.dev/github.com/fluentassert/verify#FailureMessage.Require)\nwhich executes the actual assertion.\n\n## Supported types\n\nOut-of-the-box the package provides fluent assertions for the following types.\nThe more specific function you use, the more assertions you get.\n\n| Go type | Assertion entry point |\n| - | - |\n| `interface{}` ([`any`](https://pkg.go.dev/builtin#any)) | [`verify.Any()`](https://pkg.go.dev/github.com/fluentassert/verify#Any) |\n| [`comparable`](https://pkg.go.dev/builtin#comparable) | [`verify.Obj()`](https://pkg.go.dev/github.com/fluentassert/verify#Obj) |\n| [`constraints.Ordered`](https://pkg.go.dev/golang.org/x/exp/constraints#Ordered) | [`verify.Ordered()`](https://pkg.go.dev/github.com/fluentassert/verify#Ordered) |\n| [`constraints.Number`](https://pkg.go.dev/golang.org/x/exp/constraints#Number) | [`verify.Number()`](https://pkg.go.dev/github.com/fluentassert/verify#Number) |\n| [`string`](https://pkg.go.dev/builtin#string) | [`verify.String()`](https://pkg.go.dev/github.com/fluentassert/verify#String) |\n| [`error`](https://go.dev/ref/spec#Errors) | [`verify.Error()`](https://pkg.go.dev/github.com/fluentassert/verify#Error) |\n| `[]T` ([slice](https://go.dev/ref/spec#Slice_types)) | [`verify.Slice()`](https://pkg.go.dev/github.com/fluentassert/verify#Slice) |\n| `map[K]V` ([map](https://go.dev/ref/spec#Map_types)) | [`verify.Map()`](https://pkg.go.dev/github.com/fluentassert/verify#Map) |\n\nBelow you can find some convenience functions.\n\n- [`verify.NoError()`](https://pkg.go.dev/github.com/fluentassert/verify#NoError)\n- [`verify.IsError()`](https://pkg.go.dev/github.com/fluentassert/verify#IsError)\n- [`verify.Nil()`](https://pkg.go.dev/github.com/fluentassert/verify#Nil)\n- [`verify.NotNil()`](https://pkg.go.dev/github.com/fluentassert/verify#NotNil)\n- [`verify.True()`](https://pkg.go.dev/github.com/fluentassert/verify#True)\n- [`verify.False()`](https://pkg.go.dev/github.com/fluentassert/verify#False)\n\n### Deep equality\n\nFor testing deep equality use\n[`DeepEqual()`](https://pkg.go.dev/github.com/fluentassert/verify#FluentAny.DeepEqual)\nor [`NotDeepEqual()`](https://pkg.go.dev/github.com/fluentassert/verify#FluentAny.NotDeepEqual).\n\n```go\npackage test\n\nimport (\n\t\"testing\"\n\n\t\"github.com/fluentassert/verify\"\n)\n\ntype A struct {\n\tStr   string\n\tBool  bool\n\tSlice []int\n}\n\nfunc TestDeepEqual(t *testing.T) {\n\tgot := A{Str: \"wrong\", Slice: []int{1, 4}}\n\n\tverify.Any(got).DeepEqual(\n\t\tA{Str: \"string\", Bool: true, Slice: []int{1, 2}},\n\t).Assert(t)\n}\n```\n\n```sh\n$ go test\n--- FAIL: TestDeepEqual (0.00s)\n    deepeq_test.go:20:\n        mismatch (-want +got):\n          test.A{\n        -       Str:  \"string\",\n        +       Str:  \"wrong\",\n        -       Bool: true,\n        +       Bool: false,\n                Slice: []int{\n                        1,\n        -               2,\n        +               4,\n                },\n          }\n```\n\n### Collection assertions\n\nThe library contains many collection assertions.\nBelow is an example of checking unordered equality.\n\n```go\npackage test\n\nimport (\n\t\"testing\"\n\n\t\"github.com/fluentassert/verify\"\n)\n\nfunc TestSlice(t *testing.T) {\n\tgot := []int { 3, 1, 2 }\n\n\tverify.Slice(got).Equivalent([]int { 2, 3, 4 }).Assert(t)\n}\n```\n\n```sh\n$ go test\n--- FAIL: TestSlice (0.00s)\n    slice_test.go:12:\n        not equivalent\n        got: [3 1 2]\n        want: [2 3 4]\n        extra got: [1]\n        extra want: [4]\n```\n\n### Periodic polling\n\nFor asynchronous testing you can use\n[`verify.Eventually()`](https://pkg.go.dev/github.com/fluentassert/verify#Eventually)\nor [`verify.EventuallyChan()`](https://pkg.go.dev/github.com/fluentassert/verify#EventuallyChan).\n\n```go\npackage test\n\nimport (\n\t\"net/http\"\n\t\"testing\"\n\t\"time\"\n\n\t\"github.com/fluentassert/verify\"\n)\n\nfunc TestPeriodic(t *testing.T) {\n\tverify.Eventually(10*time.Second, time.Second, func() verify.FailureMessage {\n\t\tclient := http.Client{Timeout: time.Second}\n\t\tresp, err := client.Get(\"http://not-existing:1234\")\n\t\tif err != nil {\n\t\t\treturn verify.NoError(err)\n\t\t}\n\t\treturn verify.Number(resp.StatusCode).Lesser(300)\n\t}).Assert(t)\n}\n```\n\n```sh\n$ go test\n--- FAIL: TestPeriodic (10.00s)\n    async_test.go:19:\n        function never passed, last failure message:\n        Get \"http://not-existing:1234\": context deadline exceeded (Client.Timeout exceeded while awaiting headers)\n```\n\n### Custom predicates\n\nFor the most basic scenarios, you can use one of the\n[`Check()`](https://pkg.go.dev/github.com/fluentassert/verify#FluentAny.Check),\n[`Should()`](https://pkg.go.dev/github.com/fluentassert/verify#FluentAny.Should),\n[`ShouldNot()`](https://pkg.go.dev/github.com/fluentassert/verify#FluentAny.ShouldNot)\nassertions.\n\n```go\npackage test\n\nimport (\n\t\"strings\"\n\t\"testing\"\n\n\t\"github.com/fluentassert/verify\"\n)\n\nfunc TestShould(t *testing.T) {\n\tgot := \"wrong\"\n\n\tchars := \"abc\"\n\tverify.Any(got).Should(func(got string) bool {\n\t\treturn strings.ContainsAny(got, chars)\n\t}).Assertf(t, \"does not contain any of: %s\", chars)\n}\n```\n\n```sh\n$ go test\n--- FAIL: TestShould (0.00s)\n    should_test.go:16: does not contain any of: abc\n        object does not meet the predicate criteria\n        got: \"wrong\"\n```\n\n### Panics\n\nFor testing panics use [`verify.Panics()`](https://pkg.go.dev/github.com/fluentassert/verify#Panics)\nand [`verify.NotPanics()`](https://pkg.go.dev/github.com/fluentassert/verify#NotPanics).\n\n### Custom assertion function\n\nYou can create a function that returns [`FailureMessage`](https://pkg.go.dev/github.com/fluentassert/verify#FailureMessage).\nUse [`verify.And()`](https://pkg.go.dev/github.com/fluentassert/verify#And)\nand [`verify.Or()`](https://pkg.go.dev/github.com/fluentassert/verify#Or)\nfunctions together with [`Prefix()`](https://pkg.go.dev/github.com/fluentassert/verify#FailureMessage.Prefix)\nmethod to create complex assertions.\n\n```go\npackage test\n\nimport (\n\t\"testing\"\n\n\t\"github.com/fluentassert/verify\"\n)\n\ntype A struct {\n\tStr string\n\tOk  bool\n}\n\nfunc TestCustom(t *testing.T) {\n\tgot := A{Str: \"something was wrong\"}\n\n\tverifyA(got).Assert(t)\n}\n\nfunc verifyA(got A) verify.FailureMessage {\n\treturn verify.And(\n\t\tverify.String(got.Str).Contain(\"ok\").Prefix(\"got.String: \"),\n\t\tverify.True(got.Ok).Prefix(\"got.Ok: \"),\n\t)\n}\n```\n\n```sh\n$ go test\n--- FAIL: TestCustom (0.00s)\n    custom_test.go:17:\n        got.String: the value does not contain the substring\n        got: \"something was wrong\"\n        substr: \"ok\"\n\n        got.Ok: the value is false\n```\n\n## Extensibility\n\nYou can take advantage of the [`FailureMessage`](https://pkg.go.dev/github.com/fluentassert/verify#FailureMessage)\nand `Fluent*` types\nto create your own fluent assertions for a given type.\n\nFor reference, take a look at the implementation\nof existing fluent assertions in this repository\n(for example [comparable.go](comparable.go)).\n\n## Supported Go versions\n\nMinimal supported Go version is 1.18.\n\n## Contributing\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md) if you want to help.\n\n## License\n\n**fluentassert** is licensed under the terms of [the MIT license](LICENSE).\n\n[`github.com/google/go-cmp`](https://github.com/google/go-cmp)\n(license: [BSD-3-Clause](https://pkg.go.dev/github.com/google/go-cmp/cmp?tab=licenses))\nis the only [third-party dependency](go.mod).\n","funding_links":[],"categories":["Testing","测试"],"sub_categories":["HTTP Clients","HTTP客户端","Testing Frameworks"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffluentassert%2Fverify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffluentassert%2Fverify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffluentassert%2Fverify/lists"}