{"id":29649765,"url":"https://github.com/iwdgo/testingfiles","last_synced_at":"2025-07-22T04:35:17.769Z","repository":{"id":57486361,"uuid":"179801418","full_name":"iwdgo/testingfiles","owner":"iwdgo","description":"Using files to test large output","archived":false,"fork":false,"pushed_at":"2025-01-06T20:56:10.000Z","size":98,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-06T21:29:36.289Z","etag":null,"topics":["go","golang","reference-files","testing","testing-tools"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/iwdgo/testingfiles","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iwdgo.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-06T07:18:47.000Z","updated_at":"2025-01-06T20:56:13.000Z","dependencies_parsed_at":"2024-06-21T11:53:35.290Z","dependency_job_id":"bd8b1eb1-3492-450d-9ef9-430f66346db6","html_url":"https://github.com/iwdgo/testingfiles","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/iwdgo/testingfiles","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iwdgo%2Ftestingfiles","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iwdgo%2Ftestingfiles/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iwdgo%2Ftestingfiles/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iwdgo%2Ftestingfiles/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iwdgo","download_url":"https://codeload.github.com/iwdgo/testingfiles/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iwdgo%2Ftestingfiles/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266428477,"owners_count":23927005,"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","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"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":["go","golang","reference-files","testing","testing-tools"],"created_at":"2025-07-22T04:35:16.944Z","updated_at":"2025-07-22T04:35:17.743Z","avatar_url":"https://github.com/iwdgo.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Go Reference](https://pkg.go.dev/badge/github.com/iwdgo/testingfiles.svg)](https://pkg.go.dev/github.com/iwdgo/testingfiles)\n[![Go Report Card](https://goreportcard.com/badge/github.com/iwdgo/testingfiles)](https://goreportcard.com/report/github.com/iwdgo/testingfiles)\n[![codecov](https://codecov.io/gh/iwdgo/testingfiles/branch/master/graph/badge.svg)](https://codecov.io/gh/iwdgo/testingfiles)\n\n[![Build Status](https://api.cirrus-ci.com/github/iwdgo/testingfiles.svg)](https://cirrus-ci.com/github/iwdgo/testingfiles)\n[![Build status](https://ci.appveyor.com/api/projects/status/eimlas99romrrro0?svg=true)](https://ci.appveyor.com/project/iwdgo/testingfiles)\n[![Go](https://github.com/iwdgo/testingfiles/actions/workflows/go.yml/badge.svg)](https://github.com/iwdgo/testingfiles/actions/workflows/go.yml)\n\n# Using reference files for large output\n\nA `want` reference file is compared to data from a `got` source.\nComparison is provided for `File`, `Buffer` or `ReadCloser` where a file is the least efficient.\n\nWhen comparison fails, a file is created with `got_` prefix from the byte where the first difference\nappeared. No further check on the file is done.\n\nWhen running tests for the first time, they might fail as no `want` file is usually available.\nThe produced `got` file can be renamed into a `want` file to have a second successful run.\n\n### Offline test\n\n```\n\nfunc TestOffline(t *testing.T) {\n\tif err := tearDownOffline(handler(...), t.Name()); err != nil {\n    \t\tt.Error(err)\n    }\n}\n\nfunc tearDownOffline(b *bytes.Buffer, s string) (err error) {\n\tif b == nil {\n\t\treturn errors.New(\"bytes.Buffer is nil\")\n\t}\n\ttestingfiles.OutputDir(\"output\")\n\t\n\tif err := testingfiles.BufferCompare(b, s); err != nil {\n        return err\n    }\n    return nil\n}\n\n```\n\n### Online test\n\n```\n\nfunc TestOnline(t *testing.T) {\n\tresp, err := http.Get(getAppUrl(\"\").String())\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\ttearDown(t, resp)\n}\n\nfunc tearDown(t *testing.T, resp *http.Response) {\n\tif resp == nil {\n\t\tt.Fatal(\"response is nil\")\n\t}\n\tif resp.StatusCode != 200 {\n\t\tt.Fatalf(\"request failed with error %d for %s\", resp.StatusCode, s)\n\t}\n\ttestingfiles.OutputDir(\"output\")\n\t\n\tif err := testingfiles.ReadCloserCompare(resp.Body, t.Bame()); err != nil {\n        t.Error(err)\n    }\n}\n\n```\n\n## Working directory\n\nReference files are expected to reside in a working directory which defaults to `./output`.\nUsing a subdirectory avoids having the data files mixed with source code.\nThe directory is not created but its existence is checked.\nIf the working directory is unavailable, tests will panic.\nIn CI scripts, the working directory is created before running the tests.\n\n## Testing of the module\n\nTesting can be online or offline.\n\nOnline is used to read a reference page. \nOffline requires to provide the reference file.\n\n# Common files\n\nA first method allows to extract common lines between files selected using a glob pattern.\nA second method removes common lines from each file.\n\n```\n    // Extract all common features from Linux ports\n\tp := filepath.Join(os.Getenv(\"GOROOT\"), \"/api/refs\")\n\tgf := \"z_syscall_linux_*.txt\"\n\tbaseline := \"z_syscall_linux.txt\"\n\tif err := ExtractCommon(p, gf, baseline); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tif err := CreateSupplements(p, gf, baseline); err != nil {\n\t\tlog.Fatal(err)\n\t}\n```\n# Good to know\n\nOther examples are available in modules of [largeoutput](https://github.com/iwdgo/largeoutput) repository.\n\nBenchmarking between string and bytes.Buffer is inconclusive inline with documented behavior.\n\n```\ngo version go1.13beta1 windows/amd64\npkg: github.com/iwdgo/testingfiles\nBenchmarkGetPageStringToFile-4                 1        1029407400 ns/op\nBenchmarkGetPageBufferToFile-4                 1        1108362700 ns/op\nBenchmarkGetPageBufferCompare-4                2         512716000 ns/op\nBenchmarkGetPageReadCloserCompare-4            3         545020000 ns/op\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiwdgo%2Ftestingfiles","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiwdgo%2Ftestingfiles","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiwdgo%2Ftestingfiles/lists"}