{"id":20971858,"url":"https://github.com/marco-m/xprog","last_synced_at":"2025-04-12T01:16:37.936Z","repository":{"id":57650028,"uuid":"439955568","full_name":"marco-m/xprog","owner":"marco-m","description":"xprog -- a test runner for go test -exec","archived":false,"fork":false,"pushed_at":"2024-12-14T13:44:47.000Z","size":61,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T01:16:28.644Z","etag":null,"topics":["go","remote","ssh","testing","vm"],"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/marco-m.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2021-12-19T19:56:40.000Z","updated_at":"2024-12-14T13:44:50.000Z","dependencies_parsed_at":"2023-10-02T00:21:30.422Z","dependency_job_id":null,"html_url":"https://github.com/marco-m/xprog","commit_stats":{"total_commits":16,"total_committers":1,"mean_commits":16.0,"dds":0.0,"last_synced_commit":"b4adf7545f44d16b8106df947e5aa09166e92421"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marco-m%2Fxprog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marco-m%2Fxprog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marco-m%2Fxprog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marco-m%2Fxprog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marco-m","download_url":"https://codeload.github.com/marco-m/xprog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248501860,"owners_count":21114684,"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":["go","remote","ssh","testing","vm"],"created_at":"2024-11-19T04:05:27.417Z","updated_at":"2025-04-12T01:16:37.917Z","avatar_url":"https://github.com/marco-m.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# xprog -- a test runner for `go test -exec`\n\nGeneric usage with `go test`:\n\n    $ go test -exec=\"xprog \u003ccommand\u003e [opts] --\" \u003cgo-packages\u003e [go-test-flags]\n\nCross-compile the tests and run them on the target, connect via SSH:\n\n    $ GOOS=linux go test -exec=\"xprog ssh [opts] --\" \u003cgo-packages\u003e [go-test-flags]\n\nAs above, but collect also code coverage and show it on the host:\n\n    $ GOOS=linux go test -coverprofile=coverage.out -exec=\"xprog ssh [opts] --\" \u003cgo-packages\u003e [go-test-flags] \u0026\u0026\n    go tool cover -html=coverage.out\n\nTo see `xprog` output, pass `-v` both to `xprog` and `go test`:\n\n    $ go test -v -exec=\"xprog -v \u003ccommand\u003e [opts] --\" \u003cgo-packages\u003e [go-test-flags]\n\n## Install\n\n```\n$ go install github.com/marco-m/xprog/cmd/xprog@latest\n```\n\n## Writing tests that will not harm YOUR host\n\nIf you have at least one test that exercises a destructive or invasive function, it is of the utmost importance to ensure that running `go test` in the default Go way:\n\n```\n$ go test ./...\n```\n\n(maybe you forgot about xprog, or somebody new to the project) will not cause harm to the host system!\n\nConsider functions `Harmless` and `Destructive` ([examples/example.go](examples/example.go)):\n\n```go\npackage examples\n\nfunc Harmless() {\n\tfmt.Fprintln(os.Stderr, \"hello from Harmless on\", runtime.GOOS)\n}\n\n// For example: delete and add files, invoke programs, ...\nfunc Destructive() {\n\tfmt.Fprintln(os.Stderr, \"hello from Destructive on\", runtime.GOOS)\n}\n```\n\nWe can test `Harmless` as usual ([examples/example_test.go](examples/example_test.go)):\n\n```go\nfunc TestHarmless(t *testing.T) {\n    examples.Harmless()\n}\n```\n\nOn the other hand, we want to be sure that `Destructive` is tested ONLY on the VM target. This can be achieved as follows ([examples/example_test.go](examples/example_test.go)):\n\n\n```go\nimport \"github.com/marco-m/xprog\"\n\nfunc TestDestructiveXprog(t *testing.T) {\n    if xprog.Absent() {\n        t.Skip(\"skip: test requires xprog\")\n    }\n    examples.Destructive()\n}\n```\n\nRunning the tests on the host as usual, note that `TestDestructiveXprog` is skipped:\n\n```\n$ go test -v ./examples\n=== RUN   TestHarmless\nhello from Harmless on darwin\n--- PASS: TestHarmless (0.00s)\n=== RUN   TestDestructiveXprog\n    example_test.go:21: skip: test requires xprog\n--- SKIP: TestDestructiveXprog (0.00s)\nPASS\nok      github.com/marco-m/xprog/examples\n```\n\nRunning the tests on the target VM via `xprog`, note that `TestDestructiveXprog` runs:\n\n```\n$ GOOS=linux go test -v -exec=\"xprog ssh -cfg $PWD/ssh_config --\" ./examples\n=== RUN   TestHarmless\nhello from Harmless on linux\n--- PASS: TestHarmless (0.00s)\n=== RUN   TestDestructiveXprog\nhello from Destructive on linux\n--- PASS: TestDestructiveXprog (0.00s)\nPASS\nok      github.com/marco-m/xprog/examples\n```\n\n### Running tests as root\n\nTo do this, be sure that the tests are **safe** to run everywhere (see section above).\n\nThen, add `--sudo` to the `ssh` command.\n\nThis assumes a passwordless sudo on the target (what you get by default on a Vagrant VM).\n\n## Usage\n\nFor details, have a look at the targets in the [Taskfile](Taskfile.yml), they are commented.\n\n### Quick preparation\n\n```\n$ virtualbox up\n;; Generate a SSH configuration file\n$ vagrant ssh-config \u003e ssh_config\n```\n\n### Quick usage\n\nCross-compile the tests and run them on the target, using `xprog ssh`:\n\n```\n$ GOOS=linux go test -exec=\"xprog ssh --cfg $PWD/ssh_config --\" ./... -v\n```\n\nStop the VM when done\n\n```\nvagrant halt\n```\n\n### More controlled preparation\n\nSee `task prepare-vm` or\n\n```\n$ vagrant destroy --force\n$ vagrant up\n;; Take snapshot, name `pristine`\n$ vagrant snapshot save pristine\n;; Generate a SSH configuration file\n$ vagrant ssh-config \u003e ssh_config\n```\n\n### More controlled usage\n\nSee `task test:vm:...`\n\nRun the VM-based tests on the VM current filesystem (faster but inaccurate):\n\n```\n$ GOOS=linux go test -coverprofile=coverage.out -exec=\"$PWD/bin/xprog ssh --cfg $PWD/ssh_config --\" ./... -v\n```\n\nOr: run the VM-based tests from a clean snapshot:\n\n```\n$ vagrant snapshot restore pristine\n$ GOOS=linux go test -coverprofile=coverage.out -exec=\"$PWD/bin/xprog ssh --cfg $PWD/ssh_config --\" ./... -v\n```\n\n### Notes\n\n`go test` will execute `xprog` in the directory (or directories) corresponding to the package(s) specified to the `go test` invocation. For example:\n\n```\n$ go test -exec=\"xprog ssh --cfg $PWD/ssh_config --\" ./foo\n```\n\nwill run `xprog` in directory `./foo`. This is why it is important to specify the ssh_config file with an absolute path: `--cfg $PWD/ssh_config`, so that it will be found no matter the `xprog` working directory.\n\n## Limitations\n\n### Configuration\n\n`xprog ssh` expects a `ssh_config` file generated by `vagrant ssh-config` and will pick the first `Host` entry.\n\n### Reserved environment variables\n\nThe prefix `XPROG_SYS_` is reserved for xprog internal usage. Messing with it can cause `xprog.Absent()` to return false positives and thus destructive tests will run also on your host.\n\n## License\n\nSee [LICENSE](LICENSE).\n\n## Credits\n\n- [vmtest](https://github.com/anatol/vmtest)\n- [dockexec](https://github.com/mvdan/dockexec)\n- [Go tooling essentials](https://rakyll.org/go-tool-flags/)\n- [go_android_exec](https://github.com/golang/go/blob/master/misc/android/go_android_exec.go)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarco-m%2Fxprog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarco-m%2Fxprog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarco-m%2Fxprog/lists"}