{"id":13413869,"url":"https://github.com/rekby/fixenv","last_synced_at":"2025-10-05T02:33:49.361Z","repository":{"id":37989241,"uuid":"400649733","full_name":"rekby/fixenv","owner":"rekby","description":null,"archived":false,"fork":false,"pushed_at":"2024-08-09T16:39:29.000Z","size":103,"stargazers_count":30,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-10T10:02:34.310Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rekby.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2021-08-27T22:33:04.000Z","updated_at":"2024-10-07T09:34:47.000Z","dependencies_parsed_at":"2022-09-02T16:47:38.615Z","dependency_job_id":"c5b02a7d-11ee-49da-b735-80db1c14a604","html_url":"https://github.com/rekby/fixenv","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rekby%2Ffixenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rekby%2Ffixenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rekby%2Ffixenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rekby%2Ffixenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rekby","download_url":"https://codeload.github.com/rekby/fixenv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230511479,"owners_count":18237657,"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":[],"created_at":"2024-07-30T20:01:51.588Z","updated_at":"2025-10-05T02:33:49.247Z","avatar_url":"https://github.com/rekby.png","language":"Go","readme":"[![Go Reference](https://pkg.go.dev/badge/github.com/rekby/fixenv.svg)](https://pkg.go.dev/github.com/rekby/fixenv)\n[![Coverage Status](https://coveralls.io/repos/github/rekby/fixenv/badge.svg?branch=master)](https://coveralls.io/github/rekby/fixenv?branch=master)\n[![GoReportCard](https://goreportcard.com/badge/github.com/rekby/fixenv)](https://goreportcard.com/report/github.com/rekby/fixenv)\n[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)  \n\nGo Fixtures\n===========\n\nInspired by pytest fixtures. No dependencies.\n\n[Examples](https://github.com/rekby/fixenv/tree/master/examples)\n\nThe package provide engine for write and use own fixtures.\n\nFixture - function-helper for provide some object/service for test. \nFixture calls with same parameters cached and many time calls of the fixture return same result \nand work did once only.\n\n```golang\npackage example\n\n// counter fixture - increment globalCounter every non cached call\n// and return new globalCounter value\n// cache shared one test \nfunc counter(e fixenv.Env) int {...}\n\nfunc TestCounter(t *testing.T) {\n\te := fixenv.NewEnv(t)\n\n\tr1 := counter(e)\n\tr2 := counter(e)\n\tif r1 != r2 {\n\t\tt.Error()\n\t}\n\n\tt.Run(\"subtest\", func(t *testing.T) {\n\t\te := fixenv.NewEnv(t)\n\t\tr3 := counter(e)\n\t\tif r3 == r1 {\n\t\t\tt.Error()\n\t\t}\n\t})\n}\n```\n\n\nFor example with default scope test - it work will done once per test. \nWith scope TestAndSubtests - cache shared by test (TestFunction(t *testing.T)) and all of that subtest.\nWith package scope - result cached for all test in package.\nFixture can have cleanup function, that called while out of scope.\n\nFixture can call other fixtures, cache shared between them.\n\nFor example simple account test:\n```golang\npackage example\n\n// db create database abd db struct, cached per package - call\n// once and same db shared with all tests\nfunc db(e Env)*DB{...}\n\n// DbCustomer - create customer with random personal data\n// but fixed name. Fixture result shared by test and subtests, \n// then mean many calls Customer with same name will return same\n// customer object.\n// Call Customer with other name will create new customer\n// and resurn other object.\nfunc DbCustomer(e Env, name string) Customer {\n\t// ... create customer\n\tdb(e).CustomerStore(cust)\n\t// ...\n\treturn cust\n}\n\n// DbAccount create bank account for customer with given name.\nfunc DbAccount(e Env, customerName, accountName string)Account{\n\tcust := DbCustomer(e, customerName)\n\t// ... create account\n\tdb(e).AccountStore(acc)\n\t// ...\n\treturn acc\n}\n\nfunc TestFirstOwnAccounts(t *testing.T){\n\te := NewEnv(t)\n\t// background:\n\t// create database\n\t// create customer bob \n\t// create account from\n\taccFrom := DbAccount(e, \"bob\", \"from\")\n\t\n\t// get existed db, get existed bob, create account to\n\taccTo := DbAccount(e, \"bob\", \"to\")\n\t\n\tPutMoney(accFrom, 100)\n\tSendMoney(accFrom, accTo, 20)\n\tif accFrom != 80 {\n\t\tt.Error()\n\t}\n\tif accTo != 20 {\n\t\tt.Error()   \n\t}\n\t\n\t// background:\n\t// delete account to\n\t// delete account from\n\t// delete customer bob\n}\n\nfunc TestSecondTransferBetweenCustomers(t *testing.T){\n\te := NewEnv(t)\n\t\n\t// background:\n\t// get db, existed from prev test\n\t// create customer bob\n\t// create account main for bob\n\taccFrom := DbAccount(e, \"bob\", \"main\")\n\t\n\t// background:\n\t// get existed db\n\t// create customer alice\n\t// create account main for alice\n\taccTo := DbAccount(e, \"alice\", \"main\")\n\tPutMoney(accFrom, 100)\n\tSendMoney(accFrom, accTo, 20)\n\tif accFrom != 80 {\n\t\tt.Error()\n\t}\n\tif accTo != 20 {\n\t\tt.Error()\n\t}\n\t\n\t// background:\n\t// remove account of alice\n\t// remove customer alice\n\t// remove account of bob\n\t// remove customer bob\n}\n\n// background:\n// after all test finished drop database\n```\n","funding_links":[],"categories":["Testing","Testing Frameworks","测试","Template Engines"],"sub_categories":["Testing Frameworks","HTTP客户端","HTTP Clients"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frekby%2Ffixenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frekby%2Ffixenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frekby%2Ffixenv/lists"}