Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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 ./..`.