{"id":21275688,"url":"https://github.com/halimath/fsmock","last_synced_at":"2025-03-15T13:13:51.981Z","repository":{"id":62867862,"uuid":"563032064","full_name":"halimath/fsmock","owner":"halimath","description":"fs.FS mock implemenation for golang","archived":false,"fork":false,"pushed_at":"2022-11-12T19:28:22.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-22T03:27:33.037Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/halimath.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}},"created_at":"2022-11-07T19:10:17.000Z","updated_at":"2022-11-07T19:10:35.000Z","dependencies_parsed_at":"2022-11-08T06:49:48.858Z","dependency_job_id":null,"html_url":"https://github.com/halimath/fsmock","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halimath%2Ffsmock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halimath%2Ffsmock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halimath%2Ffsmock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/halimath%2Ffsmock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/halimath","download_url":"https://codeload.github.com/halimath/fsmock/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243732303,"owners_count":20338839,"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-11-21T09:36:09.960Z","updated_at":"2025-03-15T13:13:51.963Z","avatar_url":"https://github.com/halimath.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fsmock\n\nA golang mock implementation of `fs.FS` and friends for testing.\n\n![CI Status][ci-img-url] \n[![Go Report Card][go-report-card-img-url]][go-report-card-url] \n[![Package Doc][package-doc-img-url]][package-doc-url] \n[![Releases][release-img-url]][release-url]\n\n[ci-img-url]: https://github.com/halimath/fsmock/workflows/CI/badge.svg\n[go-report-card-img-url]: https://goreportcard.com/badge/github.com/halimath/fsmock\n[go-report-card-url]: https://goreportcard.com/report/github.com/halimath/fsmock\n[package-doc-img-url]: https://img.shields.io/badge/GoDoc-Reference-blue.svg\n[package-doc-url]: https://pkg.go.dev/github.com/halimath/fsmock\n[release-img-url]: https://img.shields.io/github/v/release/halimath/fsmock.svg\n[release-url]: https://github.com/halimath/fsmock/releases\n\n`fsmock` implements a mock filesystem satisfying `fs.FS` and other interfaces\nto enable easier testing of code that uses `fs.FS` to access file systems.\n\n# Installation\n\n`fsmock` is provided as a go module and requires go \u003e= 1.16.\n\n```shell\ngo get github.com/halimath/fsmock@main\n```\n\n# Usage\n\n`fsmock` provides two basic types `Dir` and `File`. These can be used to build\nup a filesystem in plain go. Use the provided functions `NewDir` and `NewFile`\nto create them conveniently.\n\nCreate a new filesystem by invoking `fsmock.New` providing a root directory.\n\n```go\nfsys := fsmock.New(fsmock.NewDir(\"\",\n    fsmock.EmptyFile(\"go.mod\"),\n    fsmock.EmptyFile(\"go.sum\"),\n    fsmock.NewDir(\"cmd\",\n        fsmock.TextFile(\"main.go\", \"package main\"),\n    ),\n    fsmock.NewDir(\"internal\",\n        fsmock.EmptyFile(\"tool.go\"),\n        fsmock.EmptyFile(\"tool_test.go\"),\n    ),\n))\n```\n\nYou can use the methods defined in `fs.FS` and other interfaces from the `fs`\npackage to access files and directories:\n\n```go\nf, err := fsys.Open(\"cmd/main.go\")\nif err != nil {\n    panic(err)\n}\n```\n\n```go\nfs.WalkDir(fsys, \"\", func(path string, d fs.DirEntry, err error) error {\n    // ...\n    return nil\n})\n```\n\n## Modifying the filesystem\n\nIn addition to the read-only functions defined by the `fs` interfaces, `fsmock`\nprovides some helper functions to modify the filesystem.\n\nTo update a modification timestamp of either a file or directory use the\n`Touch` function. This will also create an empty file if the named file does\nnot exist (just like the Unix `touch` command does):\n\n```go\nif err := fsys.Touch(\"internal/foo/foo.go\"); err != nil {\n    panic(err)\n}\n```\n\nTo create a directory use the `Mkdir` function which works like the `mkdir`\nUnix shell command (_without_ the `-p` option):\n\n```go\nif err := fsys.Mkdir(\"internal/foo\"); err != nil {\n    panic(err)\n}\n```\n\nSee [`fsmock_test.go`](./fsmock_test.go) for a full-blown example.\n\n# License\n\nCopyright 2022 Alexander Metzner.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)\n\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhalimath%2Ffsmock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhalimath%2Ffsmock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhalimath%2Ffsmock/lists"}