{"id":21560402,"url":"https://github.com/icza/mighty","last_synced_at":"2025-04-10T11:52:18.078Z","repository":{"id":57480718,"uuid":"67695856","full_name":"icza/mighty","owner":"icza","description":"Lightweight extension to Go's testing package.","archived":false,"fork":false,"pushed_at":"2023-03-30T13:32:00.000Z","size":34,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-24T10:45:47.270Z","etag":null,"topics":["library","lightweight-extension","testing"],"latest_commit_sha":null,"homepage":"","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/icza.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":"icza"}},"created_at":"2016-09-08T11:08:52.000Z","updated_at":"2024-08-01T14:17:46.000Z","dependencies_parsed_at":"2024-06-19T05:29:27.907Z","dependency_job_id":"7d2cd24a-8351-4844-828e-88370bd227d4","html_url":"https://github.com/icza/mighty","commit_stats":{"total_commits":37,"total_committers":1,"mean_commits":37.0,"dds":0.0,"last_synced_commit":"909cba2425e976530eca066f1f8292b76a191202"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icza%2Fmighty","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icza%2Fmighty/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icza%2Fmighty/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icza%2Fmighty/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/icza","download_url":"https://codeload.github.com/icza/mighty/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248215192,"owners_count":21066622,"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":["library","lightweight-extension","testing"],"created_at":"2024-11-24T09:14:07.644Z","updated_at":"2025-04-10T11:52:18.061Z","avatar_url":"https://github.com/icza.png","language":"Go","funding_links":["https://github.com/sponsors/icza"],"categories":[],"sub_categories":[],"readme":"# mighty\n\n![Build Status](https://github.com/icza/mighty/actions/workflows/go.yml/badge.svg)\n[![Go Reference](https://pkg.go.dev/badge/github.com/icza/mighty.svg)](https://pkg.go.dev/github.com/icza/mighty)\n[![Go Report Card](https://goreportcard.com/badge/github.com/icza/mighty)](https://goreportcard.com/report/github.com/icza/mighty)\n[![codecov](https://codecov.io/gh/icza/mighty/branch/master/graph/badge.svg)](https://codecov.io/gh/icza/mighty)\n\nPackage `mighty` is a lightweight extension to Go's [testing](https://golang.org/pkg/testing/) package.\n\nWith this utility, you can make your Go test files super clean but still intuitive.\nThis package doesn't want to hide complex things from you, but wants to eliminate repetitive,\nlong code from your tests.\n\n## Using `mighty`\n\nYou could create a value of `mighty.Myt` and use its methods like `m.Eq()`, `m.Neq()`, ... etc. as seen below:\n\n\tm := mighty.Myt{t} // t is of type *testing.T\n\tm.Eq(6, len(\"mighty\")) // Expect len(\"mighty\") to be 6\n\tr := bytes.NewBuffer([]byte{'a'})\n\tm.ExpEq(byte('a'))(r.ReadByte()) // Expect to read 'a' and no error\n\nBut the recommended, more intuitive and more compact way is to acquire and use [method values](https://golang.org/ref/spec#Method_values)\nreturned by functions of `mighty`:\n\n\teq, expEq := mighty.EqExpEq(t) // t is of type *testing.T\n\teq(6, len(\"mighty\")) // Expect len(\"mighty\") to be 6\n\tr := bytes.NewBuffer([]byte{'a'})\n\texpEq(byte('a'))(r.ReadByte()) // Expect to read 'a' and no error\n\n### Example #1: testing `math.Abs()`\n\nWithout `mighty` it could look like this:\n\n\tcases := []struct{ in, exp float64 }{{1, 1}, {-1, 1}}\n\tfor _, c := range cases {\n\t\tif got := math.Abs(c.in); got != c.exp {\n\t\t\tt.Errorf(\"Expected: %v, got: %v\", c.exp, got)\n\t\t}\n\t}\n\nUsing `mighty`:\n\n\tcases := []struct{ in, exp float64 }{{1, 1}, {-1, 1}}\n\teq := mighty.Eq(t)\n\tfor _, c := range cases {\n\t\teq(c.exp, math.Abs(c.in))\n\t}\n\n### Example #2: testing reading from `bytes.Buffer`\n\nWithout `mighty` it could look like this:\n\n\tr := bytes.NewBufferString(\"test-data\")\n\tif b, err := r.ReadByte(); b != 't' || err != nil {\n\t\tt.Errorf(\"Expected: %v, got: %v, error: %v\", 't', b, err)\n\t}\n\tif line, err := r.ReadString('-'); line != \"est-\" || err != nil {\n\t\tt.Errorf(\"Expected: %v, got: %v, error: %v\", \"est\", line, err)\n\t}\n\tp := make([]byte, 4)\n\tif n, err := r.Read(p); n != 4 || string(p) != \"data\" || err != nil {\n\t\tt.Errorf(\"Expected: n=%v, p=%v; got: n=%v, p=%v; error: %v\",\n\t\t\t4, \"data\", n, string(p), err)\n\t}\n\nUsing `mighty`:\n\n\teq, expEq := mighty.EqExpEq(t)\n\tr := bytes.NewBufferString(\"test-data\")\n\texpEq(byte('t'))(r.ReadByte())\n\texpEq(\"est-\")(r.ReadString('-'))\n\tp := make([]byte, 4)\n\texpEq(4)(r.Read(p))\n\teq(\"data\", string(p))\n\n### More examples\n\nFor more usage examples, check out the following packages which use `mighty` extensively in their testing code:\n\n- [github.com/icza/bitio](https://github.com/icza/bitio)\n- [github.com/icza/session](https://github.com/icza/session)\n- [github.com/icza/kvcache](https://github.com/icza/kvcache)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficza%2Fmighty","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ficza%2Fmighty","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficza%2Fmighty/lists"}