Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap file IO functions #54

Open
3 tasks done
tangrufus opened this issue Aug 15, 2019 · 1 comment
Open
3 tasks done

Wrap file IO functions #54

tangrufus opened this issue Aug 15, 2019 · 1 comment

Comments

@tangrufus
Copy link
Collaborator

tangrufus commented Aug 15, 2019

Summary

Wrap file IO functions, something like:

var execCommand = exec.Command

func mockExecCommand(command string, args ...string) *exec.Cmd {
cs := []string{"-test.run=TestHelperProcess", "--", command}
cs = append(cs, args...)
cmd := exec.Command(os.Args[0], cs...)
cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1"}
return cmd
}

Motivation

Currently, tests that perform file IO might fail because files might not exist. Leaving them only testable in integration test.

Wrapping file IO functions makes uniting tests (go test -short) possible (like mockExecCommand).

@swalkinshaw
Copy link
Member

Makes sense 👍 I'd have to look around since I don't know much about Go testing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants