{"id":29801234,"url":"https://github.com/go-spring/gs-assert","last_synced_at":"2025-07-28T09:44:12.905Z","repository":{"id":300333591,"uuid":"1005847166","full_name":"go-spring/gs-assert","owner":"go-spring","description":"A minimal, fluent, and highly readable assertion library for Go unit testing.","archived":false,"fork":false,"pushed_at":"2025-07-28T06:03:33.000Z","size":112,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-28T08:18:14.764Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/go-spring.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"zenodo":null}},"created_at":"2025-06-20T23:53:23.000Z","updated_at":"2025-07-28T05:59:41.000Z","dependencies_parsed_at":"2025-06-21T05:28:38.163Z","dependency_job_id":"608dc2a6-d278-4619-b5cf-ccc70d50b876","html_url":"https://github.com/go-spring/gs-assert","commit_stats":null,"previous_names":["go-spring/assert","go-spring/gs-assert"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/go-spring/gs-assert","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-spring%2Fgs-assert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-spring%2Fgs-assert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-spring%2Fgs-assert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-spring%2Fgs-assert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/go-spring","download_url":"https://codeload.github.com/go-spring/gs-assert/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-spring%2Fgs-assert/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267496555,"owners_count":24097099,"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","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2025-07-28T09:44:10.299Z","updated_at":"2025-07-28T09:44:12.896Z","avatar_url":"https://github.com/go-spring.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gs-assert\n\n\u003cdiv\u003e\n   \u003cimg src=\"https://img.shields.io/github/license/go-spring/gs-assert\" alt=\"license\"/\u003e\n   \u003cimg src=\"https://img.shields.io/github/go-mod/go-version/go-spring/gs-assert\" alt=\"go-version\"/\u003e\n   \u003cimg src=\"https://img.shields.io/github/v/release/go-spring/gs-assert?include_prereleases\" alt=\"release\"/\u003e\n   \u003ca href=\"https://codecov.io/gh/go-spring/gs-assert\" \u003e \n      \u003cimg src=\"https://codecov.io/gh/go-spring/gs-assert/graph/badge.svg?token=SX7CV1T0O8\" alt=\"test-coverage\"/\u003e\n   \u003c/a\u003e\n   \u003ca href=\"https://deepwiki.com/go-spring/gs-assert\"\u003e\u003cimg src=\"https://deepwiki.com/badge.svg\" alt=\"Ask DeepWiki\"\u003e\u003c/a\u003e\n\u003c/div\u003e\n\n[English](README.md) | [中文](README_CN.md)\n\ngs-assert is an assertion library for Go unit tests,\ndesigned to enhance test code readability and maintainability.\nIt provides functional and fluent assertion styles and\nsupports assertions for multiple data structures,\nincluding generic values, strings, numbers, slices, maps, and `error`.\n\n## Installation Guide\n\nTo use the `gs-assert` library, ensure you have Go installed.\nThen, install `gs-assert` using the following command:\n\n```bash\ngo get github.com/go-spring/gs-assert\n```\n\n## Features\n\n- **Functional Assertions**：\n  Offers a rich set of assertion functions such as `Nil`, `NotNil`, `Equal`, `NotEqual`, etc.\n- **Fluent Assertions**：\n  Improves code readability through method chaining, e.g., `assert.That(t).NotNil(obj).Equal(...)`.\n- **Data Structure Support**：\n  Supports assertions for common data structures like generic values, maps, slices, strings, numbers, and `error`.\n- **`require` Module**：\n  Provides stricter assertion methods that immediately terminate the test when an assertion fails.\n\n### Supported Data Structures and Assertion Methods\n\n#### Generic Value Assertions (assert.Assertion)\n\nCreated via `assert.That(t, value)`, supports the following methods:\n\n- `True() / False()` - Assert boolean values.\n- `Nil() / NotNil()` - Assert whether a value is nil or not.\n- `Equal(expect) / NotEqual(expect)` - Assert equality or inequality.\n- `Same(expect) / NotSame(expect)` - Assert identity or non-identity.\n- `TypeOf(expect)` - Assert type compatibility.\n- `Implements(expect)` - Assert interface implementation.\n- `Has(expect)` - Assert element inclusion（via Has method）\n- `Contains(expect)` - Assert element inclusion（via Contains method）\n\n#### String Assertions (assert.StringAssertion)\n\nCreated via `assert.ThatString(t, value)`, supports the following methods:\n\n- `Length(length)` - Assert string length.\n- `Blank() / NonBlank()` - Assert whether the string is blank or not.\n- `Equal(expect) / NotEqual(expect)` - Assert string equality or inequality.\n- `EqualFold(expect)` - Assert case-insensitive equality.\n- `JSONEqual(expect)` - Assert JSON structure equality.\n- `Matches(pattern)` - Assert regex match.\n- `HasPrefix(prefix) / HasSuffix(suffix)` - Assert prefix/suffix.\n- `Contains(substr)` - Assert substring inclusion.\n- `IsLowerCase() / IsUpperCase()` - Assert case status.\n- `IsNumeric() / IsAlpha() / IsAlphaNumeric()` - Assert character type.\n- `IsEmail() / IsURL() / IsIPv4() / IsHex() / IsBase64()` - Assert specific formats.\n\n#### Number Assertions (assert.NumberAssertion)\n\nCreated via `assert.ThatNumber(t, value)`, supports the following methods:\n\n- `Equal(expect) / NotEqual(expect)` - Assert numeric equality or inequality.\n- `GreaterThan(expect) / GreaterOrEqual(expect)` - Assert greater than or equal.\n- `LessThan(expect) / LessOrEqual(expect)` - Assert less than or equal.\n- `Zero() / NonZero()` - Assert zero or non-zero.\n- `Positive() / NotPositive()` - Assert positive or non-positive.\n- `Negative() / NotNegative()` - Assert negative or non-negative.\n- `Between(lower, upper) / NotBetween(lower, upper)` - Assert within or outside a range.\n- `InDelta(expect, delta)` - Assert within a delta range.\n- `IsNaN() / IsInf(sign) / IsFinite()` - Assert special numeric states.\n\n#### Slice Assertions (assert.SliceAssertion)\n\nCreated via `assert.ThatSlice(t, value)`, supports the following methods:\n\n- `Length(length)` - Assert slice length.\n- `Nil() / NotNil()` - Assert whether the slice is nil or not.\n- `Equal(expect) / NotEqual(expect)` - Assert slice equality or inequality.\n- `Contains(element) / NotContains(element)` - Assert element inclusion/exclusion.\n- `ContainsSlice(sub) / NotContainsSlice(sub)` - Assert sub-slice inclusion/exclusion.\n- `HasPrefix(prefix) / HasSuffix(suffix)` - Assert prefix/suffix.\n- `AllUnique()` - Assert all elements are unique.\n- `AllMatches(fn) / AnyMatches(fn) / NoneMatches(fn)` - Assert element conditions.\n\n#### Map Assertions (assert.MapAssertion)\n\nCreated via `assert.ThatMap(t, value)`, supports the following methods:\n\n- `Length(length)` - Assert map length.\n- `Nil() / NotNil()` - Assert whether the map is nil or not.\n- `Equal(expect) / NotEqual(expect)` - Assert map equality or inequality.\n- `ContainsKey(key) / NotContainsKey(key)` - Assert key inclusion/exclusion.\n- `ContainsValue(value) / NotContainsValue(value)` - Assert value inclusion/exclusion.\n- `ContainsKeyValue(key, value)` - Assert key-value pair inclusion.\n- `ContainsKeys(keys) / NotContainsKeys(keys)` - Assert multiple key inclusions/exclusions.\n- `ContainsValues(values) / NotContainsValues(values)` - Assert multiple value inclusions/exclusions.\n- `SubsetOf(expect) / SupersetOf(expect)` - Assert subset/superset.\n- `HasSameKeys(expect) / HasSameValues(expect)` - Assert same keys/values.\n\n#### Error Assertions (assert.ErrorAssertion)\n\nCreated via `assert.ThatError(t, value)`, supports the following methods:\n\n- `Nil() / NotNil()` - Assert error is nil or not.\n- `Is(target) / NotIs(target)` - Assert error matches or does not match a target.\n- `Matches(expr)` - Assert error message matches regex.\n\n#### Panic Assertions\n\nUse `assert.Panic(t, fn, expr)` to assert a function panics and\nthe panic message matches an expression.\n\n## Usage Examples\n\n```go\nimport \"github.com/go-spring/gs-assert/assert\"\nimport \"github.com/go-spring/gs-assert/require\"\n\nfunc TestAssertExample(t *testing.T) {\n    // Use assert module for assertions, test continues on failure\n    assert.That(t, t).NotNil().NotSame(nil)\n    assert.That(t, 1+1).Equal(2).NotEqual(3)\n}\n\nfunc TestRequireExample(t *testing.T) {\n    // Use require module for assertions, test stops on failure\n    require.That(t, t).NotNil().NotSame(nil)\n    require.That(t, 1+1).Equal(2).NotEqual(3)\n}\n\nfunc TestPanicExample(t *testing.T) {\n    // Assert function panics and message matches the expression\n    require.Panic(t, func () {\n        panic(\"something went wrong\")\n    }, \"something went wrong\")\n}\n```\n\n## Contribution Guide\n\nWe welcome any form of contribution!\nIf you have suggestions or find bugs, please submit an issue or pull request.\nBefore submitting contributions, ensure your code adheres to\nthe project's coding standards and passes all tests.\n\n## License\n\nThe Go-Spring is released under version 2.0 of the Apache License.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-spring%2Fgs-assert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgo-spring%2Fgs-assert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-spring%2Fgs-assert/lists"}