{"id":16809040,"url":"https://github.com/timakin/dsmock","last_synced_at":"2026-03-14T00:36:27.074Z","repository":{"id":68621559,"uuid":"143312878","full_name":"timakin/dsmock","owner":"timakin","description":"dsmock is a fixture-injector for appengine datastore, based on YAML format fixtures","archived":false,"fork":false,"pushed_at":"2018-08-11T11:47:43.000Z","size":9,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T01:41:18.863Z","etag":null,"topics":["appengine","appengine-go","datastore","gcp","go","golang","google","mocking","testing","testing-tools"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/timakin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-08-02T15:25:27.000Z","updated_at":"2019-04-24T04:58:17.000Z","dependencies_parsed_at":"2023-02-21T13:31:01.417Z","dependency_job_id":null,"html_url":"https://github.com/timakin/dsmock","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/timakin/dsmock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timakin%2Fdsmock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timakin%2Fdsmock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timakin%2Fdsmock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timakin%2Fdsmock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timakin","download_url":"https://codeload.github.com/timakin/dsmock/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timakin%2Fdsmock/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30480541,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-13T23:57:05.347Z","status":"ssl_error","status_checked_at":"2026-03-13T23:56:58.046Z","response_time":60,"last_error":"SSL_read: 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":["appengine","appengine-go","datastore","gcp","go","golang","google","mocking","testing","testing-tools"],"created_at":"2024-10-13T10:00:41.482Z","updated_at":"2026-03-14T00:36:27.061Z","avatar_url":"https://github.com/timakin.png","language":"Go","readme":"dsmock\n====\n\ndsmock is a fixture-injector for appengine datastore, based on YAML format fixtures.\nRunning unit tests with [aetest](https://cloud.google.com/appengine/docs/standard/go/tools/localunittesting/reference) is simple, but like as an integration test, when you try to test API handlers is very hard. One of the reasons is preparing mock data for datastore has no general way.\nThis package will help you to insert them without any painful steps.\n\n## Install\n\n`go get -u github.com/timakin/dsmock`\n\n## Getting started\n\n### fixtures\nAt first, you write the fixtures on YAML file.\nThis yaml must contains the information about your datastore entity with the keys: `schema` and `entities`.\n\n```\nscheme:\n  kind: User\n  key: ID\n\nentities:\n- ID: 1\n  Name: John Doe\n  Enabled: true\n  CreatedAt: 1526477595\n  UpdatedAt: 1526477595\n- ID: 2\n  Name: Jane Doe\n  Enabled: true\n  CreatedAt: 1526477595\n  UpdatedAt: 1526477595\n```\n\n### Insert data\n\nAfter you put fixtures on a directory, set up a pre-execution process to insert them into emulated datastore like this example. \n\n```\npackage testutils\n\nimport (\n    ...\n    \"github.com/timakin/dsmock\"\n    ...\n)\n\nfunc Setup(t *testing.T) (context.Context, aetest.Instance, func()) {\n\tinstance, ctx, err := testerator.SpinUp()\n\tif err != nil {\n\t\tt.Fatal(err.Error())\n\t}\n\n\t// Insert fixtures\n\tfps := getFixturePaths()\n\tfor _, fp := range fps {\n\t\tSetupFixtures(ctx, fp)\n\t}\n\n\treturn ctx, instance, func() { testerator.SpinDown() }\n}\n\n\nfunc SetupFixtures(ctx context.Context, path string) error {\n\treturn dsmock.InsertMockData(ctx, path)\n}\n\nfunc getFixturePaths() []string {\n\tdatadir, _ := filepath.Abs(\"path/to/fixtures\")\n\treturn dirwalk(datadir)\n}\n\nfunc dirwalk(dir string) []string {\n\tfiles, err := ioutil.ReadDir(dir)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tvar paths []string\n\tfor _, file := range files {\n\t\tif file.IsDir() {\n\t\t\tpaths = append(paths, dirwalk(filepath.Join(dir, file.Name()))...)\n\t\t\tcontinue\n\t\t}\n\t\tpaths = append(paths, filepath.Join(dir, file.Name()))\n\t}\n\n\treturn paths\n}\n```\n\nThen, call that setup func on each tests. Unless a volume of fixture is not huge, it works smoothly.  \n\n```\n\nfunc TestGetUsersHandler(t *testing.T) {\n    ctx, instance, cleanup := testutils.Setup(t)\n    defer cleanup()\n\t\n    //\n    // integration tests with fixtures.\n    // \n}\n```\n\nLicense\nThe MIT License (MIT)\n\nCopyright (c) 2018 Seiji Takahashi","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimakin%2Fdsmock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimakin%2Fdsmock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimakin%2Fdsmock/lists"}