{"id":42701351,"url":"https://github.com/storage-lock/go-storage-test-helper","last_synced_at":"2026-01-29T14:20:14.337Z","repository":{"id":186151583,"uuid":"674697097","full_name":"storage-lock/go-storage-test-helper","owner":"storage-lock","description":"用于辅助测试Storage的实现是否OK的测试工具，辅助提高开发效率。","archived":false,"fork":false,"pushed_at":"2023-09-02T19:30:09.000Z","size":30,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-01-27T17:05:32.373Z","etag":null,"topics":["storage","test-tools"],"latest_commit_sha":null,"homepage":"","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/storage-lock.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-08-04T14:46:31.000Z","updated_at":"2023-08-07T16:32:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"95ff7cc6-a650-46e6-8282-089f69a4ea60","html_url":"https://github.com/storage-lock/go-storage-test-helper","commit_stats":{"total_commits":14,"total_committers":3,"mean_commits":4.666666666666667,"dds":0.1428571428571429,"last_synced_commit":"4425112efb8c6f0a65c8658195436c5d68d89259"},"previous_names":["storage-lock/go-storage-test-helper"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/storage-lock/go-storage-test-helper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/storage-lock%2Fgo-storage-test-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/storage-lock%2Fgo-storage-test-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/storage-lock%2Fgo-storage-test-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/storage-lock%2Fgo-storage-test-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/storage-lock","download_url":"https://codeload.github.com/storage-lock/go-storage-test-helper/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/storage-lock%2Fgo-storage-test-helper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28879331,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-29T10:31:27.438Z","status":"ssl_error","status_checked_at":"2026-01-29T10:31:01.017Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":["storage","test-tools"],"created_at":"2026-01-29T14:20:13.425Z","updated_at":"2026-01-29T14:20:14.302Z","avatar_url":"https://github.com/storage-lock.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Storage Test Helper\n\n# 一、这是什么\n\n用于辅助测试[Storage](https://github.com/storage-lock/go-storage)的实现是否OK的测试工具，辅助提高开发效率。\n\n# 二、安装依赖\n\n```bash\ngo get -u github.com/storage-lock/go-storage-test-helper\n```\n\n# 三、如何使用\n\n## 3.1 实现Storage\n\n根据存储介质的特性自行实现[Storage](https://github.com/storage-lock/go-storage)，这里就随便找一个空实现的例子，这个例子是肯定跑不过测试的，只是为了演示流程使用： \n\n```go\npackage examples\n\nimport (\n\t\"context\"\n\t\"github.com/golang-infrastructure/go-iterator\"\n\t\"github.com/storage-lock/go-storage\"\n\t\"time\"\n)\n\ntype FooStorage struct {\n}\n\nvar _ storage.Storage = \u0026FooStorage{}\n\nfunc (x *FooStorage) GetName() string {\n\treturn \"\"\n}\n\nfunc (x *FooStorage) Init(ctx context.Context) error {\n\treturn nil\n}\n\nfunc (x *FooStorage) UpdateWithVersion(ctx context.Context, lockId string, exceptedVersion, newVersion storage.Version, lockInformation *storage.LockInformation) error {\n\treturn nil\n}\n\nfunc (x *FooStorage) CreateWithVersion(ctx context.Context, lockId string, version storage.Version, lockInformation *storage.LockInformation) error {\n\treturn nil\n}\n\nfunc (x *FooStorage) DeleteWithVersion(ctx context.Context, lockId string, exceptedVersion storage.Version, lockInformation *storage.LockInformation) error {\n\treturn nil\n}\n\nfunc (x *FooStorage) Get(ctx context.Context, lockId string) (string, error) {\n\treturn \"\", nil\n}\n\nfunc (x *FooStorage) GetTime(ctx context.Context) (time.Time, error) {\n\treturn time.Now(), nil\n}\n\nfunc (x *FooStorage) Close(ctx context.Context) error {\n\treturn nil\n}\n\nfunc (x *FooStorage) List(ctx context.Context) (iterator.Iterator[*storage.LockInformation], error) {\n\treturn nil, nil\n}\n```\n\n## 3.2 添加依赖\n\n在你自己的Storage实现的差不多了的时候，在此项目中执行：\n\n```bash\ngo get -u github.com/storage-lock/go-storage-test-helper\n```\n\n把此测试库添加到你自己的Storage的依赖中。\n\n## 3.3 创建单元测试\n\n为你的Storage创建一个单元测试，比如下面是测试FooStorage：\n\n```go\npackage examples\n\nimport (\n\tstorage_test_helper \"github.com/storage-lock/go-storage-test-helper\"\n\t\"testing\"\n)\n\nfunc TestFooStorage(t *testing.T) {\n\t// 在要测试的Storage实现的仓库中创建好Storage，然后传递给方法测试\n\tstorage_test_helper.TestStorage(t, \u0026FooStorage{})\n}\n```\n\n再看一个更贴近实际例子的，比如下面是一个MySQL Storage的单元测试：\n\n```go\npackage mysql_storage\n\nimport (\n\t\"context\"\n\tstorage_test_helper \"github.com/storage-lock/go-storage-test-helper\"\n\t\"github.com/stretchr/testify/assert\"\n\t\"os\"\n\t\"testing\"\n)\n\nfunc TestNewMySQLStorage(t *testing.T) {\n\tenvName := \"STORAGE_LOCK_MYSQL_DSN\"\n\tdsn := os.Getenv(envName)\n\tassert.NotEmpty(t, dsn)\n\tconnectionGetter := NewMySQLConnectionManagerFromDSN(dsn)\n\ts, err := NewMySQLStorage(context.Background(), \u0026MySQLStorageOptions{\n\t\tConnectionManager: connectionGetter,\n\t\tTableName:         \"storage_lock_test\",\n\t})\n\tassert.Nil(t, err)\n    // 重点在与这一句，把 *testing.T 和 storage.Storage 传进去 \n\tstorage_test_helper.TestStorage(t, s)\n}\n```\n\n保证此单元测试通过，你可以在CI中执行单元测试以保证你每次修改之后Storage都能够正常工作。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstorage-lock%2Fgo-storage-test-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstorage-lock%2Fgo-storage-test-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstorage-lock%2Fgo-storage-test-helper/lists"}