{"id":26685441,"url":"https://github.com/goapt/dbunit","last_synced_at":"2026-05-18T13:03:45.121Z","repository":{"id":57540923,"uuid":"285731432","full_name":"goapt/dbunit","owner":"goapt","description":"golang database unit testing package","archived":false,"fork":false,"pushed_at":"2026-01-22T06:53:04.000Z","size":82,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-22T19:57:53.089Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/goapt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-08-07T03:50:12.000Z","updated_at":"2026-01-22T06:51:01.000Z","dependencies_parsed_at":"2022-09-17T23:22:55.971Z","dependency_job_id":null,"html_url":"https://github.com/goapt/dbunit","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/goapt/dbunit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goapt%2Fdbunit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goapt%2Fdbunit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goapt%2Fdbunit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goapt%2Fdbunit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goapt","download_url":"https://codeload.github.com/goapt/dbunit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goapt%2Fdbunit/sbom","scorecard":{"id":432777,"data":{"date":"2025-08-11","repo":{"name":"github.com/goapt/dbunit","commit":"90217913accccb1460129c0b077f606e2977578d"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.1,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/12 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/main.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/goapt/dbunit/main.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/goapt/dbunit/main.yml/master?enable=pin","Warn: downloadThenRun not pinned by hash: .github/workflows/main.yml:32","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 downloadThenRun dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T03:45:52.537Z","repository_id":57540923,"created_at":"2025-08-19T03:45:52.537Z","updated_at":"2025-08-19T03:45:52.537Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33178727,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-18T09:27:30.708Z","status":"ssl_error","status_checked_at":"2026-05-18T09:27:28.300Z","response_time":71,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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-03-26T10:16:03.659Z","updated_at":"2026-05-18T13:03:45.116Z","avatar_url":"https://github.com/goapt.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 数据库单元测试辅助\n\n\u003ca href=\"https://github.com/goapt/dbunit/actions\"\u003e\u003cimg src=\"https://github.com/goapt/dbunit/workflows/build/badge.svg\" alt=\"Build Status\"\u003e\u003c/a\u003e\n\u003ca href=\"https://codecov.io/gh/goapt/dbunit\"\u003e\u003cimg src=\"https://codecov.io/gh/goapt/dbunit/branch/master/graph/badge.svg\" alt=\"codecov\"\u003e\u003c/a\u003e\n\u003ca href=\"https://goreportcard.com/report/github.com/goapt/dbunit\"\u003e\u003cimg src=\"https://goreportcard.com/badge/github.com/goapt/dbunit\" alt=\"Go Report Card\n\"\u003e\u003c/a\u003e\n\u003ca href=\"https://pkg.go.dev/github.com/goapt/dbunit\"\u003e\u003cimg src=\"https://img.shields.io/badge/go.dev-reference-007d9c?logo=go\u0026logoColor=white\u0026style=flat-square\" alt=\"GoDoc\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opensource.org/licenses/mit-license.php\" rel=\"nofollow\"\u003e\u003cimg src=\"https://badges.frapsoft.com/os/mit/mit.svg?v=103\"\u003e\u003c/a\u003e\n\n## 使用\n\n```shell script\ngo get github.com/goapt/dbunit\n```\n\n1、单数据库自动辅助测试函数\n\n```go\ndsn := \"root:123456@tcp(127.0.0.1:3306)/\"\ndbunit.Run(t, dsn, \"testdata/schema.sql\", func(t *testing.T, db *sql.DB) {\n    row := db.QueryRow(\"select email from users where id = 1\")\n    var email string\n    if err := row.Scan(\u0026email); err != nil {\n        t.Fatal(err)\n    }\n\n    if email != \"test@test.cn\" {\n        t.Fatalf(\"user mismatch want %s,but get %s\", \"test@test.cn\", email)\n    }\n})\n```\n\n\u003e dbunit.Run 会自动创建数据库，并且自动导入`testdata/fixtures`目录下面的测试数据\n\n2、多数据库创建\n\n```go\ndsn := \"root:123456@tcp(127.0.0.1:3306)/\"\ndbunit.New(t, func(d *DBUnit) {\n    db := d.NewDatabase(dsn, \"testdata/schema.sql\",\"testdata/fixtures/users.yml\")\n    // more database\n    db2 = d.NewDatabase(dsn, \"testdata/schema2.sql\")\n    .....\n})\n```\n\n## 支持数据库\n\n- MySQL\n- PostgreSQL (driver: pgx)\n\n## 从测试库导出测试数据文件\n\n### 使用脚本导出数据\n\n```go\ndb, err := sql.Open(\"mysql\", fmt.Sprintf(\"%s:%s@tcp(%s:3306)/%s\", os.Getenv(\"DEV_DATABASE_USERNAME\"), os.Getenv(\"DEV_DATABASE_PASSWORD\"), os.Getenv(\"DEV_DATABASE_HOST\"), \"example\")+\"?charset=utf8\u0026parseTime=True\u0026loc=Asia%2FShanghai\")\nif err != nil {\n    t.Fatal(\"db open error:\", err)\n}\n// 导出前10个文档信息\ndata, err := dbunit.Dump(db, \"testdata/fixtures/documents.yml\", \"select * from documents limit 10\")\nif err != nil {\n    t.Fatal(\"dump documents error:\", err)\n}\n\n// 从结果集中获取用户ID\nuserIds := dbunit.Pluck(data, \"user_id\")\n\n//  导出所有相关的用户\n_, err = dbunit.Dump(db, \"testdata/fixtures/users.yml\", \"select * from users where id in(?)\", userIds)\nif err != nil {\n    t.Fatal(\"dump users error:\", err)\n}\n```\n\n\u003e 如果导出的数据已经在数据集文件中存在，则会忽略，判断依据为主键一致\n\n### 导出测试集\n\n你可以在参看 `testdata/fixture.go` 脚本编写测试集导出脚本\n\n```go\n// 文章数据集\ndata, err := dbunit.Dump(db, \"testdata/fixtures/articles.yml\",\n    \"select * from articles where doc_id in(1,2)\",\n)\nif err != nil {\n    panic(err)\n}\n```\n\n### 和其他ORM配合使用\n\n```go\ndsn := \"root:123456@tcp(127.0.0.1:3306)/\"\ndbunit.New(t, func(d *DBUnit) {\n    db := d.NewDatabase(dsn, \"testdata/schema.sql\",\"testdata/fixtures/users.yml\")\n\n    gormDB, err := gorm.Open(mysql.New(mysql.Config{Conn: db}))\n})\n```\n\n## 关于fixture\n\n当数据中需要动态数据，比如时间，可以参考如下做法，或者贡献你要的templateFunc\n\n```yaml\n- id: 1\n  created_at: { { now } }\n  updated_at: { { now } }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoapt%2Fdbunit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoapt%2Fdbunit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoapt%2Fdbunit/lists"}