{"id":27628774,"url":"https://github.com/ldez/usetesting","last_synced_at":"2025-04-23T14:20:06.073Z","repository":{"id":265298458,"uuid":"895714247","full_name":"ldez/usetesting","owner":"ldez","description":"Detects when some calls can be replaced by methods from the testing package","archived":false,"fork":false,"pushed_at":"2025-04-14T00:21:33.000Z","size":102,"stargazers_count":27,"open_issues_count":4,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-23T14:19:56.511Z","etag":null,"topics":["go","golang","linter","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/ldez.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,"zenodo":null},"funding":{"github":"ldez","ko_fi":"ldez_oss","liberapay":"ldez","thanks_dev":"u/gh/ldez"}},"created_at":"2024-11-28T18:34:29.000Z","updated_at":"2025-04-14T00:21:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"ac8ff0e4-16ff-4c41-b0f7-abbb7b664910","html_url":"https://github.com/ldez/usetesting","commit_stats":null,"previous_names":["ldez/usetesting"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ldez%2Fusetesting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ldez%2Fusetesting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ldez%2Fusetesting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ldez%2Fusetesting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ldez","download_url":"https://codeload.github.com/ldez/usetesting/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250447982,"owners_count":21432166,"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":["go","golang","linter","testing"],"created_at":"2025-04-23T14:20:05.373Z","updated_at":"2025-04-23T14:20:06.054Z","avatar_url":"https://github.com/ldez.png","language":"Go","funding_links":["https://github.com/sponsors/ldez","https://ko-fi.com/ldez_oss","https://liberapay.com/ldez","https://thanks.dev/u/gh/ldez"],"categories":[],"sub_categories":[],"readme":"# UseTesting\n\nDetects when some calls can be replaced by methods from the testing package.\n\n[![Sponsor](https://img.shields.io/badge/Sponsor%20me-%E2%9D%A4%EF%B8%8F-pink)](https://github.com/sponsors/ldez)\n\n## Usages\n\n### Inside golangci-lint\n\nRecommended.\n\n```yml\nlinters:\n  enable:\n    - usetesting\n\n  settings:\n      usetesting:\n        # Enable/disable `os.CreateTemp(\"\", ...)` detections.\n        # Default: true\n        os-create-temp: false\n    \n        # Enable/disable `os.MkdirTemp()` detections.\n        # Default: true\n        os-mkdir-temp: false\n    \n        # Enable/disable `os.Setenv()` detections.\n        # Default: true\n        os-setenv: false\n    \n        # Enable/disable `os.TempDir()` detections.\n        # Default: false\n        os-temp-dir: true\n        \n        # Enable/disable `os.Chdir()` detections.\n        # Disabled if Go \u003c 1.24.\n        # Default: true\n        os-chdir: false\n    \n        # Enable/disable `context.Background()` detections.\n        # Disabled if Go \u003c 1.24.\n        # Default: true\n        context-background: false\n    \n        # Enable/disable `context.TODO()` detections.\n        # Disabled if Go \u003c 1.24.\n        # Default: true\n        context-todo: false\n```\n\n### As a CLI\n\n```shell\ngo install github.com/ldez/usetesting/cmd/usetesting@latest\n```\n\n```\nusetesting: Reports uses of functions with replacement inside the testing package.\n\nUsage: usetesting [-flag] [package]\n\nFlags:\n  -contextbackground\n        Enable/disable context.Background() detections (default true)\n  -contexttodo\n        Enable/disable context.TODO() detections (default true)\n  -oschdir\n        Enable/disable os.Chdir() detections (default true)\n  -osmkdirtemp\n        Enable/disable os.MkdirTemp() detections (default true)\n  -ossetenv\n        Enable/disable os.Setenv() detections (default false)\n  -ostempdir\n        Enable/disable os.TempDir() detections (default false)\n  -oscreatetemp\n        Enable/disable os.CreateTemp(\"\", ...) detections (default true)\n...\n```\n\n## Examples\n\n### `os.MkdirTemp`\n\n```go\nfunc TestExample(t *testing.T) {\n\tos.MkdirTemp(\"a\", \"b\")\n\t// ...\n}\n```\n\nIt can be replaced by:\n\n```go\nfunc TestExample(t *testing.T) {\n\tt.TempDir()\n    // ...\n}\n```\n\n### `os.TempDir`\n\n```go\nfunc TestExample(t *testing.T) {\n\tos.TempDir()\n\t// ...\n}\n```\n\nIt can be replaced by:\n\n```go\nfunc TestExample(t *testing.T) {\n\tt.TempDir()\n    // ...\n}\n```\n\n### `os.CreateTemp`\n\n```go\nfunc TestExample(t *testing.T) {\n\tos.CreateTemp(\"\", \"x\")\n\t// ...\n}\n```\n\nIt can be replaced by:\n\n```go\nfunc TestExample(t *testing.T) {\n    os.CreateTemp(t.TempDir(), \"x\")\n    // ...\n}\n```\n\n### `os.Setenv`\n\n```go\nfunc TestExample(t *testing.T) {\n\tos.Setenv(\"A\", \"b\")\n\t// ...\n}\n```\n\nIt can be replaced by:\n\n```go\nfunc TestExample(t *testing.T) {\n\tt.Setenv(\"A\", \"b\")\n    // ...\n}\n```\n\n### `os.Chdir` (Go \u003e= 1.24)\n\n```go\nfunc TestExample(t *testing.T) {\n\tos.Chdir(\"x\")\n\t// ...\n}\n```\n\nIt can be replaced by:\n\n```go\nfunc TestExample(t *testing.T) {\n\tt.Chdir(\"x\")\n    // ...\n}\n```\n\n### `context.Background` (Go \u003e= 1.24)\n\n```go\nfunc TestExample(t *testing.T) {\n    ctx := context.Background()\n\t// ...\n}\n```\n\nIt can be replaced by:\n\n```go\nfunc TestExample(t *testing.T) {\n    ctx := t.Context()\n    // ...\n}\n```\n\n### `context.TODO` (Go \u003e= 1.24)\n\n```go\nfunc TestExample(t *testing.T) {\n    ctx := context.TODO()\n\t// ...\n}\n```\n\nIt can be replaced by:\n\n```go\nfunc TestExample(t *testing.T) {\n    ctx := t.Context()\n    // ...\n}\n```\n\n## References\n\n- https://tip.golang.org/doc/go1.15#testingpkgtesting (`TempDir`)\n- https://tip.golang.org/doc/go1.17#testingpkgtesting (`SetEnv`)\n- https://tip.golang.org/doc/go1.24#testingpkgtesting (`Chdir`, `Context`)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fldez%2Fusetesting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fldez%2Fusetesting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fldez%2Fusetesting/lists"}