{"id":15404379,"url":"https://github.com/agis/spawn","last_synced_at":"2025-04-16T20:53:36.722Z","repository":{"id":57493892,"uuid":"149450393","full_name":"agis/spawn","owner":"agis","description":"Spawn your Go server from within its own test suite, for end-to-end tests","archived":false,"fork":false,"pushed_at":"2023-04-13T08:34:35.000Z","size":17,"stargazers_count":32,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T05:41:33.036Z","etag":null,"topics":["e2e","e2e-testing","e2e-tests","go","golang","golang-testing","testing","testing-tools"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/agis/spawn","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/agis.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":"2018-09-19T12:53:13.000Z","updated_at":"2023-04-13T08:31:06.000Z","dependencies_parsed_at":"2024-06-19T10:09:40.842Z","dependency_job_id":null,"html_url":"https://github.com/agis/spawn","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/agis%2Fspawn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agis%2Fspawn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agis%2Fspawn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agis%2Fspawn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/agis","download_url":"https://codeload.github.com/agis/spawn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249275777,"owners_count":21242284,"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":["e2e","e2e-testing","e2e-tests","go","golang","golang-testing","testing","testing-tools"],"created_at":"2024-10-01T16:12:32.319Z","updated_at":"2025-04-16T20:53:36.693Z","avatar_url":"https://github.com/agis.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"spawn\n===============\n\nSpawn makes it easy to spin up your Go server right from within its own test suite, for end-to-end testing.\n\nUsage\n--------------\nAn example usage for [this simple HTTP server](examples/main.go) can be found below.\nThe complete runnable example is at [examples](examples/).\n\n```go\nfunc TestMain(m *testing.M) {\n\t// start the server on localhost:8080 (we assume it accepts a `--port` argument)\n\tserver := spawn.New(main, \"--port\", \"8080\")\n\tctx, cancel := context.WithCancel(context.Background())\n\tserver.Start(ctx)\n\n\t// wait a bit for it to become ready\n\ttime.Sleep(500 * time.Millisecond)\n\n\t// execute the test suite\n\tresult := m.Run()\n\n\t// cleanly shutdown server\n\tcancel()\n\terr := server.Wait()\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tos.Exit(result)\n}\n\nfunc TestServerFoo(t *testing.T) {\n\tres, _ := http.Get(\"http://localhost:8080/foo\")\n\tdefer res.Body.Close()\n\n\tresBody, _ := ioutil.ReadAll(res.Body)\n\n\tif string(resBody) != \"Hello!\" {\n\t\tt.Fatalf(\"expected response to be 'Hello!', got '%s'\", resBody)\n\t}\n}\n\n// more tests using the server\n```\n\nRationale\n--------------\nWriting an end-to-end test for a server typically involves:\n\n1) compiling the server code\n2) spinning up the binary\n3) communicating with it from the tests\n4) shutting the server down\n5) verify everything went OK (server was closed cleanly etc.)\n\nThis package aims to simplify this process.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagis%2Fspawn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fagis%2Fspawn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagis%2Fspawn/lists"}