{"id":19450367,"url":"https://github.com/jackmordaunt/filebuilder","last_synced_at":"2025-06-19T20:37:33.525Z","repository":{"id":57583650,"uuid":"118803807","full_name":"JackMordaunt/filebuilder","owner":"JackMordaunt","description":"Declaratively build file structures. Useful for testing apps that interact with the filesystem. Built on top of https://github.com/spf13/afero","archived":false,"fork":false,"pushed_at":"2018-05-07T04:02:37.000Z","size":13,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-11T09:35:56.532Z","etag":null,"topics":["afero","filesystem","go","mocking","pluggable","testing"],"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/JackMordaunt.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":"2018-01-24T18:17:35.000Z","updated_at":"2021-11-23T20:50:18.000Z","dependencies_parsed_at":"2022-09-10T08:52:01.960Z","dependency_job_id":null,"html_url":"https://github.com/JackMordaunt/filebuilder","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JackMordaunt%2Ffilebuilder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JackMordaunt%2Ffilebuilder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JackMordaunt%2Ffilebuilder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JackMordaunt%2Ffilebuilder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JackMordaunt","download_url":"https://codeload.github.com/JackMordaunt/filebuilder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240637569,"owners_count":19833137,"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":["afero","filesystem","go","mocking","pluggable","testing"],"created_at":"2024-11-10T16:37:01.830Z","updated_at":"2025-02-25T09:20:59.664Z","avatar_url":"https://github.com/JackMordaunt.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# filebuilder - A quick uitility for creating file structures and comparing them\n\n`go get github.com/jackmordaunt/filebuilder`\n\n## Why?\n\nI had trouble trying to mock out the filesystem for command line apps. \nCreating the files and comparing the files procedurally is tedious.\nI wanted a declarative way to specify \"these are the files I have\", \"these are the files I want\", and \"compare this directory with that directory\".\n\nTo that end, I don't know if this is the 'best' way to do it, or even a good way to do it.\n\nCode suggestions and project suggestions very welcome.\n\n```go\nfunc main() {\n\n        // Declare the files you want, you can nest with relative paths or use \n        // a flat list, or both.\n        entries := []filebuilder.Entry{\n                filebuilder.File{Path: \"foo/bar/baz.exe\"},\n                filebuilder.File{Path: \"foo/baz.exe\"},\n                filebuilder.File{Path: \"baz.exe\"},\n                filebuilder.Dir{Path: \"bar\", Entries: []filebuilder.Entry{\n                        filebuilder.File{Path: \"baz.txt\", Content: []byte(\"foo\")},\n                        filebuilder.File{Path: \"foo/bar/baz.txt\", Content: []byte(\"bar\")},\n                }},\n        }\n        \n        // Grab a filesystem implementation, or use the default by passing in nil.\n        // The optional root will be the parent of the provided entries.\n        fs := afero.NewMemMapFs()\n        cleanup, err := filebuilder.Build(fs, \"parent\", entries...)\n        if err != nil {\n                log.Fatalf(\"failed creating entries: %v\", err)\n        }\n\n        // Optional cleanup func which erases all files created. \n        defer func() {\n                if err := cleanup(); err != nil {\n                        log.Fatalf(\"failed cleanup of files: %v\", err)\n                }\n        }()\n\n        // fs is stateful, you can build up the file tree over multiple calls.\n        _, err = filebuilder.Build(fs, \"inside/this/folder\", entries)\n        if err != nil {\n                log.Fatalf(\"failed creating entries: %v\", err)\n        }\n\n        // Compare the directories.\n        diff, ok, err := filebuilder.CompareDirectories(fs, \"parent\", \"inside/this/folder\")\n        if err != nil {\n                log.Fatalf(\"error while comparing directories: %v\", err)\n        }\n        if !ok {\n                log.Printf(\"directories are not equivalent, %v\\n\", diff)\n        }\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackmordaunt%2Ffilebuilder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjackmordaunt%2Ffilebuilder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackmordaunt%2Ffilebuilder/lists"}