Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jthomperoo/test-exec-command-golang
Example showing how to test exec.Command in Go
https://github.com/jthomperoo/test-exec-command-golang
command exec go golang shell unit-testing
Last synced: 2 months ago
JSON representation
Example showing how to test exec.Command in Go
- Host: GitHub
- URL: https://github.com/jthomperoo/test-exec-command-golang
- Owner: jthomperoo
- License: mit
- Created: 2019-11-04T22:22:55.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-05T00:13:23.000Z (about 5 years ago)
- Last Synced: 2024-06-20T15:01:46.390Z (7 months ago)
- Topics: command, exec, go, golang, shell, unit-testing
- Language: Go
- Size: 2.93 KB
- Stars: 17
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Example repo of how to test exec.Command (and other system functions) in Golang
Accompanies this article: [Unit-Testing-Exec-Command-In-Golang](https://jamiethompson.me/posts/Unit-Testing-Exec-Command-In-Golang/)
## Overview
Package `funshell` contains the `ShellCommand` function which is being tested.
`ShellCommand` just kicks off the shell command `echo 'fun!'`.
The `main` function in `main.go` just calls this, catches errors and then prints out anything that was output to stdout.
Package `funshell_test` runs some simple unit tests against `ShellCommand`.## Running
Run the program with `go run main.go`.
Run the tests with `go test ./..`.